@codeflow-ai/cli 1.30.1 → 1.30.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +25 -25
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,45 +1,45 @@
1
1
  #!/usr/bin/env node
2
- import{once as WR}from"events";import{createInterface as VR}from"readline/promises";import{parseArgs as KR}from"util";var km={name:"@codeflow-ai/cli",version:"1.30.1",type:"module",description:"CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF\uFF1A\u4E00\u952E\u914D\u7F6E AI \u5BA2\u6237\u7AEF",keywords:["codeflow","claude-code","codex","openclaw","hermes-agent","opencode","pi-coding-agent","cli"],license:"UNLICENSED",engines:{node:">=22"},bin:{codeflow:"dist/cli.js"},files:["dist"],publishConfig:{access:"public"},scripts:{dev:"tsx src/cli.ts",build:"tsup",typecheck:"tsc --noEmit"},dependencies:{"@decimalturn/toml-patch":"3.0.4",ink:"7.1.1",json5:"2.2.3","jsonc-parser":"3.3.1",marked:"18.0.9",qrcode:"1.5.4",react:"19.2.0","smol-toml":"1.9.0","string-width":"8.2.0",yaml:"2.9.1",zod:"4.4.3"},devDependencies:{"@codeflow/shared":"workspace:*","@types/node":"25.9.1","@types/qrcode":"1.5.6","@types/react":"19.2.2",tsup:"8.5.1",tsx:"4.22.3",typescript:"5.9.3"}};var Wt="codeflow",Vt=km.version,vm="https://codeflow.sh",Fo="@codeflow-ai/cli",Rr=0,Uo=1,qa=2,ro=3,Cm=4;import{randomBytes as lS}from"crypto";import{mkdirSync as Em,readFileSync as mS,rmSync as Mm,statSync as uS,writeFileSync as dS}from"fs";import{join as Im}from"path";import{setTimeout as pS}from"timers/promises";import{z as rn}from"zod";var U=class extends Error{exitCode;hint;constructor(t,n={}){super(t,{cause:n.cause}),this.name="CliError",this.exitCode=n.exitCode??Uo,this.hint=n.hint}};function xe(e){return e instanceof Error?e.message:String(e)}import{chmodSync as nS,existsSync as oS,mkdirSync as rS,readFileSync as iS,writeFileSync as sS}from"fs";import{dirname as aS}from"path";function Nt(e){return oS(e)?iS(e,"utf8"):null}function kn(e,t,n){rS(aS(e),{recursive:!0,mode:448});try{sS(e,t,{mode:n}),nS(e,n)}catch(o){throw new U(`\u5199\u5165 ${e} \u5931\u8D25\uFF1A${xe(o)}`,{cause:o})}}function Rm(e,t,n){kn(e,`${JSON.stringify(t,null,2)}
3
- `,n)}function _i(e,t,n,o,r){let i=null,s=()=>{if(i)return i;let a=n(),c=Nt(a);if(c===null)return i=structuredClone(t),i;let l;try{l=JSON.parse(c)}catch(m){throw new U(`${o} ${a} \u5DF2\u635F\u574F\uFF0C\u8BF7\u5220\u9664\u8BE5\u6587\u4EF6\u540E${r}`,{cause:m})}let u=e.safeParse(l);if(!u.success)throw new U(`${o} ${a} \u7ED3\u6784\u4E0D\u7B26\uFF0C\u8BF7\u5220\u9664\u8BE5\u6587\u4EF6\u540E${r}`);return i=u.data,i};return{load:s,reload:()=>(i=null,s()),update:a=>{let c=structuredClone(s());return a(c),Rm(n(),c,384),i=c,c}}}import{homedir as cS}from"os";import{join as jo}from"path";function vn(){let e=process.env.XDG_CONFIG_HOME;if(e)return jo(e,"codeflow");if(process.platform==="win32"){let t=process.env.APPDATA;if(t)return jo(t,"codeflow")}return jo(cS(),".config","codeflow")}var _m=()=>jo(vn(),"config.json"),Pm=()=>jo(vn(),"credentials.json"),Am=()=>jo(vn(),"refresh.lock");var fS=rn.object({refreshCookie:rn.string(),accessToken:rn.string(),accessExpiresAt:rn.number(),username:rn.string(),email:rn.string(),site:rn.string()}),gS=rn.object({site:rn.string(),cookie:rn.string()}),hS=rn.object({session:fS.nullable(),device:gS.nullable()}),Ga=_i(hS,{session:null,device:null},Pm,"\u672C\u5730\u51ED\u636E","\u91CD\u65B0\u767B\u5F55"),Lt=Ga.load,Nm=Ga.reload,za=Ga.update;function Lm(){let{session:e}=Lt();if(!e)throw new U("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:ro});return e}var yS=6e4,bS=75e3,SS=120;function xS(e,t){try{Em(e)}catch{try{Date.now()-uS(e).mtimeMs>yS&&Mm(e,{recursive:!0,force:!0})}catch{}return!1}return dS(Im(e,"owner"),t),!0}function TS(e,t){let n;try{n=mS(Im(e,"owner"),"utf8")}catch{return}n===t&&Mm(e,{recursive:!0,force:!0})}async function Om(e){let t=Am(),n=lS(16).toString("hex");Em(vn(),{recursive:!0,mode:448});let o=Date.now()+bS;for(;!xS(t,n);){if(Date.now()>o)throw new U(`\u7B49\u5F85\u5237\u65B0\u9501\u8D85\u65F6\uFF0C\u82E5\u786E\u8BA4\u6CA1\u6709\u5176\u4ED6 ${Wt} \u5728\u8FD0\u884C\uFF0C\u8BF7\u5220\u9664 ${t}`);await pS(SS)}try{return await e()}finally{TS(t,n)}}function wS(){let e=process.env.CODEFLOW_SITE;if(e)return e;let t=Lt().session;return t?t.site:vm}function Dm(){return{site:wS()}}function io(e,t,n){if(!e.isTTY)return n;let o=Number.parseInt(t.slice(1),16);return`\x1B[38;2;${o>>16&255};${o>>8&255};${o&255}m${n}\x1B[39m`}import{existsSync as vx,rmSync as Cx}from"fs";import{z as je}from"zod";var kS=["active","disabled"],M_=je.enum(kS),Wa=["subscription_first","balance_first","subscription_only","balance_only"],Va=je.enum(Wa),vS=["openai","anthropic"],$m=je.enum(vS),CS=["openai-chat","openai-responses","anthropic-messages"],Bm=je.enum(CS);var _r=["pending","paid","refund_requested","partially_refunded","refunded","failed","expired"],Fm=je.enum(_r),RS=["recharge","subscription"],Ka=je.enum(RS),_S=["requested","pending","succeeded","failed","rejected","canceled"],Um=je.enum(_S),Ya=["pending","issued","rejected"],jm=je.enum(Ya),PS=["special","general"],Ja=je.enum(PS),AS=["info","success","warning","error"],Hm=je.enum(AS),ES=["terms","privacy"],I_=je.enum(ES),Xa=["recharge","reserve","consume","reserve_refund","refund","refund_release","reward","admin_adjust"],qm=je.enum(Xa),MS=["usage_log","order","invitation","admin"],Gm=je.enum(MS),Qa=["first_inviter","first_invitee","subsequent_inviter"],zm=je.enum(Qa),Za=["success","error","canceled","anomaly"],Wm=je.enum(Za),ec=["open","replied","closed"],Vm=je.enum(ec),tc=["billing","technical","account","other"],Km=je.enum(tc),nc=["low","normal","high"],Ym=je.enum(nc),IS=["user","admin"],Jm=je.enum(IS),NS=["pending","published","rejected","removed"],Pr=je.enum(NS),oc=["activity","published"],Xm=je.enum(oc),Pi=["spam","abuse","explicit","illegal","privacy","other"],Qm=je.enum(Pi),LS=["none","minor","major","critical"],Zm=je.enum(LS);import{z as Ho}from"zod";var OS=["internal_error","validation_error","not_found","conflict","rate_limited","forbidden","unauthorized","invalid_credentials","password_incorrect","account_disabled","email_already_registered","username_taken","verification_code_invalid","verification_code_expired","token_expired","token_reuse_detected","token_limit_exceeded","totp_invalid","totp_replayed","totp_setup_expired","totp_not_enabled","login_ticket_invalid","recovery_code_invalid","passkey_registration_failed","passkey_verification_failed","passkey_not_found","passkey_origin_not_allowed","insufficient_quota","no_available_channel","model_not_found","model_not_in_group","token_group_missing","token_quota_exceeded","upstream_error","order_not_found","order_not_payable","payment_verify_failed","payment_precreate_failed","amount_mismatch","refund_not_allowed","refund_amount_invalid","refund_insufficient_balance","refund_failed","refund_pending","refund_in_progress","refund_blocked_by_pending_order","refund_order_superseded","refund_request_not_found","refund_nothing_refundable","subscription_limit_reached","no_subscription_coverage","subscription_revoked","plan_disabled","order_already_invoiced","order_not_eligible","order_invoiced","invoice_profile_exists","invite_code_invalid","ticket_closed","ticket_limit_exceeded","attachment_storage_unconfigured","attachment_too_large","attachment_image_too_large","attachment_invalid","attachment_staging_limit_exceeded","docs_not_configured","docs_source_unavailable","docs_page_not_found","provider_status_unavailable","community_muted","community_state_changed","community_category_missing"],DS=Ho.enum(OS),eu=Ho.object({error:Ho.object({code:DS,message:Ho.string(),details:Ho.unknown().optional(),requestId:Ho.string().optional()})});var tu={internal_error:"\u670D\u52A1\u6682\u65F6\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",validation_error:"\u63D0\u4EA4\u7684\u5185\u5BB9\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5",not_found:"\u8BBF\u95EE\u7684\u5185\u5BB9\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664",conflict:"\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u8BB0\u5F55\uFF0C\u8BF7\u52FF\u91CD\u590D\u63D0\u4EA4",rate_limited:"\u64CD\u4F5C\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",forbidden:"\u6CA1\u6709\u6743\u9650\u6267\u884C\u6B64\u64CD\u4F5C",unauthorized:"\u8BF7\u5148\u767B\u5F55",invalid_credentials:"\u8D26\u53F7\u6216\u5BC6\u7801\u4E0D\u6B63\u786E",password_incorrect:"\u5F53\u524D\u5BC6\u7801\u4E0D\u6B63\u786E",account_disabled:"\u8D26\u6237\u5DF2\u88AB\u7981\u7528\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",email_already_registered:"\u8BE5\u90AE\u7BB1\u5DF2\u88AB\u6CE8\u518C",username_taken:"\u8BE5\u7528\u6237\u540D\u5DF2\u88AB\u4F7F\u7528",verification_code_invalid:"\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E",verification_code_expired:"\u9A8C\u8BC1\u7801\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u83B7\u53D6",token_expired:"\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",token_reuse_detected:"\u767B\u5F55\u72B6\u6001\u5F02\u5E38\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",token_limit_exceeded:"\u4EE4\u724C\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u5220\u9664\u4E0D\u518D\u4F7F\u7528\u7684\u4EE4\u724C",totp_invalid:"\u52A8\u6001\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E\uFF0C\u8BF7\u91CD\u8BD5",totp_replayed:"\u8BE5\u9A8C\u8BC1\u7801\u521A\u521A\u5DF2\u88AB\u4F7F\u7528\uFF0C\u8BF7\u7B49\u5F85\u9A8C\u8BC1\u5668\u663E\u793A\u4E0B\u4E00\u4E2A\u9A8C\u8BC1\u7801\u540E\u518D\u8F93\u5165",totp_setup_expired:"\u7ED1\u5B9A\u4F1A\u8BDD\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5F00\u59CB\u7ED1\u5B9A",totp_not_enabled:"\u5C1A\u672A\u542F\u7528\u4E24\u6B65\u9A8C\u8BC1",login_ticket_invalid:"\u767B\u5F55\u9A8C\u8BC1\u5DF2\u8FC7\u671F\u6216\u5C1D\u8BD5\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",recovery_code_invalid:"\u6062\u590D\u7801\u4E0D\u6B63\u786E\u6216\u5DF2\u88AB\u4F7F\u7528",passkey_registration_failed:"Passkey \u6CE8\u518C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",passkey_verification_failed:"Passkey \u9A8C\u8BC1\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",passkey_not_found:"\u8BE5 Passkey \u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664",passkey_origin_not_allowed:"\u5F53\u524D\u8BBF\u95EE\u5730\u5740\u672A\u914D\u7F6E\u4E3A\u7AD9\u70B9\u5730\u5740\uFF0C\u65E0\u6CD5\u4F7F\u7528 Passkey",insufficient_quota:"\u989D\u5EA6\u4E0D\u8DB3\uFF0C\u8BF7\u5145\u503C\u540E\u518D\u8BD5",no_available_channel:"\u4E0A\u6E38\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",model_not_found:"\u8BE5\u6A21\u578B\u4E0D\u5B58\u5728",model_not_in_group:"\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u4E0D\u652F\u6301\u8BE5\u6A21\u578B\uFF0C\u8BF7\u66F4\u6362\u4EE4\u724C\u5206\u7EC4\u6216\u6539\u7528\u5206\u7EC4\u652F\u6301\u7684\u6A21\u578B",token_group_missing:"\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u5DF2\u88AB\u5220\u9664\uFF0C\u8BF7\u7F16\u8F91\u4EE4\u724C\u91CD\u65B0\u9009\u62E9\u5206\u7EC4",token_quota_exceeded:"\u8BE5\u4EE4\u724C\u7684\u6D88\u8D39\u5DF2\u8FBE\u8D39\u7528\u9650\u5236\uFF0C\u8BF7\u8C03\u9AD8\u6216\u6E05\u9664\u9650\u5236\u540E\u518D\u4F7F\u7528",upstream_error:"\u4E0A\u6E38\u670D\u52A1\u8FD4\u56DE\u9519\u8BEF\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",order_not_found:"\u8BA2\u5355\u4E0D\u5B58\u5728",order_not_payable:"\u8BA2\u5355\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u518D\u8BD5",payment_verify_failed:"\u652F\u4ED8\u7ED3\u679C\u786E\u8BA4\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",payment_precreate_failed:"\u53D1\u8D77\u652F\u4ED8\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",amount_mismatch:"\u652F\u4ED8\u91D1\u989D\u4E0E\u8BA2\u5355\u4E0D\u7B26\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",refund_not_allowed:"\u8BE5\u8BA2\u5355\u5F53\u524D\u4E0D\u53EF\u9000\u6B3E",refund_amount_invalid:"\u9000\u6B3E\u91D1\u989D\u4E0D\u6B63\u786E\u6216\u8D85\u8FC7\u53EF\u9000\u4F59\u989D",refund_insufficient_balance:"\u53EF\u7528\u989D\u5EA6\u4E0D\u8DB3\u4EE5\u6263\u56DE\u672C\u6B21\u9000\u6B3E\uFF08\u5DF2\u6D88\u8017\u90E8\u5206\u5BF9\u5E94\u7684\u73B0\u91D1\u4E0D\u53EF\u9000\uFF09",refund_failed:"\u652F\u4ED8\u5B9D\u9000\u6B3E\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u6216\u68C0\u67E5\u652F\u4ED8\u5B9D\u5546\u6237\u540E\u53F0",refund_pending:"\u9000\u6B3E\u7ED3\u679C\u5F85\u786E\u8BA4\uFF0C\u8BF7\u7A0D\u540E\u67E5\u770B\u9000\u6B3E\u8BB0\u5F55",refund_in_progress:"\u8BE5\u8BA2\u5355\u6216\u8BA2\u9605\u6709\u9000\u6B3E\u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u5F85\u5176\u5B8C\u6210\u540E\u518D\u64CD\u4F5C",refund_blocked_by_pending_order:"\u8BE5\u8BA2\u9605\u6709\u5F85\u652F\u4ED8\u7684\u7EED\u8D39\u8BA2\u5355\uFF0C\u8BF7\u5F85\u5176\u652F\u4ED8\u6216\u8D85\u65F6\u540E\u518D\u9000\u6B3E",refund_order_superseded:"\u5B58\u5728\u66F4\u665A\u5165\u8D26\u7684\u8BA2\u5355\uFF0C\u8BF7\u6309\u4ECE\u65B0\u5230\u65E7\u7684\u987A\u5E8F\u9000\u6B3E",refund_request_not_found:"\u9000\u6B3E\u7533\u8BF7\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5904\u7406\uFF0C\u8BF7\u5237\u65B0\u540E\u67E5\u770B",refund_nothing_refundable:"\u8BE5\u8BA2\u9605\u8BA2\u5355\u6309\u9650\u989D\u5468\u671F\u8BA1\u8D39\u540E\u5DF2\u65E0\u53EF\u9000\u91D1\u989D",subscription_limit_reached:"\u8BA2\u9605\u989D\u5EA6\u5DF2\u7528\u5C3D\uFF0C\u8BF7\u7B49\u5F85\u7A97\u53E3\u91CD\u7F6E",no_subscription_coverage:"\u5F53\u524D\u5206\u7EC4\u6CA1\u6709\u53EF\u7528\u7684\u8BA2\u9605\uFF0C\u8BF7\u8BA2\u9605\u5957\u9910\u6216\u8C03\u6574\u6263\u8D39\u65B9\u5F0F",subscription_revoked:"\u8BE5\u8BA2\u9605\u5DF2\u88AB\u4F5C\u5E9F",plan_disabled:"\u8BE5\u5957\u9910\u5DF2\u505C\u552E",order_already_invoiced:"\u8BE5\u8BA2\u5355\u5DF2\u7533\u8BF7\u8FC7\u53D1\u7968",order_not_eligible:"\u6240\u9009\u8BA2\u5355\u4E0D\u7B26\u5408\u5F00\u7968\u6761\u4EF6",order_invoiced:"\u8BE5\u8BA2\u5355\u5DF2\u5F00\u7968\u6216\u6709\u672A\u5904\u7406\u7684\u5F00\u7968\u7533\u8BF7\uFF0C\u65E0\u6CD5\u9000\u6B3E",invoice_profile_exists:"\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u5E38\u7528\u5F00\u7968\u4FE1\u606F",invite_code_invalid:"\u9080\u8BF7\u7801\u65E0\u6548",ticket_closed:"\u5DE5\u5355\u5DF2\u5173\u95ED\uFF0C\u8BF7\u5148\u91CD\u65B0\u6253\u5F00\u540E\u518D\u56DE\u590D",ticket_limit_exceeded:"\u672A\u5173\u95ED\u7684\u5DE5\u5355\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u5173\u95ED\u5DF2\u89E3\u51B3\u7684\u5DE5\u5355",attachment_storage_unconfigured:"\u5C1A\u672A\u914D\u7F6E\u9644\u4EF6\u5B58\u50A8",attachment_too_large:"\u9644\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236",attachment_image_too_large:"\u56FE\u7247\u5C3A\u5BF8\u6216\u5E27\u6570\u8D85\u8FC7\u9650\u5236",attachment_invalid:"\u9644\u4EF6\u65E0\u6548\u6216\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u4E0A\u4F20",attachment_staging_limit_exceeded:"\u5F85\u63D0\u4EA4\u7684\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u63D0\u4EA4\u73B0\u6709\u9644\u4EF6",docs_not_configured:"\u6587\u6863\u4E2D\u5FC3\u672A\u542F\u7528",docs_source_unavailable:"\u6587\u6863\u5185\u5BB9\u83B7\u53D6\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",docs_page_not_found:"\u8BE5\u6587\u6863\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",provider_status_unavailable:"\u5B98\u65B9\u670D\u52A1\u72B6\u6001\u6682\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",community_muted:"\u8D26\u53F7\u5904\u4E8E\u7981\u8A00\u671F\u95F4\uFF0C\u6682\u65F6\u65E0\u6CD5\u53D1\u5E16\u3001\u8BC4\u8BBA\u3001\u7F16\u8F91\u3001\u4E0A\u4F20\u6216\u66F4\u6362\u5934\u50CF\u4E0E\u7528\u6237\u540D",community_state_changed:"\u5185\u5BB9\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5",community_category_missing:"\u6240\u9009\u677F\u5757\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9"};import{z as qo}from"zod";var $S=qo.string().trim().min(1),rc=$S.pipe(qo.url()),BS=qo.object({name:qo.string().trim().min(1),description:qo.string().trim().min(1),url:rc}),B_=qo.array(BS);function nu(e){return`codeflow-cli/${e.cliVersion} (${e.platform} ${e.release}; ${e.arch}) node/${e.nodeVersion}`}function Go(e){if(!e)return"\u672A\u77E5\u8BBE\u5907";let t=e.type==="cli"?e.clientVersion:e.clientVersion?.split(".")[0],o=[e.client?t?`${e.client} ${t}`:e.client:null,e.os].filter(r=>r!==null);return o.length>0?o.join(" \xB7 "):"\u672A\u77E5\u8BBE\u5907"}import{z as dn}from"zod";var ic=1e8;var H_=dn.object({id:dn.coerce.number().int().positive()}),ou=100,ru=dn.object({page:dn.coerce.number().int().min(1)});function mt(e){return dn.object({items:dn.array(e),total:dn.number()})}var se=dn.object({ok:dn.literal(!0)}),iu=(e=dn.string().trim())=>e.nullable().optional().transform(t=>t==null||t.length===0?null:t);import{z as ce}from"zod";var so=ce.email().max(254).toLowerCase(),Ot=8,Ar=ce.string().min(Ot).max(128),Er=ce.string().min(1).max(128),Kt=32,sc=ce.string().trim().min(1).max(Kt),ac=ce.string().trim().min(1).max(254),z_=ce.object({email:so}),W_=ce.object({username:sc,email:so,password:Ar,code:ce.string().min(4).max(8),inviteCode:ce.string().trim().min(1).max(32).optional()}),V_=ce.object({account:ac,password:Er}),K_=ce.object({email:so,code:ce.string().min(4).max(8),password:Ar}),Y_=ce.object({oldPassword:Er,newPassword:Ar}),J_=ce.object({email:so}),X_=ce.object({email:so,code:ce.string().min(4).max(8),password:Er}),su=ce.object({username:ce.string(),email:ce.string(),avatarUrl:ce.string().nullable()}),zo=ce.object({accessToken:ce.string(),user:su}),au=ce.discriminatedUnion("status",[zo.extend({status:ce.literal("ok")}),ce.object({status:ce.literal("totp_required"),ticket:ce.string()})]),cu=ce.object({user:su}),cc=ce.object({client:ce.string().nullable(),clientVersion:ce.string().nullable(),os:ce.string().nullable(),osVersion:ce.string().nullable(),type:ce.string().nullable(),vendor:ce.string().nullable(),model:ce.string().nullable()}),FS=ce.object({id:ce.number().int(),ip:ce.string(),userAgent:ce.string().nullable(),device:cc.nullable(),loginAt:ce.string(),lastActiveAt:ce.string(),expiresAt:ce.string(),current:ce.boolean()}),lu=ce.object({sessions:ce.array(FS)});import{z as ke}from"zod";var Wo=ke.string().trim().length(6),US=ke.string().trim().min(10).max(20),Ai=ke.string().trim().min(1).max(64),Ei=ke.record(ke.string(),ke.unknown()),e0=ke.object({ticket:ke.string().min(1),code:Wo}),t0=ke.object({ticket:ke.string().min(1),code:US}),n0=ke.object({code:Wo.optional()}),o0=ke.object({code:Wo}),mu=ke.object({secret:ke.string(),otpauthUri:ke.string()}),lc=ke.object({recoveryCodes:ke.array(ke.string())}),jS=ke.object({id:ke.number().int(),name:ke.string(),createdAt:ke.string(),lastUsedAt:ke.string().nullable()}),uu=ke.object({totp:ke.object({enabled:ke.boolean(),enabledAt:ke.string().nullable(),recoveryCodesRemaining:ke.number().int()}),passkeys:ke.array(jS)}),r0=ke.object({name:Ai,response:Ei}),i0=ke.object({name:Ai}),s0=ke.object({response:Ei});import{z as Ne}from"zod";var u0=Ne.object({account:ac,password:Er}),HS=Ne.object({totp:Ne.boolean(),passkeys:Ne.boolean()}),d0=Ne.discriminatedUnion("status",[Ne.object({status:Ne.literal("totp_required"),ticket:Ne.string()}),Ne.object({status:Ne.literal("setup_required"),ticket:Ne.string(),missing:HS})]),p0=Ne.object({ticket:Ne.string().min(1)}),f0=Ne.object({ticket:Ne.string().min(1),code:Wo}),g0=Ne.object({ticket:Ne.string().min(1),name:Ai,response:Ei}),h0=Ne.object({ticket:Ne.string().min(1),code:Wo.optional()}),du=Ne.object({username:Ne.string(),email:Ne.string(),avatarUrl:Ne.string().nullable()}),y0=Ne.object({accessToken:Ne.string(),admin:du}),b0=Ne.object({admin:du});import{z as mc}from"zod";var k0=mc.object({siteName:mc.string().trim().min(1).max(64),siteDescription:mc.string().trim().max(200).optional(),siteOrigin:rc,username:sc,email:so,password:Ar});import{z as $e}from"zod";var pu={orderNo:$e.string(),amountCny:$e.number().int(),status:Fm,credited:$e.boolean(),refundedAmountCny:$e.number().int(),succeededRefundCny:$e.number().int(),pendingRefundCny:$e.number().int(),createdAt:$e.string()},Mr=$e.object({...pu,quota:$e.number(),refundedQuota:$e.number()}),Ir=$e.object({...pu,planName:$e.string(),renewal:$e.boolean(),grantedDurationDays:$e.number().int()}),Mi=$e.object({order:Mr.pick({orderNo:!0,amountCny:!0,quota:!0}),qrCode:$e.string()}),Nr=$e.object({order:Ir.pick({orderNo:!0,amountCny:!0,planName:!0,grantedDurationDays:!0}),qrCode:$e.string()}),fu=$e.object({id:$e.number().int(),amountCny:$e.number().int(),status:Um,refundTradeNo:$e.string().nullable(),reason:$e.string().nullable(),rejectReason:$e.string().nullable(),createdAt:$e.string()});function gu(e){return e.status!=="paid"&&e.status!=="partially_refunded"||e.pendingRefundCny>0?!1:e.kind==="recharge"?e.refundedAmountCny<e.amountCny:e.refundedAmountCny===0}import{z as ut}from"zod";import{z as Yt}from"zod";var uc=Yt.object({kind:Yt.literal("user"),username:Yt.string(),avatarUrl:Yt.string().nullable(),points:Yt.number().int()}),dc=Yt.object({kind:Yt.literal("admin"),username:Yt.string(),avatarUrl:Yt.string().nullable()}),Vo=Yt.discriminatedUnion("kind",[uc,dc]),hu=Yt.object({kind:Jm,username:Yt.string()});var Ii=ut.object({id:ut.number().int(),title:ut.string(),category:Km,priority:Ym,status:Vm,createdAt:ut.string(),updatedAt:ut.string()}),yu=Ii.pick({id:!0}),bu=25*1024*1024,Su=5,xu=ut.object({id:ut.number().int(),fileName:ut.string(),fileSize:ut.number().int(),contentType:ut.string()}),Tu=xu.pick({id:!0,fileSize:!0}),qS=ut.object({id:ut.number().int(),author:Vo,content:ut.string(),attachments:ut.array(xu),createdAt:ut.string()}),wu=ut.object({ticket:Ii,messages:ut.array(qS)});import{z as Lr}from"zod";var pc=Lr.object({id:Lr.number().int(),title:Lr.string(),content:Lr.string(),level:Hm,publishedAt:Lr.string()});import{z as Ye}from"zod";var fc=100,ku=Ye.object({groups:Ye.array(Ye.object({title:Ye.string(),items:Ye.array(Ye.object({slug:Ye.string(),title:Ye.string()}))}))}),vu=Ye.object({title:Ye.string(),markdown:Ye.string(),images:Ye.record(Ye.string(),Ye.object({width:Ye.number().int(),height:Ye.number().int()}))}),Cu=Ye.object({slug:Ye.string(),title:Ye.string(),anchor:Ye.string().nullable(),snippet:Ye.string()});function Ru(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").replace(/\s+/g,"-")}function gc(e){try{return decodeURIComponent(e)}catch{return e}}function Ni(e){if(!e.startsWith("/guides/"))return null;let t=e.indexOf("#");return{slug:(t===-1?e:e.slice(0,t)).slice(8,-3),anchor:t===-1?null:gc(e.slice(t+1))}}import{z as ot}from"zod";function Le(e){return e.toLocaleString("en-US")}function qn(e){let t=Math.abs(e);return t>=1e9?`${(e/1e9).toFixed(1)}B`:t>=1e6?`${(e/1e6).toFixed(1)}M`:t>=1e3?`${(e/1e3).toFixed(1)}k`:Le(e)}function pn(e,t){return e===0&&t!==void 0?t:e.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:6})}function ao(e){return(e/1e3).toFixed(2)}function Ko(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${(e/1024**2).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function Li(e,t){return`${e}******${t}`}var hc=ot.object({inputPricePerMillionTokens:ot.number(),outputPricePerMillionTokens:ot.number(),cachedInputPricePerMillionTokens:ot.number(),cacheWritePricePerMillionTokens:ot.number()});var GS=ot.number().int().nonnegative(),zS=ot.discriminatedUnion("kind",[hc.extend({kind:ot.literal("price"),inputTokensOver:GS}),ot.object({kind:ot.literal("multiplier"),param:ot.string(),value:ot.string(),multiplier:ot.number()})]),_u=ot.array(zS);function WS(e){return e.kind==="price"}function Pu(e){return e.kind==="multiplier"}function Au(e){return e>=1e6&&e%1e5===0?`${e/1e6}M`:e>=1e3&&e%1e3===0?`${e/1e3}k`:Le(e)}function Or(e){return e===null?"\u57FA\u7840":"\u6269\u5C55"}function yc(e){return`> ${Au(e)}`}function Eu(e,t){let n=t.filter(WS).sort((r,i)=>r.inputTokensOver-i.inputTokensOver),o=n[0];return o===void 0?[{name:Or(null),range:null,price:e}]:[{name:Or(null),range:`\u2264 ${Au(o.inputTokensOver)}`,price:e},...n.map(r=>({name:Or(r.inputTokensOver),range:yc(r.inputTokensOver),price:r}))]}var VS=ot.object({value:ot.string(),multiplier:ot.number()}),Mu=ot.array(VS);function Iu(e){return Lu(e.map(t=>t.multiplier))}function Nu(e,t){return Lu([e,...t.map(n=>n.multiplier)])}function Lu(e){return Number(e.reduce((t,n)=>t*n,1).toFixed(4))}import{z as co}from"zod";var KS=co.object({provider:$m,pageUrl:co.string(),indicator:Zm,incidents:co.array(co.object({title:co.string()}))}),Ou=co.object({providers:co.array(KS)}),YS={minor:{label:"\u90E8\u5206\u964D\u7EA7",tone:"warning"},major:{label:"\u90E8\u5206\u4E2D\u65AD",tone:"danger"},critical:{label:"\u4E25\u91CD\u4E2D\u65AD",tone:"danger"}};function Du(e){return e.filter(t=>t.indicator!=="none"||t.incidents.length>0)}function $u(e){return e.indicator==="none"?{label:"\u4E8B\u4EF6\u5904\u7406\u4E2D",tone:"warning"}:YS[e.indicator]}import{z as lo}from"zod";var Dr=25*1024*1024,Bu=20,Fu=5;var bc="/api/media/";function Uu(e){return`${bc}${e}`}var ju=lo.object({width:lo.number().int(),height:lo.number().int()}),Oi=lo.record(lo.string(),ju),Hu=lo.object({id:lo.number().int(),image:ju.nullable()}),qu=String.raw`([1-9]\d{0,14})`,K0=new RegExp(String.raw`^${bc}${qu}$`),Gu=new RegExp(String.raw`(!?)\[((?:\\.|[^\\\]\n])*)\]\(${bc}${qu}(?:\s+"[^"\n]*")?\)`,"g");function zu(e,t,n){return{id:Number(n),image:e==="!",name:t.replace(/\\(.)/g,"$1")}}function Wu(e){return[...e.matchAll(Gu)].map(([,t="",n="",o=""])=>zu(t,n,o))}function Sc(e,t){return e.replace(Gu,(n,o,r,i)=>t(zu(o,r,i)))}import{z as dt}from"zod";import{z as I}from"zod";var mo=100,Di=2e4,xc=5e3,$i=500,Bi=64,JS=new RegExp("\\p{Cc}","u"),XS=new RegExp("(?![\\n\\t])\\p{Cc}","u");function Tc(e){return I.string().trim().max(e).refine(t=>!JS.test(t))}function wc(e){return I.string().trim().max(e).refine(t=>!XS.test(t))}var nP=I.object({categoryId:I.number().int().positive(),title:Tc(mo).min(1),content:wc(Di).min(1)}),oP=I.object({categoryId:I.number().int().positive().nullable(),title:Tc(mo),content:wc(Di)}),rP=I.object({content:wc(xc).min(1),replyToId:I.number().int().positive().optional()}),iP=I.object({reason:Qm,detail:iu(Tc($i))}),sP=ru.extend({sort:Xm,categoryId:I.coerce.number().int().positive().optional(),q:I.string().trim().min(1).max(Bi).optional(),author:I.string().trim().min(1).max(Kt).optional()}),kc=I.object({id:I.number().int(),name:I.string(),description:I.string()}),Fi=kc.pick({id:!0,name:!0}),$r=I.object({id:I.number().int(),title:I.string()}),Yo=I.object({id:I.number().int(),title:I.string().nullable()}),aP=I.object({posts:I.array(I.object({id:I.number().int(),lastModified:I.string()})),users:I.array(I.string()),staff:I.array(I.string())}),vc=I.object({id:I.number().int(),title:I.string(),category:Fi,author:Vo,commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),lastActivityAt:I.string()}),Cc=I.object({id:I.number().int(),title:I.string(),content:I.string(),images:Oi,category:Fi,author:Vo,status:Pr,reviewReason:I.string().nullable(),commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),coverUrl:I.string().nullable(),createdAt:I.string(),publishedAt:I.string().nullable(),editedAt:I.string().nullable(),liked:I.boolean(),bookmarked:I.boolean()}),Vu={id:I.number().int(),author:Vo,content:I.string(),images:Oi,status:Pr,reviewReason:I.string().nullable(),likeCount:I.number().int(),liked:I.boolean(),createdAt:I.string()},Rc=I.object({...Vu,replyTo:I.object({id:I.number().int(),author:hu}).nullable()}),Ui=I.object({...Vu,floor:I.number().int().nullable(),replyCount:I.number().int(),replies:I.array(Rc)}),_c=I.object({likeCount:I.number().int()}),Ku=Cc.pick({id:!0}),Yu=Ui.pick({id:!0}),QS=I.object({status:I.enum(["pending","rejected","removed"]),reviewReason:I.string().nullable()}),Pc=I.object({review:QS.nullable()}),Br=I.object({id:I.number().int(),title:I.string(),category:Fi,status:Pr,reviewReason:I.string().nullable(),commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),createdAt:I.string(),publishedAt:I.string().nullable()}),ji=I.object({id:I.number().int(),content:I.string(),post:Yo,floorId:I.number().int(),status:Pr,reviewReason:I.string().nullable(),likeCount:I.number().int(),createdAt:I.string()}),Ac=I.object({id:I.number().int(),category:Fi.nullable(),title:I.string(),content:I.string(),images:Oi,createdAt:I.string()}),Ju=I.object({posts:I.array(Br),drafts:I.number().int()}),Xu=Ac.pick({id:!0}),Qu=I.object({muted:I.object({reason:I.string(),until:I.string().nullable()}).nullable()});var ZS=dt.object({posts:dt.number().int(),comments:dt.number().int(),likesReceived:dt.number().int()}),ex=dt.object({start:dt.string(),end:dt.string(),days:dt.array(dt.object({day:dt.string(),count:dt.number().int()}))}),tx=dt.object({posts:dt.array(Br),comments:dt.array(ji)}),Zu={joinedAt:dt.string(),stats:ZS,activity:ex,overview:tx},ed=dt.object({identity:uc,...Zu}),td=dt.object({identity:dc,...Zu});import{z as q}from"zod";var tt={id:q.number().int(),read:q.boolean(),createdAt:q.string()},Fr=q.object({floorId:q.number().int()}),nd=q.object({username:q.string()}),od=q.discriminatedUnion("kind",[q.object({...tt,kind:q.literal("post_commented"),post:$r,comment:Fr,actor:nd}),q.object({...tt,kind:q.literal("comment_replied"),post:Yo,comment:Fr,actor:nd}),q.object({...tt,kind:q.literal("post_approved"),post:$r}),q.object({...tt,kind:q.literal("post_rejected"),post:$r,reason:q.string()}),q.object({...tt,kind:q.literal("post_removed"),post:$r,reason:q.string()}),q.object({...tt,kind:q.literal("comment_approved"),post:Yo,comment:Fr}),q.object({...tt,kind:q.literal("comment_rejected"),post:Yo,comment:Fr,reason:q.string()}),q.object({...tt,kind:q.literal("comment_removed"),post:Yo,comment:Fr,reason:q.string()}),q.object({...tt,kind:q.literal("avatar_approved")}),q.object({...tt,kind:q.literal("avatar_rejected"),reason:q.string()}),q.object({...tt,kind:q.literal("avatar_removed"),reason:q.string()}),q.object({...tt,kind:q.literal("ticket_replied"),ticket:q.object({id:q.number().int(),title:q.string()})}),q.object({...tt,kind:q.literal("invoice_issued"),invoice:q.object({title:q.string(),amountCny:q.number().int()})}),q.object({...tt,kind:q.literal("invoice_rejected"),invoice:q.object({title:q.string()}),reason:q.string()}),q.object({...tt,kind:q.literal("refund_approved"),refund:q.object({orderNo:q.string(),orderType:Ka,amountCny:q.number().int()})}),q.object({...tt,kind:q.literal("refund_rejected"),refund:q.object({orderNo:q.string(),orderType:Ka}),reason:q.string()}),q.object({...tt,kind:q.literal("subscription_expiring"),subscription:q.object({planName:q.string(),expiresAt:q.string()})}),q.object({...tt,kind:q.literal("email_changed"),newEmail:q.string()}),q.object({...tt,kind:q.literal("new_device_login"),ip:q.string(),device:cc.nullable()})]),rd=q.object({unread:q.boolean()});var id="Asia/Shanghai",nx="+08:00";function ox(e){return new Date(new Date(e).getTime()+288e5)}function rx(e=Date.now()){let t=ox(e);return{day:t.toISOString().slice(0,10),hour:t.getUTCHours()}}function Ec(e=Date.now()){return rx(e).day}function Mc(e=Ec()){return new Date(`${e}T00:00:00${nx}`)}function Gn(e,t){let n=new Date(`${e}T00:00:00Z`);return new Date(n.getTime()+t*864e5).toISOString().slice(0,10)}var ix=new Intl.DateTimeFormat("zh-CN",{dateStyle:"short",timeStyle:"medium",timeZone:id}),sx=new Intl.DateTimeFormat("zh-CN",{dateStyle:"long",timeZone:id});function K(e){return ix.format(new Date(e))}function Ur(e){return sx.format(new Date(e))}var[ax,...cx]=[{min:0,name:"\u65B0\u624B"},{min:20,name:"\u5165\u95E8"},{min:100,name:"\u8FDB\u9636"},{min:300,name:"\u719F\u7EC3"},{min:800,name:"\u9AD8\u624B"},{min:2e3,name:"\u4E13\u5BB6"},{min:5e3,name:"\u5927\u5E08"}];function Hi(e){let t=1,n=ax;for(let o of cx){if(e<o.min)return{level:t,name:n.name,min:n.min,next:o.min};t+=1,n=o}return{level:t,name:n.name,min:n.min,next:null}}function qi(e){let t=Hi(e);return`Lv.${t.level} ${t.name}`}function Gi(e){let t=Hi(e);return t.next===null?"\u5DF2\u8FBE\u6700\u9AD8\u7B49\u7EA7":`\u8DDD Lv.${t.level+1} \u8FD8\u5DEE ${t.next-e} \u79EF\u5206`}var zi="\u7BA1\u7406\u5458",jr={pending:"\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u4FEE\u6539\u540E\u53EF\u91CD\u65B0\u63D0\u4EA4",removed:"\u5DF2\u88AB\u5C4F\u853D\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1\u4E14\u65E0\u6CD5\u4FEE\u6539"},Jo={pending:"\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1",removed:"\u5DF2\u88AB\u5C4F\u853D\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1"},Ic={pending:"\u65B0\u5934\u50CF\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u65B0\u5934\u50CF\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u53EF\u91CD\u65B0\u4E0A\u4F20",removed:"\u5934\u50CF\u5DF2\u88AB\u5C4F\u853D\uFF0C\u53EF\u91CD\u65B0\u4E0A\u4F20"};function sd(e,t){return t===null?e:`${e}\uFF0C\u539F\u56E0\uFF1A${t}`}function Nc(e,t){return t.status==="published"?null:sd(e[t.status],t.reviewReason)}function ad(e){return sd(Ic[e.status],e.reviewReason)}var Wi="\u8BE5\u5E16\u5B50\u6682\u4E0D\u53EF\u89C1",lx=4;function cd(e){let t=[],n=new Map;for(let o of e){let r=o.replyTo===null?void 0:n.get(o.replyTo.id),i={reply:o,mention:r===void 0&&o.replyTo!==null?o.replyTo.author:null,children:[]};n.set(o.id,i),r===void 0?t.push(i):r.children.push(i)}return ld(t,1)}function ld(e,t){return t<lx?e.map(n=>({...n,children:ld(n.children,t+1)})):e.flatMap(n=>[{...n,children:[]},...md(n)])}function md(e){return e.children.flatMap(t=>[{reply:t.reply,mention:e.reply.author,children:[]},...md(t)])}function Lc(e){return`${e===null?"\u4F60\u5DF2\u88AB\u6C38\u4E45\u7981\u8A00":`\u4F60\u5DF2\u88AB\u7981\u8A00\u81F3 ${K(e)}`}\uFF0C\u671F\u95F4\u65E0\u6CD5\u53D1\u5E16\u3001\u8BC4\u8BBA\u3001\u7F16\u8F91\u3001\u4E0A\u4F20\u6216\u66F4\u6362\u5934\u50CF\u4E0E\u7528\u6237\u540D`}function Ce(e){let t=e/100;return`${t<0?"-":""}\xA5${Math.abs(t).toFixed(2)}`}function Oc(e){return Math.round(e*100)}function ud(e){return e/100}function dd(e,t,n){let o=e/t;return`${o<0?"-":""}$${Math.abs(o).toLocaleString("en-US",{minimumFractionDigits:n,maximumFractionDigits:n})}`}function Te(e,t){return dd(e,t,2)}function Xo(e,t){return dd(e,t,6)}var fd={post:"\u67E5\u770B\u5E16\u5B50",floor:"\u67E5\u770B\u8BC4\u8BBA",ticket:"\u67E5\u770B\u5DE5\u5355",invoices:"\u67E5\u770B\u53D1\u7968",recharge:"\u67E5\u770B\u5145\u503C\u8BB0\u5F55",subscription:"\u67E5\u770B\u8BA2\u9605",security:"\u67E5\u770B\u8D26\u6237"};function pd(e){return e==="subscription"?{kind:"subscription"}:{kind:"recharge"}}function Dc(e){return e.title===null?"":`\u300C${e.title}\u300D\u4E0B\u7684`}function $c(e){switch(e.kind){case"post_commented":return{title:`${e.actor.username} \u8BC4\u8BBA\u4E86\u4F60\u7684\u5E16\u5B50`,body:`\u300C${e.post.title}\u300D`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_replied":return{title:`${e.actor.username} \u56DE\u590D\u4E86\u4F60\u7684\u8BC4\u8BBA`,body:e.post.title===null?Wi:`\u300C${e.post.title}\u300D`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"post_approved":return{title:"\u5E16\u5B50\u5DF2\u901A\u8FC7\u5BA1\u6838",body:`\u300C${e.post.title}\u300D\u5DF2\u516C\u5F00\u53D1\u5E03`,target:{kind:"post",postId:e.post.id}};case"post_rejected":return{title:"\u5E16\u5B50\u672A\u901A\u8FC7\u5BA1\u6838",body:`\u300C${e.post.title}\u300D\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u4FEE\u6539\u540E\u53EF\u91CD\u65B0\u63D0\u4EA4`,target:{kind:"post",postId:e.post.id}};case"post_removed":return{title:"\u5E16\u5B50\u5DF2\u88AB\u5C4F\u853D",body:`\u300C${e.post.title}\u300D\u5DF2\u88AB\u5C4F\u853D\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"post",postId:e.post.id}};case"comment_approved":return{title:"\u8BC4\u8BBA\u5DF2\u901A\u8FC7\u5BA1\u6838",body:`${Dc(e.post)}\u8BC4\u8BBA\u5DF2\u516C\u5F00\u53D1\u5E03`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_rejected":return{title:"\u8BC4\u8BBA\u672A\u901A\u8FC7\u5BA1\u6838",body:`${Dc(e.post)}\u8BC4\u8BBA\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"comment_removed":return{title:"\u8BC4\u8BBA\u5DF2\u88AB\u5C4F\u853D",body:`${Dc(e.post)}\u8BC4\u8BBA\u5DF2\u88AB\u5C4F\u853D\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:{kind:"floor",postId:e.post.id,floorId:e.comment.floorId}};case"avatar_approved":return{title:"\u5934\u50CF\u5DF2\u901A\u8FC7\u5BA1\u6838",body:"\u5934\u50CF\u5DF2\u516C\u5F00\u663E\u793A",target:{kind:"security"}};case"avatar_rejected":return{title:"\u5934\u50CF\u672A\u901A\u8FC7\u5BA1\u6838",body:`\u65B0\u5934\u50CF\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u53EF\u91CD\u65B0\u4E0A\u4F20`,target:{kind:"security"}};case"avatar_removed":return{title:"\u5934\u50CF\u5DF2\u88AB\u5C4F\u853D",body:`\u5934\u50CF\u5DF2\u88AB\u5C4F\u853D\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u53EF\u91CD\u65B0\u4E0A\u4F20`,target:{kind:"security"}};case"ticket_replied":return{title:"\u5DE5\u5355\u6709\u65B0\u56DE\u590D",body:`\u5DE5\u5355\u300C${e.ticket.title}\u300D\u6536\u5230\u7BA1\u7406\u5458\u56DE\u590D`,target:{kind:"ticket",ticketId:e.ticket.id}};case"invoice_issued":return{title:"\u53D1\u7968\u5DF2\u5F00\u5177",body:`\u62AC\u5934\u300C${e.invoice.title}\u300D\u91D1\u989D ${Ce(e.invoice.amountCny)} \u7684\u53D1\u7968\u5DF2\u5F00\u5177`,target:{kind:"invoices"}};case"invoice_rejected":return{title:"\u5F00\u7968\u7533\u8BF7\u88AB\u9A73\u56DE",body:`\u62AC\u5934\u300C${e.invoice.title}\u300D\u7684\u5F00\u7968\u7533\u8BF7\u88AB\u9A73\u56DE\uFF0C\u539F\u56E0\uFF1A${e.reason}\uFF1B\u53EF\u4FEE\u6B63\u4FE1\u606F\u540E\u91CD\u65B0\u7533\u8BF7`,target:{kind:"invoices"}};case"refund_approved":return{title:"\u9000\u6B3E\u7533\u8BF7\u5DF2\u901A\u8FC7",body:`\u8BA2\u5355 ${e.refund.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\u5DF2\u901A\u8FC7\uFF0C${Ce(e.refund.amountCny)} \u5C06\u539F\u8DEF\u9000\u56DE\u652F\u4ED8\u5B9D\u8D26\u6237`,target:pd(e.refund.orderType)};case"refund_rejected":return{title:"\u9000\u6B3E\u7533\u8BF7\u88AB\u9A73\u56DE",body:`\u8BA2\u5355 ${e.refund.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\u88AB\u9A73\u56DE\uFF0C${e.refund.orderType==="subscription"?"\u8BA2\u9605\u65F6\u957F\u5DF2\u6062\u590D":"\u5230\u8D26\u989D\u5EA6\u5DF2\u6062\u590D"}\uFF0C\u539F\u56E0\uFF1A${e.reason}`,target:pd(e.refund.orderType)};case"subscription_expiring":return{title:"\u8BA2\u9605\u5373\u5C06\u5230\u671F",body:`\u5957\u9910\u300C${e.subscription.planName}\u300D\u5C06\u4E8E ${K(e.subscription.expiresAt)} \u5230\u671F\uFF0C\u5230\u671F\u540E\u5C06\u65E0\u6CD5\u7EE7\u7EED\u4F7F\u7528\u5957\u9910\u5185\u989D\u5EA6`,target:{kind:"subscription"}};case"email_changed":return{title:"\u90AE\u7BB1\u5DF2\u53D8\u66F4",body:`\u8D26\u53F7\u90AE\u7BB1\u5DF2\u53D8\u66F4\u4E3A ${e.newEmail}\uFF0C\u5982\u679C\u4E0D\u662F\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u7ACB\u5373\u8054\u7CFB\u7BA1\u7406\u5458`,target:{kind:"security"}};case"new_device_login":return{title:"\u65B0\u8BBE\u5907\u767B\u5F55\u63D0\u9192",body:`\u8D26\u53F7\u5728\u65B0\u8BBE\u5907\u4E0A\u767B\u5F55\uFF1A${Go(e.device)}\uFF0CIP \u5730\u5740 ${e.ip}\uFF1B\u5982\u679C\u4E0D\u662F\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u7ACB\u5373\u4FEE\u6539\u5BC6\u7801`,target:{kind:"security"}}}}function Hr(e){if(e===void 0)return"";let t="";for(let n of e)switch(n.type){case"codespan":case"escape":case"html":case"image":t+=n.text;break;case"br":t+=" ";break;case"link":case"strong":case"em":case"del":t+=Hr(n.tokens);break;case"text":t+="tokens"in n&&n.tokens!==void 0?Hr(n.tokens):n.text;break}return t}function Bc(e){if(e===void 0)return[];let t=[];for(let n of e)switch(n.type){case"paragraph":case"heading":t.push(Hr(n.tokens));break;case"text":t.push("tokens"in n&&n.tokens!==void 0?Hr(n.tokens):n.text);break;case"code":case"html":t.push(n.text);break;case"blockquote":t.push(...Bc(n.tokens));break;case"list":n.items.forEach(o=>t.push(...Bc(o.tokens)));break;case"table":[...n.header,...n.rows.flat()].forEach(o=>t.push(Hr(o.tokens)));break}return t}function gd(e){return Bc(e).join(" ").replace(/\s+/g," ").trim()}var mx=[{name:"\u4E00\u6574\u4E2A left-pad npm \u5305",tokens:110},{name:"\u5409\u5C3C\u65AF\u7EAA\u5F55\u6700\u5065\u8C08\u9E66\u9E49\u6BD5\u751F\u5B66\u4F1A\u7684\u8BCD\u6C47",tokens:2200},{name:"\u300A\u8BBA\u8BED\u300B",tokens:25e3},{name:"\u300A\u5C0F\u738B\u5B50\u300B",tokens:3e4},{name:"\u300A\u96F7\u950B\u65E5\u8BB0\u300B",tokens:54e3},{name:"\u300A\u8BD7\u7ECF\u300B",tokens:6e4},{name:"\u5468\u6770\u4F26\u5341\u4E94\u5F20\u4E13\u8F91\u7684\u5168\u90E8\u6B4C\u8BCD",tokens:82e3},{name:"\u300A\u6D3B\u7740\u300B",tokens:11e4},{name:"\u300A\u970D\u6BD4\u7279\u4EBA\u300B",tokens:12e4},{name:"\u300A\u4E2D\u534E\u4EBA\u6C11\u5171\u548C\u56FD\u6C11\u6CD5\u5178\u300B",tokens:126e3},{name:"\u300A\u94F6\u6CB3\u7CFB\u642D\u8F66\u5BA2\u6307\u5357\u300B\u4E94\u90E8\u66F2",tokens:26e4},{name:"\u79E6\u59CB\u7687\u4E00\u5929\u6279\u9605\u7684\u7AF9\u7B80\u594F\u7AE0",tokens:34e4},{name:"\u300A\u7EB3\u5C3C\u4E9A\u4F20\u5947\u300B\u5168\u4E03\u518C",tokens:45e4},{name:"\u300A\u5802\u5409\u8BC3\u5FB7\u300B",tokens:56e4},{name:"\u300A\u9B54\u6212\u300B\u4E09\u90E8\u66F2",tokens:59e4},{name:"\u300A\u804A\u658B\u5FD7\u5F02\u300B",tokens:6e5},{name:"\u300A\u6218\u4E89\u4E0E\u548C\u5E73\u300B",tokens:76e4},{name:"\u300A\u65B0\u534E\u5B57\u5178\u300B",tokens:8e5},{name:"\u300A\u7EA2\u697C\u68A6\u300B",tokens:9e5},{name:"\u300A\u897F\u6E38\u8BB0\u300B",tokens:1e6},{name:"\u300A\u4E09\u4F53\u300B\u4E09\u90E8\u66F2",tokens:11e5},{name:"\u838E\u58EB\u6BD4\u4E9A\u5168\u96C6",tokens:115e4},{name:"\u300A\u7504\u5B1B\u4F20\u300B\u5168\u5267\u5267\u672C",tokens:12e5},{name:"\u963F\u6CE2\u7F57 11 \u53F7\u767B\u6708\u5236\u5BFC\u7A0B\u5E8F\u6E90\u7801",tokens:13e5},{name:"\u300A\u54C8\u5229\xB7\u6CE2\u7279\u300B\u5168\u4E03\u90E8",tokens:14e5},{name:"\u8FC4\u4ECA\u51FA\u571F\u7684\u5168\u90E8\u7532\u9AA8\u6587",tokens:15e5},{name:"\u5409\u5C3C\u65AF\u7EAA\u5F55\u6700\u957F\u5C0F\u8BF4\u300A\u8FFD\u5FC6\u4F3C\u6C34\u5E74\u534E\u300B",tokens:165e4},{name:"\u300A\u51B0\u4E0E\u706B\u4E4B\u6B4C\u300B\u5DF2\u51FA\u4E94\u5377",tokens:226e4},{name:"\u300A\u65F6\u5149\u4E4B\u8F6E\u300B\u5168\u5341\u56DB\u5377",tokens:57e5},{name:"\u300A\u5168\u5510\u8BD7\u300B",tokens:64e5},{name:"\u300A\u9C81\u8FC5\u5168\u96C6\u300B",tokens:85e5},{name:"\u91D1\u5EB8\u5341\u4E94\u90E8\u5C0F\u8BF4",tokens:105e5},{name:"\u300A\u8F9E\u6D77\u300B",tokens:282e5},{name:"\u300A\u5927\u82F1\u767E\u79D1\u5168\u4E66\u300B",tokens:52e6},{name:"\u4E00\u6574\u5E74\u300A\u4EBA\u6C11\u65E5\u62A5\u300B",tokens:53e6},{name:"\u300A\u4E8C\u5341\u56DB\u53F2\u300B",tokens:6e7},{name:"\u300A\u725B\u6D25\u82F1\u8BED\u8BCD\u5178\u300B\u7B2C\u4E8C\u7248",tokens:767e5},{name:"\u5355\u7530\u82B3\u6BD5\u751F\u8BC4\u4E66\u4F5C\u54C1",tokens:86e6},{name:"\u300A\u4E2D\u56FD\u5927\u767E\u79D1\u5168\u4E66\u300B\u7B2C\u4E00\u7248",tokens:1508e5},{name:"\u6574\u5957 Linux \u5185\u6838\u6E90\u7801",tokens:4e8},{name:"\u4E00\u4E2A\u666E\u901A\u4EBA\u4E00\u751F\u8BF4\u51FA\u7684\u5168\u90E8\u8BDD\u8BED",tokens:5e8},{name:"\u4E2D\u6587\u7EF4\u57FA\u767E\u79D1",tokens:1e9},{name:"\u300A\u56DB\u5E93\u5168\u4E66\u300B",tokens:12e8},{name:"\u82F1\u6587\u7EF4\u57FA\u767E\u79D1",tokens:676e7},{name:"\u8C37\u6B4C\u5168\u90E8\u4EE3\u7801\u5E93",tokens:2e10}];function ux(e){return e>=10?Math.round(e).toLocaleString("en-US"):e>=1?e.toFixed(1):e.toFixed(-Math.floor(Math.log10(e)))}function Dt(e){return e>=10?Math.round(e).toLocaleString("en-US"):e.toFixed(1)}function hd(e){return e<365?`${Dt(e)} \u5929`:`${Dt(e/365)} \u5E74`}function dx(e){let t=e/1.2/250/60;if(t<48)return`${Math.max(1,Math.round(t))} \u5C0F\u65F6`;let n=t/24;return n<730?`${Math.round(n)} \u5929`:`${Dt(n/365)} \u5E74`}function px(e){let t=e/1.2/80/60/8;return t<250?`${Dt(t)} \u4E2A\u5DE5\u4F5C\u65E5`:`${Dt(t/250)} \u4E2A\u5DE5\u4F5C\u5E74`}function fx(e){let t=e/1.2/30*4;return t<1e3?`${Math.round(t).toLocaleString("en-US")} \u514B`:t<1e6?`${Dt(t/1e3)} \u516C\u65A4`:`${Dt(t/1e6)} \u5428`}var gx=[...mx.map(e=>({min:e.tokens/10,max:e.tokens*1e4,suffix:t=>`\u7EA6\u4E3A${e.name}\u7684 ${ux(t/e.tokens)} \u500D`})),{min:3e5,max:1/0,suffix:e=>`\u6253\u5370\u6210 A4 \u7EB8\u7EA6\u6709 ${Math.round(e/1.2/1500).toLocaleString("en-US")} \u9875`},{min:3e5,max:1/0,suffix:e=>`\u6309\u6BCF\u5206\u949F 250 \u5B57\u7684\u8BED\u901F\u6717\u8BFB\u7EA6\u9700 ${dx(e)}`},{min:1680,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Math.round(e/1.2/140).toLocaleString("en-US")} \u6761\u5199\u6EE1 140 \u5B57\u7684\u5FAE\u535A`},{min:9600,max:1/0,suffix:e=>`\u7EA6\u5408 ${Math.round(e/1.2/800).toLocaleString("en-US")} \u7BC7 800 \u5B57\u7684\u9AD8\u8003\u4F5C\u6587`},{min:131400,max:1/0,suffix:e=>`\u6309\u6BCF\u5929\u4E00\u7BC7 300 \u5B57\u7684\u65E5\u8BB0\u8BA1\uFF0C\u591F\u8FDE\u7EED\u5199 ${Dt(e/1.2/300/365)} \u5E74`},{min:12e5,max:1/0,suffix:e=>`\u7EA6\u5408 ${Math.round(e/1.2/1e5).toLocaleString("en-US")} \u672C\u5341\u4E07\u5B57\u7684\u535A\u58EB\u8BBA\u6587`},{min:33e3,max:1/0,suffix:e=>`\u6309\u300A\u8D44\u6CBB\u901A\u9274\u300B\u7684\u7B14\u58A8\u5BC6\u5EA6\uFF0C\u7EA6\u591F\u53F8\u9A6C\u5149\u8BB0\u8F7D ${Math.round(e/45e5*1362).toLocaleString("en-US")} \u5E74\u5386\u53F2`},{min:49e3,max:1/0,suffix:e=>`\u7EA6\u5408\u300A\u4E00\u5343\u96F6\u4E00\u591C\u300B\u91CC\u5C71\u9C81\u4F50\u5FB7\u8BB2\u6545\u4E8B\u7684 ${Math.round(e/492e4*1001).toLocaleString("en-US")} \u4E2A\u591C\u665A`},{min:640,max:1/0,suffix:e=>`\u6309\u91D1\u9675\u523B\u7ECF\u5904\u523B\u5DE5\u534A\u6708\u523B\u6210\u4E00\u5757 800 \u5B57\u7ECF\u7248\u7684\u8FDB\u5EA6\uFF0C\u5168\u90E8\u523B\u4E0A\u96D5\u7248\u9700\u8981 ${hd(e/1.2/53)}`},{min:460800,max:1/0,suffix:e=>`\u6309\u6BCF\u5206\u949F 80 \u5B57\u3001\u6BCF\u5929 8 \u5C0F\u65F6\u8BA1\uFF0C\u591F\u4E00\u4F4D\u4E13\u804C\u6253\u5B57\u5458\u6253 ${px(e)}`},{min:4500,max:1/0,suffix:e=>`\u82E5\u523B\u6210\u6BCF\u679A 30 \u5B57\u7684\u79E6\u6C49\u7AF9\u7B80\uFF0C\u603B\u91CD\u7EA6 ${fx(e)}`},{min:18e3,max:1/0,suffix:e=>`\u6309\u300A\u6C38\u4E50\u5927\u5178\u300B\u91CD\u5F55\u4E66\u624B\u6BCF\u5929\u4E09\u53F6\u3001\u7EA6 1500 \u5B57\u7684\u5B9A\u989D\uFF0C\u591F\u4E00\u4F4D\u4E66\u624B\u6284\u5199 ${hd(e/1.2/1500)}`},{min:108e3,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Math.round(e/1.2/9e3).toLocaleString("en-US")} \u671F\u300A\u65B0\u95FB\u8054\u64AD\u300B\u7684\u64AD\u62A5\u7A3F`},{min:4e4,max:1/0,suffix:e=>`\u7EA6\u7B49\u4E8E ${Dt(e/1.2/33e3)} \u5C4A\u592E\u89C6\u6625\u665A\u7684\u5168\u90E8\u53F0\u8BCD\u548C\u6B4C\u8BCD`},{min:96e3,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u6807\u51C6 400 \u7C73\u8DD1\u9053 ${Dt(e/1.2*.005/400)} \u5708`},{min:96e5,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u5408\u5730\u9762\u5230\u56FD\u9645\u7A7A\u95F4\u7AD9\u8DDD\u79BB\u7684 ${Dt(e/1.2*.005/4e5)} \u500D`},{min:26e7,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u6708\u7403\u8D64\u9053 ${Dt(e/1.2*.005/10917e3)} \u5708`},{min:96e7,max:1/0,suffix:e=>`\u6362\u7B97\u6210\u6C49\u5B57\u6309\u6BCF\u5B57 5 \u6BEB\u7C73\u9996\u5C3E\u76F8\u63A5\u6392\u5F00\uFF0C\u7EA6\u80FD\u7ED5\u5730\u7403\u8D64\u9053 ${Dt(e/1.2*.005/40075e3)} \u5708`}];function yd(e){let{tokens:t,scope:n,range:o}=e;if(t<=0)return null;let r=gx.filter(c=>t>=c.min&&t<=c.max),i=r[Math.floor(Math.random()*r.length)];return i?`${n==="user"?"\u4F60":"\u5168\u7AD9"}${o==="all"?"\u7D2F\u8BA1":o==="30d"?"\u8FD1 30 \u5929":"\u8FD1 7 \u5929"}\u4F7F\u7528\u7684 Token \u91CF${i.suffix(t)}`:null}function Cn(e){return t=>{let n=e[t];if(!n)throw new Error(`unknown status value: ${t}`);return n}}function $t(e){return t=>{let n=e[t];if(!n)throw new Error(`unknown label value: ${t}`);return n}}var zn=Cn({pending:{label:"\u5F85\u652F\u4ED8",tone:"warning"},paid:{label:"\u5DF2\u652F\u4ED8",tone:"success"},refund_requested:{label:"\u9000\u6B3E\u5BA1\u6838\u4E2D",tone:"warning"},partially_refunded:{label:"\u90E8\u5206\u9000\u6B3E",tone:"warning"},refunded:{label:"\u5DF2\u9000\u6B3E",tone:"danger"},failed:{label:"\u5931\u8D25",tone:"danger"},expired:{label:"\u5DF2\u8FC7\u671F",tone:"neutral"}}),EP=$t({recharge:"\u5145\u503C",subscription:"\u8BA2\u9605"}),Vi=Cn({pending:{label:"\u5F85\u5904\u7406",tone:"warning"},issued:{label:"\u5DF2\u5F00\u5177",tone:"success"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"}}),MP=Cn({active:{label:"\u6B63\u5E38",tone:"success"},disabled:{label:"\u7981\u7528",tone:"danger"}}),Fc=$t({subscription_first:"\u8BA2\u9605\u4F18\u5148",balance_first:"\u4F59\u989D\u4F18\u5148",subscription_only:"\u4EC5\u8BA2\u9605",balance_only:"\u4EC5\u4F59\u989D"}),Uc=$t({subscription_first:"\u6709\u53EF\u7528\u8BA2\u9605\u65F6\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6\uFF0C\u8BA2\u9605\u7528\u5C3D\u6216\u672A\u8986\u76D6\u5F53\u524D\u5206\u7EC4\u65F6\u6539\u6263\u4F59\u989D",balance_first:"\u4F59\u989D\u5145\u8DB3\u65F6\u6263\u4F59\u989D\uFF0C\u4F59\u989D\u4E0D\u8DB3\u65F6\u6539\u7528\u8BA2\u9605\u989D\u5EA6",subscription_only:"\u53EA\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6\uFF0C\u8BA2\u9605\u7528\u5C3D\u6216\u672A\u8986\u76D6\u5F53\u524D\u5206\u7EC4\u65F6\u62D2\u7EDD\u8BF7\u6C42",balance_only:"\u53EA\u6263\u8D26\u6237\u4F59\u989D\uFF0C\u4E0D\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6"}),bd=Wa.map(e=>({value:e,label:Fc(e)})),jc=$t({recharge:"\u5145\u503C",reserve:"\u9884\u6263",consume:"\u6D88\u8D39",reserve_refund:"\u9884\u6263\u9000\u56DE",refund:"\u9000\u6B3E",refund_release:"\u9000\u6B3E\u8FD4\u8FD8",reward:"\u5956\u52B1",admin_adjust:"\u7BA1\u7406\u5458\u8C03\u6574"}),Sd=$t({usage_log:"\u7528\u91CF",order:"\u8BA2\u5355",invitation:"\u9080\u8BF7",admin:"\u7BA1\u7406\u5458"}),xd=Cn({requested:{label:"\u5F85\u5BA1\u6838",tone:"warning"},pending:{label:"\u5F85\u786E\u8BA4",tone:"warning"},succeeded:{label:"\u5DF2\u9000\u6B3E",tone:"success"},failed:{label:"\u5931\u8D25",tone:"danger"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"},canceled:{label:"\u5DF2\u64A4\u9500",tone:"neutral"}}),Ki=Cn({success:{label:"\u6210\u529F",tone:"success"},error:{label:"\u5931\u8D25",tone:"danger"},canceled:{label:"\u53D6\u6D88",tone:"neutral"},anomaly:{label:"\u5F02\u5E38",tone:"warning"}}),Td=$t({"openai-chat":"OpenAI Chat","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"}),qr=$t({special:"\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968",general:"\u589E\u503C\u7A0E\u666E\u901A\u53D1\u7968"}),uo=$t({special:"\u4E13\u7968",general:"\u666E\u7968"}),Yi=$t({first_inviter:"\u9996\u5145\u8FD4\u5229\uFF08\u9080\u8BF7\u4EBA\uFF09",first_invitee:"\u9996\u5145\u8FD4\u5229\uFF08\u88AB\u9080\u8BF7\u4EBA\uFF09",subsequent_inviter:"\u7EED\u5145\u8FD4\u5229\uFF08\u9080\u8BF7\u4EBA\uFF09"}),Gr=Cn({info:{label:"\u4FE1\u606F",tone:"neutral"},success:{label:"\u6210\u529F",tone:"success"},warning:{label:"\u8B66\u544A",tone:"warning"},error:{label:"\u91CD\u8981",tone:"danger"}}),Hc=Cn({open:{label:"\u5F85\u5904\u7406",tone:"warning"},replied:{label:"\u5DF2\u56DE\u590D",tone:"success"},closed:{label:"\u5DF2\u5173\u95ED",tone:"neutral"}}),Ji=$t({billing:"\u8BA1\u8D39",technical:"\u6280\u672F",account:"\u8D26\u53F7",other:"\u5176\u4ED6"}),qc=Cn({low:{label:"\u8F83\u4F4E",tone:"neutral"},normal:{label:"\u666E\u901A",tone:"neutral"},high:{label:"\u7D27\u6025",tone:"danger"}}),wd=$t({openai:"OpenAI",anthropic:"Anthropic"}),po=Cn({pending:{label:"\u5BA1\u6838\u4E2D",tone:"warning"},published:{label:"\u5DF2\u53D1\u5E03",tone:"success"},rejected:{label:"\u672A\u901A\u8FC7",tone:"danger"},removed:{label:"\u5DF2\u5C4F\u853D",tone:"danger"}}),kd=$t({spam:"\u5783\u573E\u5E7F\u544A",abuse:"\u4EBA\u8EAB\u653B\u51FB",explicit:"\u8272\u60C5\u4F4E\u4FD7",illegal:"\u8FDD\u6CD5\u8FDD\u89C4",privacy:"\u6CC4\u9732\u9690\u79C1",other:"\u5176\u4ED6"}),vd=$t({activity:"\u6700\u65B0\u56DE\u590D",published:"\u6700\u65B0\u53D1\u5E03"});function _t(e,t,n){let o=r=>{let i=t(r);return typeof i=="string"?i:i.label};return[{value:"",label:n},...e.map(r=>({value:r,label:o(r)}))]}function Zi(e){return`${e.name} \xD7${e.multiplier}`}var Xi=10080,Qi=1440;function Cd(e){if(e%Xi===0){let t=e/Xi;return t===1?"\u6BCF\u5468\u9650\u989D":`${t} \u5468\u9650\u989D`}if(e%Qi===0){let t=e/Qi;return t===1?"\u6BCF\u65E5\u9650\u989D":`${t} \u5929\u9650\u989D`}return e%60===0?`${e/60} \u5C0F\u65F6\u9650\u989D`:`${e} \u5206\u949F\u9650\u989D`}function hx(e){if(e%Xi===0){let t=e/Xi;return t===1?"\u6BCF\u5468":`\u6BCF ${t} \u5468`}if(e%Qi===0){let t=e/Qi;return t===1?"\u6BCF\u5929":`\u6BCF ${t} \u5929`}return e%60===0?`\u6BCF ${e/60} \u5C0F\u65F6`:`\u6BCF ${e} \u5206\u949F`}function Rd(e,t){return e.windows.map(n=>`${hx(n.durationMinutes)} ${Te(n.quota,t)}`)}function Gc(e){return Math.min(100,Math.floor(e.used/e.quota*100))}function zc(e){return e.revokedAt!==null?{label:"\u5DF2\u4F5C\u5E9F",tone:"danger"}:new Date(e.expiresAt).getTime()<=Date.now()?{label:"\u5DF2\u8FC7\u671F",tone:"neutral"}:{label:"\u751F\u6548\u4E2D",tone:"success"}}var Wc={recharge:["\u5145\u9519\u91D1\u989D\u6216\u91CD\u590D\u5145\u503C","\u9700\u8981\u7684\u6A21\u578B\u4E0D\u53EF\u7528","\u8C03\u7528\u7ECF\u5E38\u62A5\u9519\u6216\u8D85\u65F6","\u5B9E\u9645\u8BA1\u8D39\u9AD8\u4E8E\u9884\u671F","\u4F59\u989D\u7528\u4E0D\u5B8C\uFF0C\u4E0D\u518D\u9700\u8981"],subscription:["\u8BEF\u8D2D\u6216\u9009\u9519\u5957\u9910","\u5957\u9910\u4E0D\u542B\u9700\u8981\u7684\u6A21\u578B","\u9650\u989D\u592A\u4F4E\uFF0C\u4E0D\u591F\u7528","\u8C03\u7528\u7ECF\u5E38\u62A5\u9519\u6216\u8D85\u65F6","\u4F7F\u7528\u9891\u7387\u4F4E\uFF0C\u4E0D\u5212\u7B97"]},_d={recharge:"\u63D0\u4EA4\u540E\u672C\u5355\u5269\u4F59\u989D\u5EA6\u4E0E\u5173\u8054\u7684\u9080\u8BF7\u5956\u52B1\u5C06\u7ACB\u5373\u4ECE\u4F59\u989D\u6536\u56DE\uFF1B\u5BA1\u6838\u901A\u8FC7\u540E\u539F\u8DEF\u9000\u56DE\u652F\u4ED8\u5B9D\uFF0C\u9A73\u56DE\u6216\u64A4\u9500\u540E\u81EA\u52A8\u6062\u590D",subscription:"\u63D0\u4EA4\u540E\u672C\u5355\u672A\u5F00\u59CB\u7684\u65F6\u957F\u7ACB\u5373\u5931\u6548\uFF0C\u6B63\u5728\u670D\u52A1\u4E2D\u7684\u65F6\u6BB5\u4FDD\u7559\u81F3\u5F53\u524D\u9650\u989D\u5468\u671F\u7ED3\u675F\uFF1B\u5BA1\u6838\u901A\u8FC7\u540E\u6309\u672A\u5F00\u59CB\u7684\u9650\u989D\u5468\u671F\u6298\u7B97\u539F\u8DEF\u9000\u6B3E\uFF0C\u9A73\u56DE\u6216\u64A4\u9500\u540E\u81EA\u52A8\u6062\u590D"};import{release as yx}from"os";var bx=3e4,Sx=nu({cliVersion:Vt,platform:process.platform,release:yx(),arch:process.arch,nodeVersion:process.versions.node});async function Pd(e,t){if(t.json!==void 0&&t.body!==void 0)throw new Error("httpRequest cannot accept both json and body");let n=new Headers(t.headers);n.set("user-agent",Sx);let o=t.body;t.json!==void 0&&(n.set("content-type","application/json"),o=JSON.stringify(t.json));try{return await fetch(e,{method:t.method??(o===void 0?"GET":"POST"),headers:n,body:o,signal:AbortSignal.timeout(t.timeoutMs??bx),redirect:"follow"})}catch(r){let i=URL.canParse(e)?new URL(e).origin:e;throw new U(`\u65E0\u6CD5\u8FDE\u63A5 ${i}\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u7AD9\u70B9\u5730\u5740`,{exitCode:Cm,cause:r})}}async function Ad(e){let t=await e.text();if(t==="")return null;try{return JSON.parse(t)}catch{return null}}async function Jt(e,t={}){let n=await Pd(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Ad(n)};let o=await n.text(),r=null;if(o!=="")try{r=JSON.parse(o)}catch(i){throw new U(`${e} \u8FD4\u56DE\u4E86\u975E JSON \u5185\u5BB9\uFF0C\u53EF\u80FD\u88AB\u7F51\u5173\u6216\u4E2D\u95F4\u8BBE\u5907\u62E6\u622A`,{cause:i})}return{status:n.status,ok:!0,headers:n.headers,data:r}}async function Ed(e,t={}){let n=await Pd(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Ad(n),bytes:null};let o=new Uint8Array(await n.arrayBuffer());return{status:n.status,ok:!0,headers:n.headers,data:null,bytes:o}}function xx(e,t){let n=eu.safeParse(t);if(!n.success)return new U(`\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${e}\uFF09`);let{code:o,message:r}=n.data.error,i=o==="unauthorized"||o==="token_expired"?ro:void 0;return new U(tu[o]??r,i?{exitCode:i}:{})}function sn(e){if(!e.ok)throw xx(e.status,e.data)}var Nd="cf_refresh",Ld="cf_device",Md=6e4;function Id(e,t){for(let n of e.getSetCookie()){let o=n.split(";",1)[0];if(o===void 0)continue;let r=o.indexOf("=");if(!(r<0)&&o.slice(0,r).trim()===t)return o.slice(r+1).trim()}return null}function zr(e,t){return{refresh:Id(t,Nd)??e.refresh,device:Id(t,Ld)??e.device}}function es(e){let t=[];return e.refresh&&t.push(`${Nd}=${e.refresh}`),e.device&&t.push(`${Ld}=${e.device}`),t.length>0?{cookie:t.join("; ")}:{}}function Tx(e){let t=e.split(".")[1];if(t===void 0)throw new U("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u683C\u5F0F\u4E0D\u6B63\u786E");let n;try{n=JSON.parse(Buffer.from(t,"base64url").toString("utf8"))}catch(r){throw new U("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u65E0\u6CD5\u89E3\u6790",{cause:r})}let o=n.exp;if(typeof o!="number")throw new U("\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u8BBF\u95EE\u4EE4\u724C\u7F3A\u5C11\u6709\u6548\u671F");return o*1e3}function Wr(e,t,n){if(!t.refresh)throw new U("\u670D\u52A1\u7AEF\u672A\u4E0B\u53D1\u5237\u65B0\u51ED\u636E\uFF0C\u65E0\u6CD5\u4FDD\u6301\u767B\u5F55\u72B6\u6001");let o={refreshCookie:t.refresh,accessToken:n.accessToken,accessExpiresAt:Tx(n.accessToken),username:n.user.username,email:n.user.email,site:e};return za(r=>{r.session=o,t.device&&(r.device={site:e,cookie:t.device})}),o}function Vc(e){let{device:t}=Lt();return t!==null&&t.site===e?t.cookie:null}async function Od(e,t,n){let o={refresh:null,device:Vc(e)},r=await Jt(`${e}/api/auth/login`,{json:{account:t,password:n},headers:es(o)});sn(r);let i=au.parse(r.data),s=zr(o,r.headers);return i.status==="totp_required"?{status:"totp_required",ticket:i.ticket,jar:s}:{status:"ok",session:Wr(e,s,i)}}async function Dd(e,t,n,o,r){let s=await Jt(`${e}/api/auth/${r==="totp"?"login/totp":"login/recovery-code"}`,{json:{ticket:n,code:o},headers:es(t)});sn(s);let a=zo.parse(s.data);return Wr(e,zr(t,s.headers),a)}function ts(){za(e=>{e.session=null})}async function wx(e){let t={refresh:e.refreshCookie,device:Vc(e.site)},n=await Jt(`${e.site}/api/auth/refresh`,{method:"POST",headers:es(t)});if(n.status===401||n.status===403)throw ts(),new U("\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",{exitCode:ro});sn(n);let o=zo.parse(n.data);return Wr(e.site,zr(t,n.headers),o)}async function Vr(e=!1){let t=Lm();return!e&&Date.now()<t.accessExpiresAt-Md?t:Om(async()=>{let n=Nm().session;if(!n)throw new U("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:ro});return(n.refreshCookie!==t.refreshCookie||n.accessToken!==t.accessToken)&&Date.now()<n.accessExpiresAt-Md?n:wx(n)})}async function ns(){let e=Lt().session;if(!e)return;let t=await Jt(`${e.site}/api/auth/logout`,{method:"POST",headers:es({refresh:e.refreshCookie,device:Vc(e.site)})});ts(),sn(t)}import{spawn as kx}from"child_process";function Kr(e,t={}){return new Promise((n,o)=>{let r=kx("npm",e,{stdio:["ignore","pipe","pipe"],shell:process.platform==="win32"}),i=[],s=[],a=c=>{for(let l of c.toString("utf8").split(`
4
- `)){let u=l.trimEnd();u!==""&&(s.push(u),s.length>20&&s.shift())}};r.stdout.on("data",c=>{i.push(c.toString("utf8")),a(c)}),r.stderr.on("data",a),r.on("error",c=>o(new U(`\u6267\u884C npm \u5931\u8D25\uFF1A${c.message}`,{cause:c}))),r.on("close",c=>{if(c===0){n(i.join(""));return}let l=s.slice(-2).join(" / ");o(new U(`npm ${e.join(" ")} \u9000\u51FA\u7801 ${c??"null"}`,{...l===""?{}:{hint:l}}))}),t.background===!0&&(r.stdout.unref(),r.stderr.unref(),r.unref())})}async function $d(e){let t=[],n=async(o,r)=>{try{await r(),e.done(o)}catch(i){t.push(`${o}\uFF1A${xe(i)}`),e.failed(o)}};return await n("\u9000\u51FA\u767B\u5F55",()=>ns()),await n("\u5220\u9664\u672C\u5730\u6587\u4EF6",()=>{let o=vn();vx(o)&&Cx(o,{recursive:!0,force:!0})}),await n("\u5378\u8F7D\u672C\u7A0B\u5E8F",async()=>{await Kr(["uninstall","-g",Fo])}),t}import{z as Yr}from"zod";var Rx=Yr.object({line:Yr.object({name:Yr.string(),url:Yr.string()}).nullable(),lastUpdateCheckAt:Yr.number().nullable()}),Bd=_i(Rx,{line:null,lastUpdateCheckAt:null},_m,"\u672C\u5730\u914D\u7F6E","\u91CD\u65B0\u8FD0\u884C"),fo=Bd.load,os=Bd.update;var _x=1440*60*1e3;async function Fd(){let e=(await Kr(["view",Fo,"version"])).trim();if(e==="")throw new U(`npm \u6CA1\u6709\u62A5\u51FA ${Fo} \u7684\u7248\u672C`);return e}async function Ud(e,t){return await Kr(["install","-g",`${Fo}@${e}`],{background:t}),e}async function jd(){let e=await Fd();return e===Vt?null:await Ud(e,!1)}function Px(){let e=Date.now(),t=fo().lastUpdateCheckAt;return t!==null&&e-t<_x?!1:(os(n=>{n.lastUpdateCheckAt=e}),!0)}async function Hd(){if(!Px())return null;let e;try{e=await Fd()}catch{return null}return e===Vt?null:await Ud(e,!0)}import{Box as NR,render as LR,useInput as OR}from"ink";import{useEffect as wm,useRef as DR}from"react";async function fn(e,t,n={}){let o=await Jt(t,n);return sn(o),e.parse(o.data)}async function A(e,t,n={}){let o=await Vr(),r=s=>Jt(`${o.site}/api${t}`,{...n,headers:{...n.headers,authorization:`Bearer ${s}`}}),i=await r(o.accessToken);if(i.status===401){let s=await Vr(!0);i=await r(s.accessToken)}return sn(i),e.parse(i.data)}async function Kc(e,t={}){let n=await Vr(),o=i=>Ed(`${n.site}/api${e}`,{...t,headers:{...t.headers,authorization:`Bearer ${i}`}}),r=await o(n.accessToken);if(r.status===401){let i=await Vr(!0);r=await o(i.accessToken)}return sn(r),{bytes:r.bytes,headers:r.headers}}async function rs(e,t={}){return(await Kc(e,t)).bytes}function Fe(e,t){let n=new URLSearchParams;for(let[r,i]of Object.entries(t))i!==void 0&&n.set(r,String(i));let o=n.toString();return o===""?e:`${e}?${o}`}var qd=e=>A(mt(pc),Fe("/announcements",{...e})),Gd=()=>A(pc.nullable(),"/announcements/unread"),is=e=>A(se,`/announcements/${e}/read`,{method:"POST"});import{Box as zd,useWindowSize as Ax}from"ink";import{Children as Ex}from"react";import{jsx as Wd}from"react/jsx-runtime";var Mx=1,Yc=1,X=1;function j(){let{columns:e,rows:t}=Ax();return{width:Math.max(1,e-Mx*2),columns:e,rows:t}}function Vd({height:e,children:t}){return Wd(zd,{flexDirection:"column",height:e,justifyContent:"space-between",children:Ex.toArray(t).map((n,o)=>Wd(zd,{flexDirection:"column",flexShrink:0,children:n},o))})}import{useInput as Kd}from"ink";import{createContext as cs,useCallback as Xc,useContext as Ix,useEffect as Yd,useMemo as Jd,useRef as as,useState as Nx}from"react";import{jsx as ss}from"react/jsx-runtime";var ls=cs(null),Qc=cs(null),Zc=cs(null);function Jc(){let[e,t]=Nx(!1),n=as(0),o=Xc(()=>(n.current+=1,t(!0),()=>{n.current-=1,n.current===0&&t(!1)}),[]);return Jd(()=>({held:e,acquire:o}),[e,o])}var Wn={screen:0,panel:10,input:20},el=cs(null);function Xd({children:e}){let t=Jc(),n=Jc(),o=Jc(),r=as([]),i=as(0),s=Xc(l=>{let u={...l,seq:i.current+=1};return r.current.push(u),()=>{r.current=r.current.filter(m=>m!==u)}},[]),a=Xc(()=>{r.current.reduce((u,m)=>u===null||m.layer>u.layer||m.layer===u.layer&&m.seq>u.seq?m:u,null)?.handler()},[]);Kd((l,u)=>{u.escape&&a()});let c=Jd(()=>({push:s,fire:a}),[s,a]);return ss(ls.Provider,{value:t,children:ss(Qc.Provider,{value:n,children:ss(Zc.Provider,{value:o,children:ss(el.Provider,{value:c,children:e})})})})}function go(e){let t=Ix(e);if(!t)throw new Error("\u952E\u76D8\u94A9\u5B50\u5FC5\u987B\u5728 KeyboardProvider \u5185\u4F7F\u7528");return t}function tl(e,t){let{acquire:n}=go(e);Yd(()=>{if(t)return n()},[t,n])}function ms(e){tl(ls,e)}function Re(e){tl(Qc,e)}function Qd(e){tl(Zc,e)}function us(){return go(Qc).held}function ds(){return go(ls).held}function Zd(){return go(Zc).held}function G(e,t=!0){let n=go(ls).held;Kd(e,{isActive:t&&!n})}function ep(){return go(el).fire}function gn(e,{isActive:t=!0,layer:n=Wn.screen}={}){let{push:o}=go(el),r=as(e);r.current=e,Yd(()=>{if(t)return o({handler:()=>r.current(),layer:n})},[t,n,o])}import{measureElement as Lx}from"ink";import{PassThrough as Ox}from"stream";import{createContext as Dx,useCallback as $x,useContext as Bx,useEffect as rp,useRef as ps}from"react";import{jsx as Kx}from"react/jsx-runtime";var Fx="\x1B[?1000h\x1B[?1003h\x1B[?1006h",Ux="\x1B[?1006l\x1B[?1003l\x1B[?1000l",jx=27,Hx=91,qx=60,tp=77,np=109,op=20,Gx=64,zx=32,Wx=20;function Vx(e){let t=[],n=[],o=0;for(;o<e.length;){let r=e[o];if(r===void 0)break;if(r!==jx){n.push(r),o+=1;continue}let i=e[o+1],s=e[o+2];if(i===void 0||s===void 0)break;if(i!==Hx){n.push(r),o+=1;continue}if(s===tp){if(o+6>e.length)break;o+=6;continue}if(s!==qx){n.push(r),o+=1;continue}let a=o+3,c;for(;a<e.length&&a-o<op;){let d=e[a];if(d===tp||d===np){c=d;break}a+=1}if(c===void 0){if(a-o<op)break;n.push(r),o+=1;continue}let l=e.subarray(o+3,a).toString("latin1").split(";");if(o=a+1,c===np||l.length!==3)continue;let u=Number(l[0]),m=Number(l[1]),p=Number(l[2]);!Number.isFinite(u)||!Number.isFinite(m)||!Number.isFinite(p)||t.push((u&Gx)!==0?{row:p,column:m,kind:"wheel",delta:(u&1)===0?-1:1}:{row:p,column:m,kind:(u&zx)!==0?"move":"press"})}return{events:t,clean:Buffer.from(n),pending:e.subarray(o)}}function ip(e,t){let n=new Set,o=new Ox,r=Buffer.alloc(0),i=null,s=()=>{i=null,r.length!==0&&(o.write(r),r=Buffer.alloc(0))},a=p=>{i!==null&&clearTimeout(i),i=null;let d=Vx(Buffer.concat([r,p]));r=d.pending,d.clean.length>0&&o.write(d.clean);for(let b of d.events)for(let h of n)h(b);r.length>0&&(i=setTimeout(s,Wx))},c=()=>{t.write(Ux)},l={SIGHUP:1,SIGINT:2,SIGTERM:15},u=p=>{process.exit(128+(l[p]??0))};e.on("data",a),process.once("exit",c);for(let p of Object.keys(l))process.on(p,u);t.write(Fx);let m=o;return Object.assign(m,{isTTY:!0,setRawMode(p){return e.setRawMode(p),m},ref(){return e.ref(),m},unref(){return e.unref(),m}}),{stdin:m,subscribe(p){return n.add(p),()=>{n.delete(p)}},dispose(){c(),i!==null&&clearTimeout(i),process.off("exit",c);for(let p of Object.keys(l))process.off(p,u);e.off("data",a),n.clear()}}}var sp=Dx(null);function ap({subscribe:e,children:t}){let n=ps(new Set).current,o=ps(null),r=$x(i=>(n.add(i),()=>{n.delete(i)}),[n]);return rp(()=>e(i=>{let s=i.row-1,a=i.column-1,c=null;for(let u of n){let m=u.node.current;if(m===null||u.handlers.current.isActive===!1)continue;let p=Lx(m);if(s<p.y||s>=p.y+p.height||a<p.x||a>=p.x+p.width)continue;let d=p.width*p.height;(c===null||d<c.area)&&(c={region:u,top:p.y,left:p.x,area:d})}if(i.kind==="move"){let u=c===null?null:c.region;if(o.current!==u){let m=o.current;m!==null&&n.has(m)&&m.handlers.current.onHoverLeave?.(),o.current=u}c!==null&&c.region.handlers.current.onHover?.({row:s-c.top,column:a-c.left});return}if(c===null)return;let l=c.region.handlers.current;i.kind==="wheel"?l.onWheel?.(i.delta):l.onClick?.({row:s-c.top,column:a-c.left})}),[e,n]),Kx(sp.Provider,{value:r,children:t})}function rt(e){let t=Bx(sp);if(t===null)throw new Error("useMouseRegion \u5FC5\u987B\u5728 MouseProvider \u5185\u4F7F\u7528");let n=ps(null),o=ps(e);return o.current=e,rp(()=>t({node:n,handlers:o}),[t]),n}import{useApp as Yx}from"ink";import{createContext as Jx,useCallback as ho,useContext as Xx,useEffect as nl,useRef as gs,useState as Xr}from"react";var Tt=[{id:"usage",label:"\u6570\u636E\u770B\u677F"},{id:"tokens",label:"\u4EE4\u724C\u7BA1\u7406"},{id:"logs",label:"\u4F7F\u7528\u65E5\u5FD7"},{id:"models",label:"\u6A21\u578B\u5E7F\u573A"},{id:"docs",label:"\u4F7F\u7528\u6587\u6863"},{id:"recharge",label:"\u8D26\u6237\u5145\u503C"},{id:"subscription",label:"\u8BA2\u9605\u5957\u9910"},{id:"ledger",label:"\u989D\u5EA6\u6D41\u6C34"},{id:"invoices",label:"\u53D1\u7968\u7BA1\u7406"},{id:"invite",label:"\u9080\u8BF7\u597D\u53CB"},{id:"tickets",label:"\u5DE5\u5355\u652F\u6301"},{id:"community",label:"\u793E\u533A\u8BBA\u575B"},{id:"inbox",label:"\u7AD9\u5185\u6D88\u606F"},{id:"announcements",label:"\u7CFB\u7EDF\u516C\u544A"},{id:"profile",label:"\u4E2A\u4EBA\u4E3B\u9875"}],cp="usage",Jr=e=>Tt.findIndex(t=>t.id===e),fs=e=>Jr(e)>=0;import{jsx as Zx}from"react/jsx-runtime";var Qx=5e3,mp=Jx(null),up=e=>({id:e,params:void 0}),lp=()=>Lt().session===null?[{id:"home",params:void 0}]:[up(cp)];function O(){let e=Xx(mp);if(!e)throw new Error("useNav \u5FC5\u987B\u5728 NavProvider \u5185\u4F7F\u7528");return e}function dp({ctx:e,children:t}){let n=Yx(),[o,r]=Xr(lp),[i,s]=Xr(0),[a,c]=Xr([]),l=gs({announcementsChecked:!1,announcementsShown:!1}).current,u=gs(new WeakMap).current,m=ho((R,...N)=>{r(E=>[...E,{id:R,params:N[0]}])},[]),p=ho(()=>{r(R=>R.length>1?R.slice(0,-1):R),s(R=>R+1)},[]),d=ho(R=>{r([up(R)]),s(N=>N+1)},[]),b=ho(()=>{r(lp()),s(R=>R+1)},[]),h=ho(()=>s(R=>R+1),[]),g=ho((R,N)=>{c(E=>[...E,{tone:R,message:N}])},[]),x=ho(()=>c(R=>R.slice(1)),[]),T=a[0]??null;nl(()=>{if(T===null)return;let R=setTimeout(x,Qx);return()=>clearTimeout(R)},[T,x]);let k=o[o.length-1];if(k===void 0)throw new Error("\u5BFC\u822A\u6808\u4E3A\u7A7A");let S=u.get(k);S===void 0&&(S=new Map,u.set(k,S));let y={ctx:e,current:k,depth:o.length,push:m,pop:p,select:d,home:b,reload:h,toast:g,message:T,dismissToast:x,exit:n.exit,revision:i,gate:l,retained:S};return Zx(mp.Provider,{value:y,children:t})}function Me(e,t){let{retained:n}=O(),[o,r]=Xr(()=>e!==void 0&&n.has(e)?n.get(e):t());return nl(()=>{e!==void 0&&n.set(e,o)},[n,e,o]),[o,r]}function Q(e,t){let[n,o]=Xr({phase:"loading"}),r=gs(t);r.current=t;let i=gs(0);return nl(()=>{let s=i.current+=1;o({phase:"loading"}),r.current().then(a=>{i.current===s&&o({phase:"ready",data:a})}).catch(a=>{i.current===s&&o({phase:"error",message:xe(a),hint:a instanceof U?a.hint:void 0})})},e),n}import{Box as Is,Text as xo,useInput as GT}from"ink";import{Box as ti,Text as nr}from"ink";import{Lexer as rT}from"marked";import Zo from"string-width";import Qr from"string-width";var f={background:"#0d0d0d",foreground:"#f3f3f3",mutedForeground:"#949494",faintForeground:"#696969",cursorBackground:"#c8c8c8",border:"#393939",accent:"#37be95",success:"#34d399",warning:"#fbbf24",danger:"#f87171"},hs=["#242424","#5a4233","#746533","#70924f","#37be95"],ys=["#37be95","#2d9273","#246e58","#1e5443","#193f33"],et={accent:f.accent,success:f.success,warning:f.warning,danger:f.danger},Qo=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],bs=80,ae={cursor:"\u276F",bullet:"\xB7",dot:"\u2219",crumb:"\u203A",ok:"\u2714",warn:"!",fail:"\u2718",ellipsis:"\u2026",barFilled:"\u2588",barEmpty:"\u2591",section:"\u258D",prev:"\u2039",next:"\u203A"};var eT=Qr(ae.ellipsis),tT=new Intl.Segmenter(void 0,{granularity:"grapheme"}),ol=e=>Array.from(tT.segment(e),t=>t.segment),nT=(e,t)=>e+" ".repeat(Math.max(0,t-Qr(e))),oT=(e,t)=>" ".repeat(Math.max(0,t-Qr(e)))+e;function He(e,t){if(t<=0)return"";if(Qr(e)<=t)return e;let n=t-eT,o="";for(let r of ol(e)){if(Qr(o+r)>n)break;o+=r}return o+ae.ellipsis}var Vn=e=>e.replaceAll(" "," "),Je=(e,t)=>nT(He(e,t),t),Kn=(e,t)=>oT(He(e,t),t),_e=e=>e.filter(t=>typeof t=="string"&&t!=="").join(` ${ae.bullet} `);var iT=e=>e.startsWith("#")||Ni(e)!==null,sT={spans:[]},Ss=e=>e===void 0||e.spans.every(t=>t.text.trim()==="");function pp(e){let t=[];for(let n of e){let o=t[t.length-1];o!==void 0&&o.color===n.color&&o.bold===n.bold?o.text+=n.ch:t.push({text:n.ch,color:n.color,bold:n.bold})}return{spans:t}}var aT=new Set([..."\uFF0C\u3002\u3001\uFF1B\uFF1A\uFF01\uFF1F\uFF09\u300D\u300F\u3011\u300B\u2026\u201D\u2019,.;:!?)]}"]),cT=new Set([..."\uFF08\u300C\u300E\u3010\u300A\u201C\u2018([{"]),lT=(e,t)=>(Zo(e)>1||Zo(t)>1)&&!cT.has(e)&&!aT.has(t);function mT(e,t,n){for(let o=e.length;o>n;o-=1){if(e[o]?.ch===" ")return{end:o,carry:o+1};let r=e[o-1]?.ch,i=o===e.length?t:e[o]?.ch;if(r!==void 0&&i!==void 0&&r!==" "&&lT(r,i))return{end:o,carry:o}}return null}function uT(e){let t=[],n=0,o=0,r=0;for(let i of ol(e.map(s=>s.text).join(""))){let s=e[n];for(;s!==void 0&&r>=o+s.text.length;)o+=s.text.length,n+=1,s=e[n];if(s===void 0)break;t.push({ch:i,color:s.color,bold:s.bold}),r+=i.length}return t}function Pt(e,t,n=0){let o=()=>Array.from({length:n},()=>({ch:" "})),r=[],i=[],s=0,a=()=>{r.push(pp(i)),i=o(),s=n};for(let c of uT(e)){let{ch:l}=c;if(l===`
2
+ import{once as XR}from"events";import{createInterface as QR}from"readline/promises";import{parseArgs as ZR}from"util";var Pm={name:"@codeflow-ai/cli",version:"1.30.2",type:"module",description:"CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF\uFF1A\u4E00\u952E\u914D\u7F6E AI \u5BA2\u6237\u7AEF",keywords:["codeflow","claude-code","codex","openclaw","hermes-agent","opencode","pi-coding-agent","cli"],license:"UNLICENSED",engines:{node:">=22"},bin:{codeflow:"dist/cli.js"},files:["dist"],publishConfig:{access:"public"},scripts:{dev:"tsx src/cli.ts",build:"tsup",typecheck:"tsc --noEmit"},dependencies:{"@decimalturn/toml-patch":"3.0.4",ink:"7.1.1",json5:"2.2.3","jsonc-parser":"3.3.1",marked:"18.0.9",qrcode:"1.5.4",react:"19.2.0","smol-toml":"1.9.0","string-width":"8.2.0",yaml:"2.9.1",zod:"4.4.3"},devDependencies:{"@codeflow/shared":"workspace:*","@types/node":"25.9.1","@types/qrcode":"1.5.6","@types/react":"19.2.2",tsup:"8.5.1",tsx:"4.22.3",typescript:"5.9.3"}};var Wt="codeflow",Vt=Pm.version,Pi="https://codeflow.sh",Fo="@codeflow-ai/cli",Rr=0,Uo=1,Ka=2,ro=3,Am=4;import{randomBytes as pS}from"crypto";import{mkdirSync as Nm,readFileSync as fS,rmSync as Lm,statSync as gS,writeFileSync as hS}from"fs";import{join as Om}from"path";import{setTimeout as yS}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??Uo,this.hint=n.hint}};function Se(e){return e instanceof Error?e.message:String(e)}import{chmodSync as sS,existsSync as aS,mkdirSync as cS,readFileSync as lS,writeFileSync as mS}from"fs";import{dirname as uS}from"path";function Lt(e){return aS(e)?lS(e,"utf8"):null}function kn(e,t,n){cS(uS(e),{recursive:!0,mode:448});try{mS(e,t,{mode:n}),sS(e,n)}catch(o){throw new F(`\u5199\u5165 ${e} \u5931\u8D25\uFF1A${Se(o)}`,{cause:o})}}function Em(e,t,n){kn(e,`${JSON.stringify(t,null,2)}
3
+ `,n)}function Ai(e,t,n,o,r){let i=null,s=()=>{if(i)return i;let a=n(),c=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),Em(n(),c,384),i=c,c}}}import{homedir as dS}from"os";import{join as jo}from"path";function vn(){let e=process.env.XDG_CONFIG_HOME;if(e)return jo(e,"codeflow");if(process.platform==="win32"){let t=process.env.APPDATA;if(t)return jo(t,"codeflow")}return jo(dS(),".config","codeflow")}var Mm=()=>jo(vn(),"config.json"),Ei=()=>jo(vn(),"credentials.json"),Im=()=>jo(vn(),"refresh.lock");var bS=rn.object({refreshCookie:rn.string(),accessToken:rn.string(),accessExpiresAt:rn.number(),username:rn.string(),email:rn.string(),site:rn.string()}),SS=rn.object({site:rn.string(),cookie:rn.string()}),xS=rn.object({session:bS.nullable(),device:SS.nullable()}),Ya=Ai(xS,{session:null,device:null},Ei,"\u672C\u5730\u51ED\u636E","\u91CD\u65B0\u767B\u5F55"),wt=Ya.load,Mi=Ya.reload,_r=Ya.update;function Dm(){let{session:e}=wt();if(!e)throw new F("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:ro});return e}var TS=6e4,wS=75e3,kS=120;function vS(e,t){try{Nm(e)}catch{try{Date.now()-gS(e).mtimeMs>TS&&Lm(e,{recursive:!0,force:!0})}catch{}return!1}return hS(Om(e,"owner"),t),!0}function CS(e,t){let n;try{n=fS(Om(e,"owner"),"utf8")}catch{return}n===t&&Lm(e,{recursive:!0,force:!0})}async function Ii(e){let t=Im(),n=pS(16).toString("hex");Nm(vn(),{recursive:!0,mode:448});let o=Date.now()+wS;for(;!vS(t,n);){if(Date.now()>o)throw new F(`\u7B49\u5F85\u5237\u65B0\u9501\u8D85\u65F6\uFF0C\u82E5\u786E\u8BA4\u6CA1\u6709\u5176\u4ED6 ${Wt} \u5728\u8FD0\u884C\uFF0C\u8BF7\u5220\u9664 ${t}`);await yS(kS)}try{return await e()}finally{CS(t,n)}}function RS(){let e=process.env.CODEFLOW_SITE;if(e)return e;let t=wt().session;return t?t.site:Pi}function $m(){return{site:RS()}}function io(e,t,n){if(!e.isTTY)return n;let o=Number.parseInt(t.slice(1),16);return`\x1B[38;2;${o>>16&255};${o>>8&255};${o&255}m${n}\x1B[39m`}import{z as ht}from"zod";import{release as Tx}from"os";import{z as He}from"zod";var _S=["active","disabled"],O_=He.enum(_S),Ja=["subscription_first","balance_first","subscription_only","balance_only"],Xa=He.enum(Ja),PS=["openai","anthropic"],Bm=He.enum(PS),AS=["openai-chat","openai-responses","anthropic-messages"],Fm=He.enum(AS);var Pr=["pending","paid","refund_requested","partially_refunded","refunded","failed","expired"],Um=He.enum(Pr),ES=["recharge","subscription"],Qa=He.enum(ES),MS=["requested","pending","succeeded","failed","rejected","canceled"],jm=He.enum(MS),Za=["pending","issued","rejected"],Hm=He.enum(Za),IS=["special","general"],ec=He.enum(IS),NS=["info","success","warning","error"],qm=He.enum(NS),LS=["terms","privacy"],D_=He.enum(LS),tc=["recharge","reserve","consume","reserve_refund","refund","refund_release","reward","admin_adjust"],Gm=He.enum(tc),OS=["usage_log","order","invitation","admin"],zm=He.enum(OS),nc=["first_inviter","first_invitee","subsequent_inviter"],Wm=He.enum(nc),oc=["success","error","canceled","anomaly"],Vm=He.enum(oc),rc=["open","replied","closed"],Km=He.enum(rc),ic=["billing","technical","account","other"],Ym=He.enum(ic),sc=["low","normal","high"],Jm=He.enum(sc),DS=["user","admin"],Xm=He.enum(DS),$S=["pending","published","rejected","removed"],Ar=He.enum($S),ac=["activity","published"],Qm=He.enum(ac),Ni=["spam","abuse","explicit","illegal","privacy","other"],Zm=He.enum(Ni),BS=["none","minor","major","critical"],eu=He.enum(BS);import{z as Ho}from"zod";var FS=["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"],US=Ho.enum(FS),tu=Ho.object({error:Ho.object({code:US,message:Ho.string(),details:Ho.unknown().optional(),requestId:Ho.string().optional()})});var nu={internal_error:"\u670D\u52A1\u6682\u65F6\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",validation_error:"\u63D0\u4EA4\u7684\u5185\u5BB9\u6709\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5",not_found:"\u8BBF\u95EE\u7684\u5185\u5BB9\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664",conflict:"\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u8BB0\u5F55\uFF0C\u8BF7\u52FF\u91CD\u590D\u63D0\u4EA4",rate_limited:"\u64CD\u4F5C\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",forbidden:"\u6CA1\u6709\u6743\u9650\u6267\u884C\u6B64\u64CD\u4F5C",unauthorized:"\u8BF7\u5148\u767B\u5F55",invalid_credentials:"\u8D26\u53F7\u6216\u5BC6\u7801\u4E0D\u6B63\u786E",password_incorrect:"\u5F53\u524D\u5BC6\u7801\u4E0D\u6B63\u786E",account_disabled:"\u8D26\u6237\u5DF2\u88AB\u7981\u7528\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",email_already_registered:"\u8BE5\u90AE\u7BB1\u5DF2\u88AB\u6CE8\u518C",username_taken:"\u8BE5\u7528\u6237\u540D\u5DF2\u88AB\u4F7F\u7528",verification_code_invalid:"\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E",verification_code_expired:"\u9A8C\u8BC1\u7801\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u83B7\u53D6",token_expired:"\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",token_reuse_detected:"\u767B\u5F55\u72B6\u6001\u5F02\u5E38\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",token_limit_exceeded:"\u4EE4\u724C\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u5220\u9664\u4E0D\u518D\u4F7F\u7528\u7684\u4EE4\u724C",totp_invalid:"\u52A8\u6001\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E\uFF0C\u8BF7\u91CD\u8BD5",totp_replayed:"\u8BE5\u9A8C\u8BC1\u7801\u521A\u521A\u5DF2\u88AB\u4F7F\u7528\uFF0C\u8BF7\u7B49\u5F85\u9A8C\u8BC1\u5668\u663E\u793A\u4E0B\u4E00\u4E2A\u9A8C\u8BC1\u7801\u540E\u518D\u8F93\u5165",totp_setup_expired:"\u7ED1\u5B9A\u4F1A\u8BDD\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5F00\u59CB\u7ED1\u5B9A",totp_not_enabled:"\u5C1A\u672A\u542F\u7528\u4E24\u6B65\u9A8C\u8BC1",login_ticket_invalid:"\u767B\u5F55\u9A8C\u8BC1\u5DF2\u8FC7\u671F\u6216\u5C1D\u8BD5\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",recovery_code_invalid:"\u6062\u590D\u7801\u4E0D\u6B63\u786E\u6216\u5DF2\u88AB\u4F7F\u7528",passkey_registration_failed:"Passkey \u6CE8\u518C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",passkey_verification_failed:"Passkey \u9A8C\u8BC1\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",passkey_not_found:"\u8BE5 Passkey \u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664",passkey_origin_not_allowed:"\u5F53\u524D\u8BBF\u95EE\u5730\u5740\u672A\u914D\u7F6E\u4E3A\u7AD9\u70B9\u5730\u5740\uFF0C\u65E0\u6CD5\u4F7F\u7528 Passkey",insufficient_quota:"\u989D\u5EA6\u4E0D\u8DB3\uFF0C\u8BF7\u5145\u503C\u540E\u518D\u8BD5",no_available_channel:"\u4E0A\u6E38\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",model_not_found:"\u8BE5\u6A21\u578B\u4E0D\u5B58\u5728",model_not_in_group:"\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u4E0D\u652F\u6301\u8BE5\u6A21\u578B\uFF0C\u8BF7\u66F4\u6362\u4EE4\u724C\u5206\u7EC4\u6216\u6539\u7528\u5206\u7EC4\u652F\u6301\u7684\u6A21\u578B",token_group_missing:"\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u5DF2\u88AB\u5220\u9664\uFF0C\u8BF7\u7F16\u8F91\u4EE4\u724C\u91CD\u65B0\u9009\u62E9\u5206\u7EC4",token_quota_exceeded:"\u8BE5\u4EE4\u724C\u7684\u6D88\u8D39\u5DF2\u8FBE\u8D39\u7528\u9650\u5236\uFF0C\u8BF7\u8C03\u9AD8\u6216\u6E05\u9664\u9650\u5236\u540E\u518D\u4F7F\u7528",upstream_error:"\u4E0A\u6E38\u670D\u52A1\u8FD4\u56DE\u9519\u8BEF\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",order_not_found:"\u8BA2\u5355\u4E0D\u5B58\u5728",order_not_payable:"\u8BA2\u5355\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u518D\u8BD5",payment_verify_failed:"\u652F\u4ED8\u7ED3\u679C\u786E\u8BA4\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",payment_precreate_failed:"\u53D1\u8D77\u652F\u4ED8\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",amount_mismatch:"\u652F\u4ED8\u91D1\u989D\u4E0E\u8BA2\u5355\u4E0D\u7B26\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",refund_not_allowed:"\u8BE5\u8BA2\u5355\u5F53\u524D\u4E0D\u53EF\u9000\u6B3E",refund_amount_invalid:"\u9000\u6B3E\u91D1\u989D\u4E0D\u6B63\u786E\u6216\u8D85\u8FC7\u53EF\u9000\u4F59\u989D",refund_insufficient_balance:"\u53EF\u7528\u989D\u5EA6\u4E0D\u8DB3\u4EE5\u6263\u56DE\u672C\u6B21\u9000\u6B3E\uFF08\u5DF2\u6D88\u8017\u90E8\u5206\u5BF9\u5E94\u7684\u73B0\u91D1\u4E0D\u53EF\u9000\uFF09",refund_failed:"\u652F\u4ED8\u5B9D\u9000\u6B3E\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u6216\u68C0\u67E5\u652F\u4ED8\u5B9D\u5546\u6237\u540E\u53F0",refund_pending:"\u9000\u6B3E\u7ED3\u679C\u5F85\u786E\u8BA4\uFF0C\u8BF7\u7A0D\u540E\u67E5\u770B\u9000\u6B3E\u8BB0\u5F55",refund_in_progress:"\u8BE5\u8BA2\u5355\u6216\u8BA2\u9605\u6709\u9000\u6B3E\u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u5F85\u5176\u5B8C\u6210\u540E\u518D\u64CD\u4F5C",refund_blocked_by_pending_order:"\u8BE5\u8BA2\u9605\u6709\u5F85\u652F\u4ED8\u7684\u7EED\u8D39\u8BA2\u5355\uFF0C\u8BF7\u5F85\u5176\u652F\u4ED8\u6216\u8D85\u65F6\u540E\u518D\u9000\u6B3E",refund_order_superseded:"\u5B58\u5728\u66F4\u665A\u5165\u8D26\u7684\u8BA2\u5355\uFF0C\u8BF7\u6309\u4ECE\u65B0\u5230\u65E7\u7684\u987A\u5E8F\u9000\u6B3E",refund_request_not_found:"\u9000\u6B3E\u7533\u8BF7\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5904\u7406\uFF0C\u8BF7\u5237\u65B0\u540E\u67E5\u770B",refund_nothing_refundable:"\u8BE5\u8BA2\u9605\u8BA2\u5355\u6309\u9650\u989D\u5468\u671F\u8BA1\u8D39\u540E\u5DF2\u65E0\u53EF\u9000\u91D1\u989D",subscription_limit_reached:"\u8BA2\u9605\u989D\u5EA6\u5DF2\u7528\u5C3D\uFF0C\u8BF7\u7B49\u5F85\u7A97\u53E3\u91CD\u7F6E",no_subscription_coverage:"\u5F53\u524D\u5206\u7EC4\u6CA1\u6709\u53EF\u7528\u7684\u8BA2\u9605\uFF0C\u8BF7\u8BA2\u9605\u5957\u9910\u6216\u8C03\u6574\u6263\u8D39\u65B9\u5F0F",subscription_revoked:"\u8BE5\u8BA2\u9605\u5DF2\u88AB\u4F5C\u5E9F",plan_disabled:"\u8BE5\u5957\u9910\u5DF2\u505C\u552E",order_already_invoiced:"\u8BE5\u8BA2\u5355\u5DF2\u7533\u8BF7\u8FC7\u53D1\u7968",order_not_eligible:"\u6240\u9009\u8BA2\u5355\u4E0D\u7B26\u5408\u5F00\u7968\u6761\u4EF6",order_invoiced:"\u8BE5\u8BA2\u5355\u5DF2\u5F00\u7968\u6216\u6709\u672A\u5904\u7406\u7684\u5F00\u7968\u7533\u8BF7\uFF0C\u65E0\u6CD5\u9000\u6B3E",invoice_profile_exists:"\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u5E38\u7528\u5F00\u7968\u4FE1\u606F",invite_code_invalid:"\u9080\u8BF7\u7801\u65E0\u6548",ticket_closed:"\u5DE5\u5355\u5DF2\u5173\u95ED\uFF0C\u8BF7\u5148\u91CD\u65B0\u6253\u5F00\u540E\u518D\u56DE\u590D",ticket_limit_exceeded:"\u672A\u5173\u95ED\u7684\u5DE5\u5355\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u5173\u95ED\u5DF2\u89E3\u51B3\u7684\u5DE5\u5355",attachment_storage_unconfigured:"\u5C1A\u672A\u914D\u7F6E\u9644\u4EF6\u5B58\u50A8",attachment_too_large:"\u9644\u4EF6\u5927\u5C0F\u8D85\u8FC7\u9650\u5236",attachment_image_too_large:"\u56FE\u7247\u5C3A\u5BF8\u6216\u5E27\u6570\u8D85\u8FC7\u9650\u5236",attachment_invalid:"\u9644\u4EF6\u65E0\u6548\u6216\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u4E0A\u4F20",attachment_staging_limit_exceeded:"\u5F85\u63D0\u4EA4\u7684\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u63D0\u4EA4\u73B0\u6709\u9644\u4EF6",docs_not_configured:"\u6587\u6863\u4E2D\u5FC3\u672A\u542F\u7528",docs_source_unavailable:"\u6587\u6863\u5185\u5BB9\u83B7\u53D6\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",docs_page_not_found:"\u8BE5\u6587\u6863\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",provider_status_unavailable:"\u5B98\u65B9\u670D\u52A1\u72B6\u6001\u6682\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",community_muted:"\u8D26\u53F7\u5904\u4E8E\u7981\u8A00\u671F\u95F4\uFF0C\u6682\u65F6\u65E0\u6CD5\u53D1\u5E16\u3001\u8BC4\u8BBA\u3001\u7F16\u8F91\u3001\u4E0A\u4F20\u6216\u66F4\u6362\u5934\u50CF\u4E0E\u7528\u6237\u540D",community_state_changed:"\u5185\u5BB9\u72B6\u6001\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5",community_category_missing:"\u6240\u9009\u677F\u5757\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9"};import{z as qo}from"zod";var jS=qo.string().trim().min(1),cc=jS.pipe(qo.url()),HS=qo.object({name:qo.string().trim().min(1),description:qo.string().trim().min(1),url:cc}),H_=qo.array(HS);function ou(e){return`codeflow-cli/${e.cliVersion} (${e.platform} ${e.release}; ${e.arch}) node/${e.nodeVersion}`}function Go(e){if(!e)return"\u672A\u77E5\u8BBE\u5907";let t=e.type==="cli"?e.clientVersion:e.clientVersion?.split(".")[0],o=[e.client?t?`${e.client} ${t}`:e.client:null,e.os].filter(r=>r!==null);return o.length>0?o.join(" \xB7 "):"\u672A\u77E5\u8BBE\u5907"}import{z as dn}from"zod";var lc=1e8;var W_=dn.object({id:dn.coerce.number().int().positive()}),ru=100,iu=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)}),su=(e=dn.string().trim())=>e.nullable().optional().transform(t=>t==null||t.length===0?null:t);import{z as ce}from"zod";var so=ce.email().max(254).toLowerCase(),Ot=8,Er=ce.string().min(Ot).max(128),Mr=ce.string().min(1).max(128),Kt=32,mc=ce.string().trim().min(1).max(Kt),uc=ce.string().trim().min(1).max(254),Y_=ce.object({email:so}),J_=ce.object({username:mc,email:so,password:Er,code:ce.string().min(4).max(8),inviteCode:ce.string().trim().min(1).max(32).optional()}),X_=ce.object({account:uc,password:Mr}),Q_=ce.object({email:so,code:ce.string().min(4).max(8),password:Er}),Z_=ce.object({oldPassword:Mr,newPassword:Er}),e0=ce.object({email:so}),t0=ce.object({email:so,code:ce.string().min(4).max(8),password:Mr}),au=ce.object({username:ce.string(),email:ce.string(),avatarUrl:ce.string().nullable()}),zo=ce.object({accessToken:ce.string(),user:au}),cu=ce.discriminatedUnion("status",[zo.extend({status:ce.literal("ok")}),ce.object({status:ce.literal("totp_required"),ticket:ce.string()})]),lu=ce.object({user:au}),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()}),qS=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()}),mu=ce.object({sessions:ce.array(qS)});import{z as ke}from"zod";var Wo=ke.string().trim().length(6),GS=ke.string().trim().min(10).max(20),Li=ke.string().trim().min(1).max(64),Oi=ke.record(ke.string(),ke.unknown()),r0=ke.object({ticket:ke.string().min(1),code:Wo}),i0=ke.object({ticket:ke.string().min(1),code:GS}),s0=ke.object({code:Wo.optional()}),a0=ke.object({code:Wo}),uu=ke.object({secret:ke.string(),otpauthUri:ke.string()}),pc=ke.object({recoveryCodes:ke.array(ke.string())}),zS=ke.object({id:ke.number().int(),name:ke.string(),createdAt:ke.string(),lastUsedAt:ke.string().nullable()}),du=ke.object({totp:ke.object({enabled:ke.boolean(),enabledAt:ke.string().nullable(),recoveryCodesRemaining:ke.number().int()}),passkeys:ke.array(zS)}),c0=ke.object({name:Li,response:Oi}),l0=ke.object({name:Li}),m0=ke.object({response:Oi});import{z as Ne}from"zod";var g0=Ne.object({account:uc,password:Mr}),WS=Ne.object({totp:Ne.boolean(),passkeys:Ne.boolean()}),h0=Ne.discriminatedUnion("status",[Ne.object({status:Ne.literal("totp_required"),ticket:Ne.string()}),Ne.object({status:Ne.literal("setup_required"),ticket:Ne.string(),missing:WS})]),y0=Ne.object({ticket:Ne.string().min(1)}),b0=Ne.object({ticket:Ne.string().min(1),code:Wo}),S0=Ne.object({ticket:Ne.string().min(1),name:Li,response:Oi}),x0=Ne.object({ticket:Ne.string().min(1),code:Wo.optional()}),pu=Ne.object({username:Ne.string(),email:Ne.string(),avatarUrl:Ne.string().nullable()}),T0=Ne.object({accessToken:Ne.string(),admin:pu}),w0=Ne.object({admin:pu});import{z as fc}from"zod";var _0=fc.object({siteName:fc.string().trim().min(1).max(64),siteDescription:fc.string().trim().max(200).optional(),siteOrigin:cc,username:mc,email:so,password:Er});import{z as $e}from"zod";var fu={orderNo:$e.string(),amountCny:$e.number().int(),status:Um,credited:$e.boolean(),refundedAmountCny:$e.number().int(),succeededRefundCny:$e.number().int(),pendingRefundCny:$e.number().int(),createdAt:$e.string()},Ir=$e.object({...fu,quota:$e.number(),refundedQuota:$e.number()}),Nr=$e.object({...fu,planName:$e.string(),renewal:$e.boolean(),grantedDurationDays:$e.number().int()}),Di=$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()}),gu=$e.object({id:$e.number().int(),amountCny:$e.number().int(),status:jm,refundTradeNo:$e.string().nullable(),reason:$e.string().nullable(),rejectReason:$e.string().nullable(),createdAt:$e.string()});function hu(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()}),Vo=Yt.discriminatedUnion("kind",[gc,hc]),yu=Yt.object({kind:Xm,username:Yt.string()});var $i=ut.object({id:ut.number().int(),title:ut.string(),category:Ym,priority:Jm,status:Km,createdAt:ut.string(),updatedAt:ut.string()}),bu=$i.pick({id:!0}),Su=25*1024*1024,xu=5,Tu=ut.object({id:ut.number().int(),fileName:ut.string(),fileSize:ut.number().int(),contentType:ut.string()}),wu=Tu.pick({id:!0,fileSize:!0}),VS=ut.object({id:ut.number().int(),author:Vo,content:ut.string(),attachments:ut.array(Tu),createdAt:ut.string()}),ku=ut.object({ticket:$i,messages:ut.array(VS)});import{z as Or}from"zod";var yc=Or.object({id:Or.number().int(),title:Or.string(),content:Or.string(),level:qm,publishedAt:Or.string()});import{z as Ye}from"zod";var bc=100,vu=Ye.object({groups:Ye.array(Ye.object({title:Ye.string(),items:Ye.array(Ye.object({slug:Ye.string(),title:Ye.string()}))}))}),Cu=Ye.object({title:Ye.string(),markdown:Ye.string(),images:Ye.record(Ye.string(),Ye.object({width:Ye.number().int(),height:Ye.number().int()}))}),Ru=Ye.object({slug:Ye.string(),title:Ye.string(),anchor:Ye.string().nullable(),snippet:Ye.string()});function _u(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 qn(e){let t=Math.abs(e);return t>=1e9?`${(e/1e9).toFixed(1)}B`:t>=1e6?`${(e/1e6).toFixed(1)}M`:t>=1e3?`${(e/1e3).toFixed(1)}k`:Le(e)}function pn(e,t){return e===0&&t!==void 0?t:e.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:6})}function ao(e){return(e/1e3).toFixed(2)}function Ko(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${(e/1024**2).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function Fi(e,t){return`${e}******${t}`}var xc=ot.object({inputPricePerMillionTokens:ot.number(),outputPricePerMillionTokens:ot.number(),cachedInputPricePerMillionTokens:ot.number(),cacheWritePricePerMillionTokens:ot.number()});var KS=ot.number().int().nonnegative(),YS=ot.discriminatedUnion("kind",[xc.extend({kind:ot.literal("price"),inputTokensOver:KS}),ot.object({kind:ot.literal("multiplier"),param:ot.string(),value:ot.string(),multiplier:ot.number()})]),Pu=ot.array(YS);function JS(e){return e.kind==="price"}function Au(e){return e.kind==="multiplier"}function Eu(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 Tc(e){return`> ${Eu(e)}`}function Mu(e,t){let n=t.filter(JS).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 ${Eu(o.inputTokensOver)}`,price:e},...n.map(r=>({name:Dr(r.inputTokensOver),range:Tc(r.inputTokensOver),price:r}))]}var XS=ot.object({value:ot.string(),multiplier:ot.number()}),Iu=ot.array(XS);function Nu(e){return Ou(e.map(t=>t.multiplier))}function Lu(e,t){return Ou([e,...t.map(n=>n.multiplier)])}function Ou(e){return Number(e.reduce((t,n)=>t*n,1).toFixed(4))}import{z as co}from"zod";var QS=co.object({provider:Bm,pageUrl:co.string(),indicator:eu,incidents:co.array(co.object({title:co.string()}))}),Du=co.object({providers:co.array(QS)}),ZS={minor:{label:"\u90E8\u5206\u964D\u7EA7",tone:"warning"},major:{label:"\u90E8\u5206\u4E2D\u65AD",tone:"danger"},critical:{label:"\u4E25\u91CD\u4E2D\u65AD",tone:"danger"}};function $u(e){return e.filter(t=>t.indicator!=="none"||t.incidents.length>0)}function Bu(e){return e.indicator==="none"?{label:"\u4E8B\u4EF6\u5904\u7406\u4E2D",tone:"warning"}:ZS[e.indicator]}import{z as lo}from"zod";var $r=25*1024*1024,Fu=20,Uu=5;var wc="/api/media/";function ju(e){return`${wc}${e}`}var Hu=lo.object({width:lo.number().int(),height:lo.number().int()}),Ui=lo.record(lo.string(),Hu),qu=lo.object({id:lo.number().int(),image:Hu.nullable()}),Gu=String.raw`([1-9]\d{0,14})`,Q0=new RegExp(String.raw`^${wc}${Gu}$`),zu=new RegExp(String.raw`(!?)\[((?:\\.|[^\\\]\n])*)\]\(${wc}${Gu}(?:\s+"[^"\n]*")?\)`,"g");function Wu(e,t,n){return{id:Number(n),image:e==="!",name:t.replace(/\\(.)/g,"$1")}}function Vu(e){return[...e.matchAll(zu)].map(([,t="",n="",o=""])=>Wu(t,n,o))}function kc(e,t){return e.replace(zu,(n,o,r,i)=>t(Wu(o,r,i)))}import{z as dt}from"zod";import{z as I}from"zod";var mo=100,ji=2e4,vc=5e3,Hi=500,qi=64,ex=new RegExp("\\p{Cc}","u"),tx=new RegExp("(?![\\n\\t])\\p{Cc}","u");function Cc(e){return I.string().trim().max(e).refine(t=>!ex.test(t))}function Rc(e){return I.string().trim().max(e).refine(t=>!tx.test(t))}var sP=I.object({categoryId:I.number().int().positive(),title:Cc(mo).min(1),content:Rc(ji).min(1)}),aP=I.object({categoryId:I.number().int().positive().nullable(),title:Cc(mo),content:Rc(ji)}),cP=I.object({content:Rc(vc).min(1),replyToId:I.number().int().positive().optional()}),lP=I.object({reason:Zm,detail:su(Cc(Hi))}),mP=iu.extend({sort:Qm,categoryId:I.coerce.number().int().positive().optional(),q:I.string().trim().min(1).max(qi).optional(),author:I.string().trim().min(1).max(Kt).optional()}),_c=I.object({id:I.number().int(),name:I.string(),description:I.string()}),Gi=_c.pick({id:!0,name:!0}),Br=I.object({id:I.number().int(),title:I.string()}),Yo=I.object({id:I.number().int(),title:I.string().nullable()}),uP=I.object({posts:I.array(I.object({id:I.number().int(),lastModified:I.string()})),users:I.array(I.string()),staff:I.array(I.string())}),Pc=I.object({id:I.number().int(),title:I.string(),category:Gi,author:Vo,commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),lastActivityAt:I.string()}),Ac=I.object({id:I.number().int(),title:I.string(),content:I.string(),images:Ui,category:Gi,author:Vo,status:Ar,reviewReason:I.string().nullable(),commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),coverUrl:I.string().nullable(),createdAt:I.string(),publishedAt:I.string().nullable(),editedAt:I.string().nullable(),liked:I.boolean(),bookmarked:I.boolean()}),Ku={id:I.number().int(),author:Vo,content:I.string(),images:Ui,status:Ar,reviewReason:I.string().nullable(),likeCount:I.number().int(),liked:I.boolean(),createdAt:I.string()},Ec=I.object({...Ku,replyTo:I.object({id:I.number().int(),author:yu}).nullable()}),zi=I.object({...Ku,floor:I.number().int().nullable(),replyCount:I.number().int(),replies:I.array(Ec)}),Mc=I.object({likeCount:I.number().int()}),Yu=Ac.pick({id:!0}),Ju=zi.pick({id:!0}),nx=I.object({status:I.enum(["pending","rejected","removed"]),reviewReason:I.string().nullable()}),Ic=I.object({review:nx.nullable()}),Fr=I.object({id:I.number().int(),title:I.string(),category:Gi,status:Ar,reviewReason:I.string().nullable(),commentCount:I.number().int(),viewCount:I.number().int(),likeCount:I.number().int(),createdAt:I.string(),publishedAt:I.string().nullable()}),Wi=I.object({id:I.number().int(),content:I.string(),post:Yo,floorId:I.number().int(),status:Ar,reviewReason:I.string().nullable(),likeCount:I.number().int(),createdAt:I.string()}),Nc=I.object({id:I.number().int(),category:Gi.nullable(),title:I.string(),content:I.string(),images:Ui,createdAt:I.string()}),Xu=I.object({posts:I.array(Fr),drafts:I.number().int()}),Qu=Nc.pick({id:!0}),Zu=I.object({muted:I.object({reason:I.string(),until:I.string().nullable()}).nullable()});var ox=dt.object({posts:dt.number().int(),comments:dt.number().int(),likesReceived:dt.number().int()}),rx=dt.object({start:dt.string(),end:dt.string(),days:dt.array(dt.object({day:dt.string(),count:dt.number().int()}))}),ix=dt.object({posts:dt.array(Fr),comments:dt.array(Wi)}),ed={joinedAt:dt.string(),stats:ox,activity:rx,overview:ix},td=dt.object({identity:gc,...ed}),nd=dt.object({identity:hc,...ed});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()}),od=q.object({username:q.string()}),rd=q.discriminatedUnion("kind",[q.object({...tt,kind:q.literal("post_commented"),post:Br,comment:Ur,actor:od}),q.object({...tt,kind:q.literal("comment_replied"),post:Yo,comment:Ur,actor:od}),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:Yo,comment:Ur}),q.object({...tt,kind:q.literal("comment_rejected"),post:Yo,comment:Ur,reason:q.string()}),q.object({...tt,kind:q.literal("comment_removed"),post:Yo,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: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()})]),id=q.object({unread:q.boolean()});var sd="Asia/Shanghai",sx="+08:00";function ax(e){return new Date(new Date(e).getTime()+288e5)}function cx(e=Date.now()){let t=ax(e);return{day:t.toISOString().slice(0,10),hour:t.getUTCHours()}}function Lc(e=Date.now()){return cx(e).day}function Oc(e=Lc()){return new Date(`${e}T00:00:00${sx}`)}function Gn(e,t){let n=new Date(`${e}T00:00:00Z`);return new Date(n.getTime()+t*864e5).toISOString().slice(0,10)}var lx=new Intl.DateTimeFormat("zh-CN",{dateStyle:"short",timeStyle:"medium",timeZone:sd}),mx=new Intl.DateTimeFormat("zh-CN",{dateStyle:"long",timeZone:sd});function K(e){return lx.format(new Date(e))}function jr(e){return mx.format(new Date(e))}var[ux,...dx]=[{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=ux;for(let o of dx){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",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"},Jo={pending:"\u6B63\u5728\u5BA1\u6838\uFF0C\u901A\u8FC7\u540E\u516C\u5F00\u663E\u793A",rejected:"\u672A\u901A\u8FC7\u5BA1\u6838\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1",removed:"\u5DF2\u88AB\u5C4F\u853D\uFF0C\u4EC5\u81EA\u5DF1\u53EF\u89C1"},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 ad(e,t){return t===null?e:`${e}\uFF0C\u539F\u56E0\uFF1A${t}`}function $c(e,t){return t.status==="published"?null:ad(e[t.status],t.reviewReason)}function cd(e){return ad(Dc[e.status],e.reviewReason)}var Xi="\u8BE5\u5E16\u5B50\u6682\u4E0D\u53EF\u89C1",px=4;function ld(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 md(t,1)}function md(e,t){return t<px?e.map(n=>({...n,children:md(n.children,t+1)})):e.flatMap(n=>[{...n,children:[]},...ud(n)])}function ud(e){return e.children.flatMap(t=>[{reply:t.reply,mention:e.reply.author,children:[]},...ud(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 dd(e){return e/100}function pd(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 pd(e,t,2)}function Xo(e,t){return pd(e,t,6)}var gd={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 fd(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:fd(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:fd(e.refund.orderType)};case"subscription_expiring":return{title:"\u8BA2\u9605\u5373\u5C06\u5230\u671F",body:`\u5957\u9910\u300C${e.subscription.planName}\u300D\u5C06\u4E8E ${K(e.subscription.expiresAt)} \u5230\u671F\uFF0C\u5230\u671F\u540E\u5C06\u65E0\u6CD5\u7EE7\u7EED\u4F7F\u7528\u5957\u9910\u5185\u989D\u5EA6`,target:{kind:"subscription"}};case"email_changed":return{title:"\u90AE\u7BB1\u5DF2\u53D8\u66F4",body:`\u8D26\u53F7\u90AE\u7BB1\u5DF2\u53D8\u66F4\u4E3A ${e.newEmail}\uFF0C\u5982\u679C\u4E0D\u662F\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u7ACB\u5373\u8054\u7CFB\u7BA1\u7406\u5458`,target:{kind:"security"}};case"new_device_login":return{title:"\u65B0\u8BBE\u5907\u767B\u5F55\u63D0\u9192",body:`\u8D26\u53F7\u5728\u65B0\u8BBE\u5907\u4E0A\u767B\u5F55\uFF1A${Go(e.device)}\uFF0CIP \u5730\u5740 ${e.ip}\uFF1B\u5982\u679C\u4E0D\u662F\u672C\u4EBA\u64CD\u4F5C\uFF0C\u8BF7\u7ACB\u5373\u4FEE\u6539\u5BC6\u7801`,target:{kind:"security"}}}}function 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 Hc(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(...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(qr(o.tokens)));break}return t}function hd(e){return Hc(e).join(" ").replace(/\s+/g," ").trim()}var fx=[{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 gx(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 yd(e){return e<365?`${Dt(e)} \u5929`:`${Dt(e/365)} \u5E74`}function hx(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 yx(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 bx(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 Sx=[...fx.map(e=>({min:e.tokens/10,max:e.tokens*1e4,suffix:t=>`\u7EA6\u4E3A${e.name}\u7684 ${gx(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 ${hx(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 ${yd(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 ${yx(e)}`},{min:4500,max:1/0,suffix:e=>`\u82E5\u523B\u6210\u6BCF\u679A 30 \u5B57\u7684\u79E6\u6C49\u7AF9\u7B80\uFF0C\u603B\u91CD\u7EA6 ${bx(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 ${yd(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 bd(e){let{tokens:t,scope:n,range:o}=e;if(t<=0)return null;let r=Sx.filter(c=>t>=c.min&&t<=c.max),i=r[Math.floor(Math.random()*r.length)];return i?`${n==="user"?"\u4F60":"\u5168\u7AD9"}${o==="all"?"\u7D2F\u8BA1":o==="30d"?"\u8FD1 30 \u5929":"\u8FD1 7 \u5929"}\u4F7F\u7528\u7684 Token \u91CF${i.suffix(t)}`:null}function Cn(e){return t=>{let n=e[t];if(!n)throw new Error(`unknown status value: ${t}`);return n}}function $t(e){return t=>{let n=e[t];if(!n)throw new Error(`unknown label value: ${t}`);return n}}var zn=Cn({pending:{label:"\u5F85\u652F\u4ED8",tone:"warning"},paid:{label:"\u5DF2\u652F\u4ED8",tone:"success"},refund_requested:{label:"\u9000\u6B3E\u5BA1\u6838\u4E2D",tone:"warning"},partially_refunded:{label:"\u90E8\u5206\u9000\u6B3E",tone:"warning"},refunded:{label:"\u5DF2\u9000\u6B3E",tone:"danger"},failed:{label:"\u5931\u8D25",tone:"danger"},expired:{label:"\u5DF2\u8FC7\u671F",tone:"neutral"}}),LP=$t({recharge:"\u5145\u503C",subscription:"\u8BA2\u9605"}),Qi=Cn({pending:{label:"\u5F85\u5904\u7406",tone:"warning"},issued:{label:"\u5DF2\u5F00\u5177",tone:"success"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"}}),OP=Cn({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"}),Sd=Ja.map(e=>({value:e,label:qc(e)})),zc=$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"}),xd=$t({usage_log:"\u7528\u91CF",order:"\u8BA2\u5355",invitation:"\u9080\u8BF7",admin:"\u7BA1\u7406\u5458"}),Td=Cn({requested:{label:"\u5F85\u5BA1\u6838",tone:"warning"},pending:{label:"\u5F85\u786E\u8BA4",tone:"warning"},succeeded:{label:"\u5DF2\u9000\u6B3E",tone:"success"},failed:{label:"\u5931\u8D25",tone:"danger"},rejected:{label:"\u5DF2\u9A73\u56DE",tone:"danger"},canceled:{label:"\u5DF2\u64A4\u9500",tone:"neutral"}}),Zi=Cn({success:{label:"\u6210\u529F",tone:"success"},error:{label:"\u5931\u8D25",tone:"danger"},canceled:{label:"\u53D6\u6D88",tone:"neutral"},anomaly:{label:"\u5F02\u5E38",tone:"warning"}}),wd=$t({"openai-chat":"OpenAI Chat","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"}),Gr=$t({special:"\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968",general:"\u589E\u503C\u7A0E\u666E\u901A\u53D1\u7968"}),uo=$t({special:"\u4E13\u7968",general:"\u666E\u7968"}),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"}),zr=Cn({info:{label:"\u4FE1\u606F",tone:"neutral"},success:{label:"\u6210\u529F",tone:"success"},warning:{label:"\u8B66\u544A",tone:"warning"},error:{label:"\u91CD\u8981",tone:"danger"}}),Wc=Cn({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=Cn({low:{label:"\u8F83\u4F4E",tone:"neutral"},normal:{label:"\u666E\u901A",tone:"neutral"},high:{label:"\u7D27\u6025",tone:"danger"}}),kd=$t({openai:"OpenAI",anthropic:"Anthropic"}),po=Cn({pending:{label:"\u5BA1\u6838\u4E2D",tone:"warning"},published:{label:"\u5DF2\u53D1\u5E03",tone:"success"},rejected:{label:"\u672A\u901A\u8FC7",tone:"danger"},removed:{label:"\u5DF2\u5C4F\u853D",tone:"danger"}}),vd=$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"}),Cd=$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 Rd(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 xx(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 _d(e,t){return e.windows.map(n=>`${xx(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"]},Pd={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 wx=3e4,kx=ou({cliVersion:Vt,platform:process.platform,release:Tx(),arch:process.arch,nodeVersion:process.versions.node});async function Ad(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",kx);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??wx),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:Am,cause:r})}}async function Ed(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 Ad(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Ed(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 Md(e,t={}){let n=await Ad(e,t);if(!n.ok)return{status:n.status,ok:!1,headers:n.headers,data:await Ed(n),bytes:null};let o=new Uint8Array(await n.arrayBuffer());return{status:n.status,ok:!0,headers:n.headers,data:null,bytes:o}}function vx(e,t){let n=tu.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"?ro:void 0;return new F(nu[o]??r,i?{exitCode:i}:{})}function sn(e){if(!e.ok)throw vx(e.status,e.data)}var Ld="cf_refresh",Od="cf_device",Id=6e4;function Nd(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:Nd(t,Ld)??e.refresh,device:Nd(t,Od)??e.device}}function is(e){let t=[];return e.refresh&&t.push(`${Ld}=${e.refresh}`),e.device&&t.push(`${Od}=${e.device}`),t.length>0?{cookie:t.join("; ")}:{}}function Cx(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:Cx(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 Xc(e){let{device:t}=wt();return t!==null&&t.site===e?t.cookie:null}async function Dd(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=cu.parse(r.data),s=Wr(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 $d(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=zo.parse(s.data);return Vr(e,Wr(t,s.headers),a)}function ss(){_r(e=>{e.session=null})}async function Rx(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:ro});sn(n);let o=zo.parse(n.data);return Vr(e.site,Wr(t,n.headers),o)}async function Kr(e=!1){let t=Dm();return!e&&Date.now()<t.accessExpiresAt-Id?t:Ii(async()=>{let n=Mi().session;if(!n)throw new F("\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u767B\u5F55\u8D26\u53F7",{exitCode:ro});return(n.refreshCookie!==t.refreshCookie||n.accessToken!==t.accessToken)&&Date.now()<n.accessExpiresAt-Id?n:Rx(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=>Md(`${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 _x=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(_x,`${e}/api/site-config`,{...t===void 0?{}:{timeoutMs:t}})}var Px=ht.object({content:ht.string(),configured:ht.boolean()});function Bd(e,t){return fn(Px,`${e}/api/agreements/${t}`)}var Ax=1e4;function Fd(){if(process.env.CODEFLOW_SITE)return null;let{session:e}=wt();return e!==null&&e.site!==Pi?e.site:null}async function Ud(e){let t;try{({siteOrigin:t}=await Be(e,Ax))}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(),_r(o=>{o.session?.site===e&&(o.session.site=n),o.device?.site===e&&(o.device.site=n)})})}import{existsSync as Mx,rmSync as Ix}from"fs";import{spawn as Ex}from"child_process";function Yr(e,t={}){return new Promise((n,o)=>{let r=Ex("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 jd(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=vn();Mx(o)&&Ix(o,{recursive:!0,force:!0})}),await n("\u5378\u8F7D\u672C\u7A0B\u5E8F",async()=>{await Yr(["uninstall","-g",Fo])}),t}import{z as Jr}from"zod";var Nx=Jr.object({line:Jr.object({name:Jr.string(),url:Jr.string()}).nullable(),lastUpdateCheckAt:Jr.number().nullable()}),Hd=Ai(Nx,{line:null,lastUpdateCheckAt:null},Mm,"\u672C\u5730\u914D\u7F6E","\u91CD\u65B0\u8FD0\u884C"),fo=Hd.load,ls=Hd.update;var Lx=1440*60*1e3;async function qd(){let e=(await Yr(["view",Fo,"version"])).trim();if(e==="")throw new F(`npm \u6CA1\u6709\u62A5\u51FA ${Fo} \u7684\u7248\u672C`);return e}async function Gd(e,t){return await Yr(["install","-g",`${Fo}@${e}`],{background:t}),e}async function zd(){let e=await qd();return e===Vt?null:await Gd(e,!1)}function Ox(){let e=Date.now(),t=fo().lastUpdateCheckAt;return t!==null&&e-t<Lx?!1:(ls(n=>{n.lastUpdateCheckAt=e}),!0)}async function Wd(){if(!Ox())return null;let e;try{e=await qd()}catch{return null}return e===Vt?null:await Gd(e,!0)}import{Box as BR,render as FR,useInput as UR}from"ink";import{useEffect as _m,useRef as jR}from"react";var Vd=e=>A(mt(yc),Ue("/announcements",{...e})),Kd=()=>A(yc.nullable(),"/announcements/unread"),ms=e=>A(se,`/announcements/${e}/read`,{method:"POST"});import{Box as Yd,useWindowSize as Dx}from"ink";import{Children as $x}from"react";import{jsx as Jd}from"react/jsx-runtime";var Bx=1,Zc=1,X=1;function j(){let{columns:e,rows:t}=Dx();return{width:Math.max(1,e-Bx*2),columns:e,rows:t}}function Xd({height:e,children:t}){return Jd(Yd,{flexDirection:"column",height:e,justifyContent:"space-between",children:$x.toArray(t).map((n,o)=>Jd(Yd,{flexDirection:"column",flexShrink:0,children:n},o))})}import{useInput as Qd}from"ink";import{createContext as ps,useCallback as tl,useContext as Fx,useEffect as Zd,useMemo as ep,useRef as ds,useState as Ux}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]=Ux(!1),n=ds(0),o=tl(()=>(n.current+=1,t(!0),()=>{n.current-=1,n.current===0&&t(!1)}),[]);return ep(()=>({held:e,acquire:o}),[e,o])}var Wn={screen:0,panel:10,input:20},rl=ps(null);function tp({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()},[]);Qd((l,u)=>{u.escape&&a()});let c=ep(()=>({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 go(e){let t=Fx(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}=go(e);Zd(()=>{if(t)return n()},[t,n])}function gs(e){il(fs,e)}function Re(e){il(nl,e)}function np(e){il(ol,e)}function hs(){return go(nl).held}function ys(){return go(fs).held}function op(){return go(ol).held}function G(e,t=!0){let n=go(fs).held;Qd(e,{isActive:t&&!n})}function rp(){return go(rl).fire}function gn(e,{isActive:t=!0,layer:n=Wn.screen}={}){let{push:o}=go(rl),r=ds(e);r.current=e,Zd(()=>{if(t)return o({handler:()=>r.current(),layer:n})},[t,n,o])}import{measureElement as jx}from"ink";import{PassThrough as Hx}from"stream";import{createContext as qx,useCallback as Gx,useContext as zx,useEffect as cp,useRef as bs}from"react";import{jsx as tT}from"react/jsx-runtime";var Wx="\x1B[?1000h\x1B[?1003h\x1B[?1006h",Vx="\x1B[?1006l\x1B[?1003l\x1B[?1000l",Kx=27,Yx=91,Jx=60,ip=77,sp=109,ap=20,Xx=64,Qx=32,Zx=20;function eT(e){let t=[],n=[],o=0;for(;o<e.length;){let r=e[o];if(r===void 0)break;if(r!==Kx){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!==Yx){n.push(r),o+=1;continue}if(s===ip){if(o+6>e.length)break;o+=6;continue}if(s!==Jx){n.push(r),o+=1;continue}let a=o+3,c;for(;a<e.length&&a-o<ap;){let d=e[a];if(d===ip||d===sp){c=d;break}a+=1}if(c===void 0){if(a-o<ap)break;n.push(r),o+=1;continue}let l=e.subarray(o+3,a).toString("latin1").split(";");if(o=a+1,c===sp||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&Xx)!==0?{row:p,column:m,kind:"wheel",delta:(u&1)===0?-1:1}:{row:p,column:m,kind:(u&Qx)!==0?"move":"press"})}return{events:t,clean:Buffer.from(n),pending:e.subarray(o)}}function lp(e,t){let n=new Set,o=new Hx,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=eT(Buffer.concat([r,p]));r=d.pending,d.clean.length>0&&o.write(d.clean);for(let b of d.events)for(let h of n)h(b);r.length>0&&(i=setTimeout(s,Zx))},c=()=>{t.write(Vx)},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(Wx);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 mp=qx(null);function up({subscribe:e,children:t}){let n=bs(new Set).current,o=bs(null),r=Gx(i=>(n.add(i),()=>{n.delete(i)}),[n]);return cp(()=>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=jx(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]),tT(mp.Provider,{value:r,children:t})}function rt(e){let t=zx(mp);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,cp(()=>t({node:n,handlers:o}),[t]),n}import{useApp as nT}from"ink";import{createContext as oT,useCallback as ho,useContext as rT,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"}],dp="usage",Xr=e=>kt.findIndex(t=>t.id===e),Ss=e=>Xr(e)>=0;import{jsx as sT}from"react/jsx-runtime";var iT=5e3,fp=oT(null),gp=e=>({id:e,params:void 0}),pp=()=>wt().session===null?[{id:"home",params:void 0}]:[gp(dp)];function O(){let e=rT(fp);if(!e)throw new Error("useNav \u5FC5\u987B\u5728 NavProvider \u5185\u4F7F\u7528");return e}function hp({ctx:e,children:t}){let n=nT(),[o,r]=Qr(pp),[i,s]=Qr(0),[a,c]=Qr([]),l=xs({announcementsChecked:!1,announcementsShown:!1}).current,u=xs(new WeakMap).current,m=ho((R,...N)=>{r(E=>[...E,{id:R,params:N[0]}])},[]),p=ho(()=>{r(R=>R.length>1?R.slice(0,-1):R),s(R=>R+1)},[]),d=ho(R=>{r([gp(R)]),s(N=>N+1)},[]),b=ho(()=>{r(pp()),s(R=>R+1)},[]),h=ho(()=>s(R=>R+1),[]),g=ho((R,N)=>{c(E=>[...E,{tone:R,message:N}])},[]),x=ho(()=>c(R=>R.slice(1)),[]),T=a[0]??null;sl(()=>{if(T===null)return;let R=setTimeout(x,iT);return()=>clearTimeout(R)},[T,x]);let k=o[o.length-1];if(k===void 0)throw new Error("\u5BFC\u822A\u6808\u4E3A\u7A7A");let S=u.get(k);S===void 0&&(S=new Map,u.set(k,S));let y={ctx:e,current:k,depth:o.length,push:m,pop:p,select:d,home:b,reload:h,toast:g,message:T,dismissToast:x,exit:n.exit,revision:i,gate:l,retained:S};return sT(fp.Provider,{value:y,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 xo,useInput as XT}from"ink";import{Box as ni,Text as nr}from"ink";import{Lexer as uT}from"marked";import Zo 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},Qo=["\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 aT=Zr(ae.ellipsis),cT=new Intl.Segmenter(void 0,{granularity:"grapheme"}),al=e=>Array.from(cT.segment(e),t=>t.segment),lT=(e,t)=>e+" ".repeat(Math.max(0,t-Zr(e))),mT=(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-aT,o="";for(let r of al(e)){if(Zr(o+r)>n)break;o+=r}return o+ae.ellipsis}var Vn=e=>e.replaceAll(" "," "),Je=(e,t)=>lT(qe(e,t),t),Kn=(e,t)=>mT(qe(e,t),t),_e=e=>e.filter(t=>typeof t=="string"&&t!=="").join(` ${ae.bullet} `);var dT=e=>e.startsWith("#")||Bi(e)!==null,pT={spans:[]},vs=e=>e===void 0||e.spans.every(t=>t.text.trim()==="");function yp(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 fT=new Set([..."\uFF0C\u3002\u3001\uFF1B\uFF1A\uFF01\uFF1F\uFF09\u300D\u300F\u3011\u300B\u2026\u201D\u2019,.;:!?)]}"]),gT=new Set([..."\uFF08\u300C\u300E\u3010\u300A\u201C\u2018([{"]),hT=(e,t)=>(Zo(e)>1||Zo(t)>1)&&!gT.has(e)&&!fT.has(t);function yT(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!==" "&&hT(r,i))return{end:o,carry:o}}return null}function bT(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(yp(i)),i=o(),s=n};for(let c of bT(e)){let{ch:l}=c;if(l===`
5
5
  `||l===`\r
6
- `){a();continue}let u=Zo(l);if(s+u>t&&i.length>n){if(l===" "){a();continue}let m=mT(i,l,n),p=m===null?[]:i.slice(m.carry),d=p.reduce((b,h)=>b+Zo(h.ch),0);m===null||n+d+u>t?a():(i=i.slice(0,m.end),a(),i=[...i,...p],s=n+d)}i.push(c),s+=u}return(i.length>0||r.length===0)&&r.push(pp(i)),r}var hp=(e,t)=>t==="docs"?e.replaceAll(`
7
- `," "):e;function an(e,t,n){if(e===void 0)return[];let o=[];for(let r of e)switch(r.type){case"text":o.push(..."tokens"in r&&r.tokens!==void 0?an(r.tokens,t,n):[{text:hp(r.text,n),...t}]);break;case"strong":o.push(...an(r.tokens,{...t,bold:!0},n));break;case"em":o.push(...an(r.tokens,t,n));break;case"del":o.push(...an(r.tokens,{...t,color:f.faintForeground},n));break;case"codespan":o.push({text:r.text,color:f.accent,bold:t.bold});break;case"link":{let i=an(r.tokens,{...t,color:f.accent},n);o.push(...i);let s=i.map(a=>a.text).join("");r.href!==s&&!(n==="docs"&&iT(r.href))&&o.push({text:`\uFF08${r.href}\uFF09`,color:f.faintForeground});break}case"image":if(n==="docs"){o.push({text:r.text===""?"[\u56FE\u7247]":`[\u56FE\u7247] ${r.text}`,color:f.mutedForeground});break}o.push({text:r.text===""?"\u56FE\u7247":r.text,...t}),o.push({text:`\uFF08${r.href}\uFF09`,color:f.faintForeground});break;case"br":o.push({text:`
8
- `});break;case"escape":o.push({text:r.text,...t});break;default:o.push({text:r.raw,...t})}return o}var fp=2,gp=e=>e.reduce((t,n)=>t+Zo(n.text),0);function dT(e,t,n,o,r){let i=e.map(d=>({spans:an(d.tokens,{bold:!0,color:f.foreground},r),align:d.align})),s=t.map(d=>d.map(b=>({spans:an(b.tokens,{color:f.foreground},r),align:b.align}))),a=o-(e.length+1)-e.length*2;if(a<e.length*fp)return Pt([{text:n,color:f.foreground}],o);let c=e.map(()=>fp);for(let d of[i,...s])d.forEach((b,h)=>{for(let g of Pt(b.spans,Number.MAX_SAFE_INTEGER)){let x=c[h],T=gp(g.spans);x!==void 0&&T>x&&(c[h]=T)}});let l=c.reduce((d,b)=>d+b,0);for(;l>a;){let d=0,b=0;c.forEach((h,g)=>{h>b&&(d=g,b=h)}),c[d]=b-1,l-=1}let u=d=>({text:d,color:f.faintForeground}),m=(d,b,h)=>({spans:[u(`${d}${c.map(g=>"\u2500".repeat(g+2)).join(b)}${h}`)]}),p=d=>{let b=c.map((x,T)=>{let k=d[T];return{width:x,align:k?.align??null,lines:Pt(k?.spans??[],x)}}),h=b.reduce((x,T)=>Math.max(x,T.lines.length),1),g=[];for(let x=0;x<h;x+=1){let T=[];for(let k of b){let S=k.lines[x]?.spans??[],y=k.width-gp(S),R=k.align==="right"?y:k.align==="center"?Math.floor(y/2):0;T.push(u("\u2502"),{text:` ${" ".repeat(R)}`}),T.push(...S),T.push({text:`${" ".repeat(y-R)} `})}T.push(u("\u2502")),g.push({spans:T})}return g};return[m("\u250C","\u252C","\u2510"),...p(i),m("\u251C","\u253C","\u2524"),...s.flatMap(p),m("\u2514","\u2534","\u2518")]}function rl(e,t,n){let o=[],r=()=>{o.length>0&&!Ss(o[o.length-1])&&o.push(sT)};for(let i of e)switch(i.type){case"space":r();break;case"heading":{let s=an(i.tokens,{bold:!0,color:f.foreground},n),a=i.depth<=2?[{text:`${ae.section} `,color:f.accent},...s]:s,c=n==="docs"?Ru(i.text):void 0;Pt(a,t,i.depth<=2?2:0).forEach((l,u)=>o.push(u===0?{...l,anchor:c}:l)),r();break}case"paragraph":o.push(...Pt(an(i.tokens,{color:f.foreground},n),t)),r();break;case"text":o.push(...Pt("tokens"in i&&i.tokens!==void 0?an(i.tokens,{color:f.foreground},n):[{text:hp(i.text,n),color:f.foreground}],t));break;case"code":for(let s of i.text.split(`
9
- `))o.push(...Pt([{text:` ${s}`,color:f.mutedForeground}],t,2));r();break;case"blockquote":{let s=rl(i.tokens??[],Math.max(4,t-2),n);for(;s.length>0&&Ss(s[s.length-1]);)s.pop();for(let a of s)o.push({spans:[{text:`${ae.section} `,color:f.accent},...a.spans.map(c=>({...c,color:c.color??f.mutedForeground}))]});r();break}case"list":{let s=i.ordered===!0,a=typeof i.start=="number"?i.start:1;i.items.forEach((c,l)=>{let u=s?`${a+l}. `:`${ae.bullet} `,m=Zo(u),p=rl(c.tokens,Math.max(4,t-m),n);p.forEach((d,b)=>{Ss(d)&&b===p.length-1||o.push({spans:b===0?[{text:u,color:f.mutedForeground},...d.spans]:[{text:" ".repeat(m)},...d.spans]})})}),r();break}case"hr":o.push({spans:[{text:"\u2500".repeat(Math.max(1,t)),color:f.faintForeground}]}),r();break;case"table":o.push(...dT(i.header,i.rows,i.raw,t,n)),r();break;default:o.push(...Pt([{text:i.raw,color:f.foreground}],t))}return o}var il=(e,t)=>an(e,{},t).map(n=>n.text).join("");function hn(e,t,n="default"){let o=rT.lex(Vn(e),{gfm:!0,breaks:n!=="docs"}),r=rl(o,Math.max(8,t),n);for(;r.length>0&&Ss(r[r.length-1]);)r.pop();return r}import{Text as cn,useInput as pT}from"ink";import{useImperativeHandle as fT,useRef as yp,useEffect as gT,useState as Sp}from"react";import sl from"string-width";import{jsx as yn,jsxs as al}from"react/jsx-runtime";var hT=e=>e.replace(new RegExp("\\p{Cc}","gu"),"");function bp(e,t,n){let o=t,r=0;for(;o>0;){let s=sl(e[o-1]??"");if(r+s>n)break;r+=s,o-=1}let i=t;for(r+=1;i<e.length;){let s=sl(e[i]??"");if(r+s>n)break;r+=s,i+=1}return{start:o,before:e.slice(o,t).join(""),at:e[t]??" ",after:e.slice(t+1,i).join("")}}function Zr({char:e}){return yn(cn,{backgroundColor:f.cursorBackground,color:f.foreground,children:e})}function er({value:e,onChange:t,onSubmit:n,placeholder:o,mask:r=!1,isActive:i=!0,width:s=40,ref:a}){let c=[...e],[l,u]=Sp(c.length),m=Math.min(l,c.length),p=Math.max(8,s),d=yp(e),b=yp(m);d.current=e,b.current=m,ms(i);let h=y=>{b.current=y,u(y)},g=(y,R)=>{d.current=y,h(R),t(y)};if(fT(a,()=>({moveToColumn:y=>{let R=[...d.current],N=r?Array.from({length:R.length},()=>"\u2022"):R,W=bp(N,Math.min(b.current,R.length),p).start,M=0;for(;W<R.length;){let C=sl(N[W]??"");if(M+C>y)break;M+=C,W+=1}h(W)}})),pT((y,R)=>{let N=[...d.current],E=Math.min(b.current,N.length);if(R.return){n(d.current);return}if(R.tab||R.upArrow||R.downArrow)return;if(R.leftArrow){h(Math.max(0,E-1));return}if(R.rightArrow){h(Math.min(N.length,E+1));return}if(R.home){h(0);return}if(R.end){h(N.length);return}if(R.backspace){if(E===0)return;g([...N.slice(0,E-1),...N.slice(E)].join(""),E-1);return}if(R.delete){if(E>=N.length)return;g([...N.slice(0,E),...N.slice(E+1)].join(""),E);return}if(R.ctrl){if(y==="a")h(0);else if(y==="e")h(N.length);else if(y==="k")g(N.slice(0,E).join(""),E);else if(y==="u")g(N.slice(E).join(""),0);else if(y==="w"){let v=E;for(;v>0&&N[v-1]===" ";)v-=1;for(;v>0&&N[v-1]!==" ";)v-=1;g([...N.slice(0,v),...N.slice(E)].join(""),v)}return}if(R.meta||!y)return;let W=y.search(/[\r\n]/),M=hT(W===-1?y:y.slice(0,W)),C=[...N.slice(0,E),M,...N.slice(E)].join("");g(C,E+[...M].length),W!==-1&&n(C)},{isActive:i}),e===""){let y=[...o??""];return i?al(cn,{children:[yn(Zr,{char:y[0]??" "}),yn(cn,{color:f.faintForeground,children:y.slice(1).join("")})]}):yn(cn,{color:f.faintForeground,children:y.join("")})}let x=r?Array.from({length:c.length},()=>"\u2022"):c;if(!i)return yn(cn,{color:f.foreground,children:x.join("")});let{before:T,at:k,after:S}=bp(x,m,p);return al(cn,{children:[yn(cn,{color:f.foreground,children:T}),yn(Zr,{char:k}),yn(cn,{color:f.foreground,children:S})]})}function Oe({label:e}){let[t,n]=Sp(0);return gT(()=>{let o=setInterval(()=>n(r=>(r+1)%Qo.length),bs);return()=>clearInterval(o)},[]),al(cn,{children:[yn(cn,{color:f.accent,children:Qo[t]}),yn(cn,{color:f.mutedForeground,children:` ${e}`})]})}import{Box as wp,Text as tr}from"ink";import{useEffect as vp,useState as bT}from"react";import kp from"string-width";import{Box as xp,Text as xs}from"ink";import yT from"string-width";import{jsx as ei,jsxs as Tp}from"react/jsx-runtime";var ge=2,Bt=1,qe=1,Xe=Bt+qe;function Rn({title:e,note:t,width:n}){let o=t===void 0?0:yT(t)+2,r=Math.max(0,n-ge-o);return Tp(xs,{wrap:"truncate",children:[ei(xs,{color:f.accent,children:`${ae.section} `}),ei(xs,{bold:!0,color:f.foreground,children:He(e,r)}),t!==void 0&&ei(xs,{color:f.faintForeground,children:` ${t}`})]})}function pe({title:e,note:t,width:n,gap:o=qe,children:r}){return Tp(xp,{flexDirection:"column",children:[ei(Rn,{title:e,note:t,width:n}),ei(xp,{flexDirection:"column",marginTop:o,paddingLeft:ge,children:r})]})}import{jsx as _n,jsxs as Rp}from"react/jsx-runtime";var yo=e=>!("heading"in e),ST=e=>e.flatMap(t=>!yo(t)&&t.heading!==""?[t,{heading:""}]:[t]),Cp=2,Ts=2,xT=(e,t)=>t===void 0?e:e>t?Math.max(1,t-1):t;function TT(e,t,n,o){let[r,i]=Me(o,()=>e.findIndex(u=>yo(u)&&u.disabled!==!0));vp(()=>{i(u=>{let m=Math.min(u,e.length-1);for(let p=0;p<e.length;p+=1)for(let d of[m-p,m+p]){let b=e[d];if(b!==void 0&&yo(b)&&b.disabled!==!0)return d}return Math.max(0,m)})},[e.length]);let s=u=>{i(m=>{let p=e.length;if(p===0)return m;let d=m;for(let b=0;b<p;b+=1){d=(d+u+p)%p;let h=e[d];if(h!==void 0&&yo(h)&&h.disabled!==!0)return d}return m})},a=u=>{let m=e[u];return m!==void 0&&yo(m)&&m.disabled!==!0?m:null},c=u=>{a(u)!==null&&i(u)},l=u=>{let m=a(u);m!==null&&(i(u),n(m.value))};return G((u,m)=>{if(m.upArrow||u==="k"){s(-1);return}if(m.downArrow||u==="j"){s(1);return}m.return&&l(r)},t),{index:Math.max(0,r),step:s,pick:l,moveTo:c}}function cl(e,t){let[n,o]=bT(()=>e>=t?e-t+1:0);return vp(()=>{o(r=>e<r?e:e>=r+t?e-t+1:r)},[e,t]),n}function wT(e,t){let n=e.filter(yo),o=Math.max(0,...n.map(s=>kp(s.label))),r=Math.max(0,...n.map(s=>s.badge===void 0?0:kp(s.badge))),i=Cp+o+(r>0?r+Ts:0)+Ts;return{label:o,badge:r,hint:Math.max(0,t-i)}}function kT({item:e,active:t,metrics:n}){let o=e.disabled===!0,r=o?f.faintForeground:e.labelTone!==void 0?et[e.labelTone]:t?f.accent:f.foreground;return Rp(tr,{wrap:"truncate",children:[_n(tr,{color:f.accent,children:t?`${ae.cursor} `:" "}),_n(tr,{color:r,bold:t,children:Je(e.label,n.label)}),n.badge>0&&_n(tr,{color:e.badgeTone===void 0?f.faintForeground:et[e.badgeTone],children:`${" ".repeat(Ts)}${Je(e.badge??"",n.badge)}`}),e.hint!==void 0&&n.hint>0&&_n(tr,{color:o||!t?f.faintForeground:f.mutedForeground,children:`${" ".repeat(Ts)}${He(e.hint,n.hint)}`})]})}function vT({items:e,cursor:t,metrics:n,window:o,width:r,isActive:i,onPick:s,onHover:a,onScroll:c}){let l=cl(t,o),u=e.slice(l,l+o),m=d=>d<u.length?l+d:null,p=rt({isActive:i,onWheel:c,onClick:({row:d})=>{let b=m(d);b!==null&&s(b)},onHover:({row:d})=>{let b=m(d);b!==null&&a(b)}});return Rp(wp,{ref:p,flexDirection:"column",children:[u.map((d,b)=>{let h=l+b;return yo(d)?_n(kT,{item:d,active:h===t&&i,metrics:n},h):d.heading===""?_n(wp,{height:1},h):_n(Rn,{title:d.heading,width:r},h)}),e.length>o&&_n(tr,{color:f.faintForeground,children:`${" ".repeat(Cp)}${l+1}-${Math.min(l+o,e.length)} / ${e.length}`})]})}function le({items:e,onSelect:t,width:n,height:o,isActive:r=!0,retain:i}){let s=ST(e),a=TT(s,r,t,i);return _n(vT,{items:s,cursor:a.index,metrics:wT(s,n),window:xT(s.length,o),width:n,isActive:r,onPick:a.pick,onHover:a.moveTo,onScroll:a.step})}import{jsx as Xt,jsxs as ws}from"react/jsx-runtime";var _p={ok:{glyph:ae.ok,color:f.success},warn:{glyph:ae.warn,color:f.warning},fail:{glyph:ae.fail,color:f.danger},info:{glyph:ae.bullet,color:f.mutedForeground}},ll=2,ml=(e,t)=>Pt([{text:Vn(e)}],t-ll).map(n=>n.spans.map(o=>o.text).join("")),ul=(e,t,n)=>ml(e,n).length+(t===void 0?0:ml(t,n).length);function ye({tone:e,title:t,detail:n,width:o,wrap:r=!1}){let i=_p[e],s=c=>r?ml(c,o):[He(c,o-ll)],a=" ".repeat(ll);return ws(ti,{flexDirection:"column",children:[s(t).map((c,l)=>ws(nr,{children:[Xt(nr,{color:i.color,children:l===0?`${i.glyph} `:a}),Xt(nr,{color:f.foreground,children:c})]},l)),n!==void 0&&s(n).map((c,l)=>Xt(nr,{color:f.faintForeground,children:`${a}${c}`},`detail-${l}`))]})}function Ft({message:e,hint:t,width:n}){return Xt(ye,{tone:"fail",title:e,detail:t,width:n})}var CT=2,RT=2;function Pp({tone:e,message:t,width:n,onDismiss:o}){let r=_p[e],i=rt({onClick:o});return ws(ti,{ref:i,children:[Xt(nr,{backgroundColor:f.border,color:r.color,wrap:"truncate",children:` ${r.glyph} `}),Xt(nr,{backgroundColor:f.border,color:f.foreground,wrap:"truncate",children:`${He(t,n-CT-RT)} `})]})}function Ae({title:e,detail:t,confirmLabel:n,onConfirm:o,onCancel:r,width:i,busy:s,error:a}){return ws(ti,{flexDirection:"column",children:[Xt(ye,{tone:"warn",title:e,detail:t,width:i}),a!=null&&Xt(ti,{marginTop:1,children:Xt(Ft,{message:a.message,hint:a.hint,width:i})}),Xt(ti,{marginTop:1,children:typeof s=="string"?Xt(Oe,{label:s}):Xt(le,{items:[{value:"cancel",label:"\u53D6\u6D88"},{value:"confirm",label:n,labelTone:"danger"}],width:i,onSelect:c=>c==="confirm"?o():r()})})]})}import{Box as _T,Text as ks,useInput as PT}from"ink";import{useRef as AT}from"react";import{jsx as vs,jsxs as ET}from"react/jsx-runtime";function pt({lines:e,height:t,isActive:n=!0,pinBottom:o=!1,pageKeysOnly:r=!1,start:i=0,retain:s}){let a=e.length>t,c=a?Math.max(1,t-1):t,l=Math.max(0,e.length-c),[u,m]=Me(s,()=>o?l:Math.min(i,l)),p=AT(l);if(l!==p.current||u>l){let g=u>=p.current;p.current=l;let x=o&&g?l:Math.min(u,l);x!==u&&m(x)}let d=g=>m(x=>Math.min(Math.max(0,x+g),l));PT((g,x)=>{x.pageUp?d(-c):x.pageDown?d(c):!r&&x.upArrow?d(-1):!r&&x.downArrow&&d(1)},{isActive:n&&a}),G(g=>{g==="k"?d(-1):g==="j"&&d(1)},n&&a&&!r);let b=rt({isActive:n&&a,onWheel:d}),h=e.slice(u,u+c);return ET(_T,{ref:b,flexDirection:"column",children:[h.map((g,x)=>vs(ks,{wrap:"truncate",children:g.spans.length===0?" ":g.spans.map((T,k)=>vs(ks,{color:T.color??f.foreground,bold:T.bold===!0,children:T.text},k))},u+x)),Array.from({length:Math.max(0,c-h.length)},(g,x)=>vs(ks,{children:" "},x)),a&&vs(ks,{color:f.faintForeground,wrap:"truncate",children:`${u+1}-${Math.min(u+c,e.length)} / ${e.length}`})]})}function ht(e){return e.tone==="neutral"?void 0:e.tone}function yt(e){let t=ht(e);return t===void 0?e.label:{text:e.label,tone:t}}import{useCallback as dl,useRef as MT,useState as Ap}from"react";function ue(){let e=O(),[t,n]=Ap(null),[o,r]=Ap(null),i=MT(0),s=dl(()=>{i.current+=1,n(null),r(null)},[]),a=dl((l,u)=>{r({message:l,hint:u})},[]),c=dl((l,u,m={})=>{let p=i.current+=1;n(l),r(null),u().then(d=>{i.current===p&&(n(null),m.onSuccess?.(d))}).catch(d=>{if(i.current!==p)return;n(null);let b={message:xe(d),hint:d instanceof U?d.hint:void 0};m.failToast===!0?e.toast("fail",b.message):r(b)})},[e]);return{busy:t,error:o,reset:s,fail:a,run:c}}import{Box as ir}from"ink";import{Box as IT,Text as Ep}from"ink";import Ip from"string-width";import{jsx as Mp,jsxs as NT}from"react/jsx-runtime";var Cs=["\u2588\u2580\u2580 \u2588\u2580\u2588 \u2588\u2580\u2584 \u2588\u2580\u2580 \u2588\u2580\u2580 \u2588 \u2588\u2580\u2588 \u2588 \u2588 \u2588","\u2588\u2584\u2584 \u2588\u2584\u2588 \u2588\u2584\u2580 \u2588\u2584\u2584 \u2588\u2580\u2580 \u2588\u2584\u2584 \u2588\u2584\u2588 \u2580\u2584\u2580\u2584\u2580"],Np=Math.max(...Cs.map(e=>Ip(e))),Rs=Cs.length,_s=e=>Np<=e;function Ps({width:e}){let t=`v${Vt}`,n=Np+2+Ip(t)<=e;return Mp(IT,{flexDirection:"column",children:Cs.map((o,r)=>NT(Ep,{color:f.accent,children:[o,r===Cs.length-1&&n&&Mp(Ep,{color:f.faintForeground,children:` ${t}`})]},o))})}import{Box as gl,Text as wt}from"ink";import{useState as Lp}from"react";import bo from"string-width";import{jsx as Qt,jsxs as rr}from"react/jsx-runtime";var As=2,pl=` ${ae.crumb} `;function Es({trail:e,width:t,onBack:n,isActive:o}){let r=e[e.length-1]??"",i=e.slice(0,-1),s=i.reduce((p,d)=>p+bo(d)+bo(pl),0),a=s+bo(r)<=t,c=a?s:0,[l,u]=Lp(!1),m=rt({isActive:o,onClick:({column:p})=>{p<c&&n()},onHover:({column:p})=>u(p<c),onHoverLeave:()=>u(!1)});return Qt(gl,{ref:m,marginBottom:1,children:a?rr(wt,{children:[i.map((p,d)=>rr(wt,{children:[Qt(wt,{color:d===0?f.accent:l&&o?f.foreground:f.mutedForeground,children:p}),Qt(wt,{color:f.faintForeground,children:pl})]},d)),Qt(wt,{bold:!0,color:f.foreground,children:r})]}):Qt(wt,{color:f.mutedForeground,children:He(e.join(pl),t)})})}var fl=2,ni=2,or=2;function Op({current:e,width:t,onPick:n,isActive:o,unread:r}){let i=Math.max(0,Jr(e)),[s,a]=Lp(null),c=y=>r[y.id]===!0,l=y=>c(y)?`${y.label} ${ae.dot}`:y.label,u=Math.max(...Tt.map(y=>bo(y.label))),m=Tt.some(c)?bo(` ${ae.dot}`):0,d=(y=>y*u+(y-1)*ni+fl+m)(Tt.length)>t,b=d?t-or*2:t,h=d?Math.max(1,Math.floor((b-m+ni-fl)/(u+ni))):Tt.length,g=Math.min(Math.max(0,i-Math.floor((h-1)/2)),Tt.length-h),x=Tt.slice(g,g+h),T=[],k=d?or:0;x.forEach((y,R)=>{R>0&&(k+=ni);let N=bo(l(y))+(y.id===e?fl:0);T.push({id:y.id,from:k,to:k+N}),k+=N});let S=rt({isActive:o,onHover:({column:y})=>{let R=T.find(N=>y>=N.from&&y<N.to);a(R?.id??null)},onHoverLeave:()=>a(null),onClick:({column:y})=>{let R=T.find(E=>y>=E.from&&y<E.to);if(R!==void 0){n(R.id);return}if(!d||y>=or&&y<k)return;let N=y<or?Tt[g-1]:Tt[g+h];N!==void 0&&n(N.id)}});return Qt(gl,{ref:S,marginBottom:1,children:rr(wt,{wrap:"truncate",children:[d&&Qt(wt,{color:f.border,children:g>0?`${ae.prev} `:" ".repeat(or)}),x.map((y,R)=>{let N=c(y)&&Qt(wt,{color:f.danger,children:` ${ae.dot}`});return rr(wt,{children:[R>0&&" ".repeat(ni),y.id===e?rr(wt,{backgroundColor:f.foreground,color:f.background,bold:!0,children:[` ${y.label}`,N," "]}):rr(wt,{children:[Qt(wt,{color:o&&y.id===s?f.foreground:f.mutedForeground,children:y.label}),N]})]},y.id)}),d&&Qt(wt,{color:f.border,children:g+h<Tt.length?` ${ae.next}`:" ".repeat(or)})]})})}var LT=2;function Dp(e,t){let n=[];for(let o of e){let r=n[n.length-1];if(r!==void 0&&bo(_e([...r,o]))<=t)r.push(o);else if(n.length<LT)n.push([o]);else break}return n.map(_e)}function $p({lines:e}){return Qt(gl,{flexDirection:"column",flexShrink:0,children:e.map((t,n)=>Qt(wt,{wrap:"truncate",color:f.faintForeground,children:t},n))})}import{createContext as OT,useCallback as DT,useContext as $T,useEffect as Hp,useMemo as BT,useRef as qp,useState as FT}from"react";var Bp=e=>A(mt(od),Fe("/inbox",{...e})),Fp=()=>A(rd,"/inbox/unread"),Up=e=>A(se,`/inbox/${e}/read`,{method:"POST"}),jp=()=>A(se,"/inbox/read-all",{method:"POST"});import{jsx as jT}from"react/jsx-runtime";var UT=6e4,Gp=OT(null);function zp({children:e}){let{revision:t,toast:n}=O(),[o,r]=FT(!1),i=qp(0),s=qp(!1),a=DT(()=>{let l=i.current+=1;if(Lt().session===null){r(!1);return}Fp().then(u=>{s.current=!1,i.current===l&&r(u.unread)},u=>{i.current!==l||s.current||(s.current=!0,n("warn",`\u7AD9\u5185\u6D88\u606F\u672A\u8BFB\u72B6\u6001\u83B7\u53D6\u5931\u8D25\uFF1A${xe(u)}`))})},[n]);Hp(a,[t,a]),Hp(()=>{let l=setInterval(a,UT);return()=>clearInterval(l)},[a]);let c=BT(()=>({any:o,refresh:a}),[o,a]);return jT(Gp.Provider,{value:c,children:e})}function Ms(){let e=$T(Gp);if(!e)throw new Error("useUnread \u5FC5\u987B\u5728 UnreadProvider \u5185\u4F7F\u7528");return e}import{Fragment as qT,jsx as kt,jsxs as Kp}from"react/jsx-runtime";var Wp=3,HT=8;function oi(e){let{rows:t}=j();return Math.max(1,t-Yc-Wp-e)}function Vp(){let e=O(),{width:t,rows:n}=j(),o=e.current.id,r=e.depth===1&&fs(o)?o:null,i=Math.max(1,n-Yc-Wp),s=Rs+X,a=r!==null&&_s(t)&&i-As-s>=HT;return{tab:r,mark:a,rows:a?As+s:As}}var Z=()=>oi(Vp().rows);function So({header:e,hints:t,children:n}){let{width:o}=j(),{message:r,dismissToast:i}=O(),s=Dp(t,o);return Kp(ir,{flexDirection:"column",flexGrow:1,children:[kt(ir,{flexDirection:"column",flexShrink:0,children:e}),kt(ir,{flexDirection:"column",flexGrow:1,overflow:"hidden",children:kt(ir,{flexDirection:"column",flexShrink:0,children:n})}),kt(ir,{height:1,marginTop:s.length>1?0:1,flexShrink:0,justifyContent:"flex-end",children:r!==null&&kt(Pp,{tone:r.tone,message:r.message,width:o,onDismiss:i})}),kt($p,{lines:s})]})}function Y({trail:e,hints:t=[],children:n,onEscape:o,isActive:r=!0,locked:i=!1,bleed:s=!1}){let a=O(),{width:c}=j(),{tab:l,mark:u}=Vp(),m=Ms(),p=us(),d=ds(),b=Zd(),h=r&&!b,g=h?t:t.filter(y=>y!=="Esc \u8FD4\u56DE"),x=d||p?[]:[...r?["[] \u5207\u529F\u80FD"]:[],"q \u9000\u51FA","? \u5E2E\u52A9"],T=[...h?["Esc \u8FD4\u56DE"]:[],...d||p?[]:["? \u5E2E\u52A9"]];gn(o??a.pop,{isActive:r});let k=ep(),S=r&&!i&&!p;return G(y=>{if(l===null||y!=="["&&y!=="]")return;let R=Tt[(Jr(l)+(y==="["?-1:1)+Tt.length)%Tt.length];R!==void 0&&a.select(R.id)},r&&!i&&!p&&!s),s?kt(So,{header:null,hints:i?g:[...g,...T],children:n}):l!==null?kt(So,{header:Kp(qT,{children:[u&&kt(ir,{marginBottom:X,children:kt(Ps,{width:c})}),kt(Op,{current:l,width:c,onPick:y=>{y===l?k():a.select(y)},isActive:S,unread:{inbox:m.any}})]}),hints:i?g:[...g,...x],children:n}):kt(So,{header:kt(Es,{trail:["CodeFlow",...e??[]],width:c,onBack:k,isActive:S}),hints:i?g:[...g,...T],children:n})}function V({state:e,loading:t,width:n,children:o}){return e.phase==="loading"?kt(Oe,{label:t}):e.phase==="error"?kt(Ft,{message:e.message,hint:e.hint,width:n}):o(e.data)}import{jsx as Zt,jsxs as hl}from"react/jsx-runtime";function Yp({params:e}){let t=O(),{width:n}=j(),o=Z(),{item:r}=e,{busy:i,error:s,run:a}=ue();GT((m,p)=>{p.return&&a("\u6B63\u5728\u786E\u8BA4",()=>is(r.id),{onSuccess:()=>t.pop()})},{isActive:i===null});let c=Gr(r.level),l=ht(c),u=Math.max(3,o-4-(s===null?0:2));return Zt(Y,{trail:["\u7CFB\u7EDF\u516C\u544A","\u672A\u8BFB\u786E\u8BA4"],hints:["\u2191\u2193 \u6EDA\u52A8","Enter \u6211\u77E5\u9053\u4E86"],locked:!0,onEscape:()=>{},children:hl(Is,{flexDirection:"column",children:[hl(xo,{wrap:"truncate",children:[Zt(xo,{bold:!0,color:f.foreground,children:r.title}),Zt(xo,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),Zt(xo,{color:f.faintForeground,children:` \u53D1\u5E03\u4E8E ${K(r.publishedAt)}`})]}),Zt(Is,{marginTop:1,children:Zt(pt,{lines:hn(r.content,n),height:u})}),s!==null&&Zt(Is,{marginTop:1,children:Zt(Ft,{message:s.message,hint:s.hint,width:n})}),Zt(Is,{marginTop:1,children:i!==null?Zt(Oe,{label:i}):hl(xo,{wrap:"truncate",children:[Zt(xo,{color:f.accent,children:`${ae.cursor} `}),Zt(xo,{bold:!0,color:f.accent,children:"\u6211\u77E5\u9053\u4E86"})]})})]})})}import{Box as wl,Text as Ns}from"ink";import{useState as tw}from"react";import{Box as yl,Text as Pn}from"ink";import{useEffect as bl,useRef as zT,useState as Jp}from"react";import Sl from"string-width";import{jsx as Yn,jsxs as ii}from"react/jsx-runtime";var Xp=e=>e===void 0?"":typeof e=="string"?e:e.text,xl=2,WT=6;function VT(e,t,n){let o=e.map(a=>t===0?n/e.length:n*a/t),r=o.map(a=>Math.floor(a)),i=n-r.reduce((a,c)=>a+c,0),s=o.map((a,c)=>({i:c,fraction:a-Math.floor(a)})).sort((a,c)=>c.fraction-a.fraction);for(let{i:a}of s){if(i<=0)break;r[a]=(r[a]??0)+1,i-=1}return e.map((a,c)=>a+(r[c]??0))}function Tl(e,t,n){let o=e.map((c,l)=>Math.max(Sl(c.label),...t.map(u=>Sl(u[l]??"")))),r=o.reduce((c,l)=>c+l,0),i=r+xl*Math.max(0,e.length-1)-n;if(i<0)return VT(o,r,-i);e.forEach((c,l)=>{if(c.cap===void 0||i<=0)return;let u=Math.min(i,Math.max(0,(o[l]??0)-c.cap));o[l]=(o[l]??0)-u,i-=u});let s=e.flatMap((c,l)=>c.shrink===!0||c.cap!==void 0?[l]:[]),a=s.length>0?s:e.map((c,l)=>l);for(;i>0;){let c=a.filter(l=>(o[l]??0)>WT).sort((l,u)=>(o[u]??0)-(o[l]??0))[0];if(c===void 0)break;o[c]=(o[c]??0)-1,i-=1}return o}var KT=(e,t,n)=>t.map((o,r)=>o.align==="right"?Kn(e[r]??"",n[r]??0):Je(e[r]??"",n[r]??0)).join(" ".repeat(xl)),ri=2,YT=2;function de({items:e,columns:t,row:n,width:o,height:r,onOpen:i,searchOf:s,isActive:a=!0,emptyLabel:c="\u6682\u65E0\u6570\u636E",emptyDescription:l,retain:u,select:m}){let p=$=>u===void 0?void 0:`${u}:${$}`,d=i!==void 0,[b,h]=Me(d?p("cursor"):void 0,()=>0),[g,x]=Me(p("query"),()=>""),[T,k]=Jp(!1),S=g.trim().toLowerCase(),y=S===""||s===void 0?e:e.filter($=>s($).toLowerCase().includes(S)),R=T||S!=="",N=Math.max(1,r-1-(R?1:0)),E=y.length>N?Math.max(1,N-1):N,W=Math.max(0,y.length-E),[M,C]=Jp(()=>b>=E?b-E+1:0);bl(()=>{h($=>Math.min($,Math.max(0,y.length-1)))},[y.length]);let v=m===void 0?-1:y.findIndex(m);bl(()=>{v>=0&&h(v)},[v]),bl(()=>{C($=>d?b<$?b:b>=$+E?b-E+1:$:Math.min($,W))},[b,E,W,d]);let _=$=>{if(!d){C(ne=>Math.min(Math.max(0,ne+$),W));return}y.length!==0&&h(ne=>(ne+$+y.length)%y.length)};G(($,ne)=>{if(ne.upArrow||$==="k"){_(-1);return}if(ne.downArrow||$==="j"){_(1);return}if(ne.return){let w=y[b];w!==void 0&&i?.(w,b);return}s!==void 0&&$.startsWith("/")&&(k(!0),$.length>1&&x($.slice(1)))},a&&!T),gn(()=>{k(!1),x("")},{isActive:T||S!=="",layer:T?Wn.input:Wn.panel});let L=R?1:0,P=zT(null),B=$=>{if($<=L)return null;let ne=M+$-L-1;return y[ne]===void 0?null:ne},J=rt({isActive:a,onWheel:_,onClick:({row:$,column:ne})=>{if(R&&$===0){k(!0),P.current?.moveToColumn(ne-YT);return}if(i===void 0)return;let w=B($);if(w===null)return;let F=y[w];F!==void 0&&(h(w),i(F,w))},onHover:d?({row:$})=>{let ne=B($);ne!==null&&h(ne)}:void 0}),oe=Tl(t,y.map($=>n($).map(Xp)),o-ri),fe=y.slice(M,M+E);return ii(yl,{ref:J,flexDirection:"column",children:[R&&ii(yl,{children:[Yn(Pn,{color:f.accent,children:"/ "}),Yn(er,{ref:P,value:g,onChange:x,onSubmit:()=>k(!1),isActive:T,placeholder:"\u8F93\u5165\u5173\u952E\u8BCD\u8FC7\u6EE4",width:o-2-Sl(` ${y.length}/${e.length}`)}),Yn(Pn,{color:f.faintForeground,children:` ${y.length}/${e.length}`})]}),ii(Pn,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(ri),KT(t.map($=>$.label),t,oe)]}),y.length===0?ii(yl,{flexDirection:"column",children:[Yn(Pn,{wrap:"truncate",color:f.mutedForeground,children:`${" ".repeat(ri)}${S===""?c:"\u65E0\u5339\u914D\u7ED3\u679C"}`}),l!==void 0&&S===""&&N>1&&Yn(Pn,{wrap:"truncate",color:f.faintForeground,children:`${" ".repeat(ri)}${l}`})]}):fe.map(($,ne)=>{let w=M+ne,F=d&&w===b&&a,re=F?f.accent:a?f.foreground:f.mutedForeground,D=n($);return ii(Pn,{wrap:"truncate",children:[Yn(Pn,{color:f.accent,children:F?`${ae.cursor} `:" "}),t.map((z,ee)=>{let he=D[ee],ie=Xp(he),Qe=z.align==="right"?Kn(ie,oe[ee]??0):Je(ie,oe[ee]??0),xt=typeof he=="object"?he.tone:void 0,Ze=!F&&a&&xt!==void 0?et[xt]:re;return Yn(Pn,{color:Ze,bold:F,children:ee>0?`${" ".repeat(xl)}${Qe}`:Qe},z.label)})]},w)}),(M>0||M+E<y.length)&&Yn(Pn,{color:f.faintForeground,children:`${" ".repeat(ri)}${M+1}-${Math.min(M+E,y.length)} / ${y.length}`})]})}import{Text as JT}from"ink";import{useEffect as XT,useRef as QT,useState as ZT}from"react";import{jsx as ew}from"react/jsx-runtime";function ze(e,t,{retain:n}={}){let[o,r]=Me(n,()=>1),[i,s]=ZT({pages:1,total:0}),a=QT(!1),c=Q([...e,o],()=>t(o));XT(()=>{if(c.phase!=="ready")return;let p=Math.max(1,Math.ceil(c.data.total/ou));if(s({pages:p,total:c.data.total}),o>p){r(p);return}a.current&&(a.current=!1,o<p&&r(p))},[c]);let l=p=>{r(d=>Math.min(Math.max(1,d+p),i.pages))},u=()=>r(1),m=()=>{a.current=!0};return{state:c,page:o,pages:i.pages,total:i.total,go:l,reset:u,last:m}}function We({page:e,pages:t,total:n,width:o}){return ew(JT,{wrap:"truncate",color:f.faintForeground,children:He(_e([`\u7B2C ${e} / ${t} \u9875`,`\u5171 ${n} \u6761`,"\u2190\u2192 \u7FFB\u9875"]),o)})}import{jsx as An,jsxs as kl}from"react/jsx-runtime";function Qp(){let e=O(),{width:t}=j(),n=Z(),[o,r]=tw({name:"list"}),i=ze([e.revision],a=>qd({page:a}),{retain:"page"});G((a,c)=>{o.name==="list"&&(a==="r"?e.reload():c.leftArrow?i.go(-1):c.rightArrow&&i.go(1))});let s=()=>{o.name==="list"?e.pop():r({name:"list"})};return An(Y,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"]:["\u2191\u2193 \u6EDA\u52A8","Esc \u8FD4\u56DE"],onEscape:s,children:An(V,{state:i.state,loading:"\u6B63\u5728\u8BFB\u53D6\u516C\u544A",width:t,children:a=>{if(o.name==="detail"){let c=Gr(o.item.level),l=ht(c);return kl(wl,{flexDirection:"column",children:[kl(Ns,{wrap:"truncate",children:[An(Ns,{bold:!0,color:f.foreground,children:o.item.title}),An(Ns,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),An(Ns,{color:f.faintForeground,children:` ${_e([`\u53D1\u5E03\u4E8E ${K(o.item.publishedAt)}`])}`})]}),An(wl,{marginTop:1,children:An(pt,{lines:hn(o.item.content,t),height:Math.max(3,n-2)})})]})}return kl(wl,{flexDirection:"column",children:[An(de,{retain:"list",items:a.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},{label:"\u7EA7\u522B"},{label:"\u53D1\u5E03\u4E8E",align:"right"}],row:c=>[c.title,yt(Gr(c.level)),K(c.publishedAt)],onOpen:c=>{r({name:"detail",item:c}),is(c.id).catch(()=>e.toast("warn","\u5DF2\u8BFB\u786E\u8BA4\u53D1\u9001\u5931\u8D25"))},emptyLabel:"\u6682\u65E0\u516C\u544A",emptyDescription:"\u5E73\u53F0\u6709\u65B0\u901A\u77E5\u65F6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),An(We,{page:i.page,pages:i.pages,total:i.total,width:t})]})}})})}import{Box as at,Text as fi}from"ink";import{useState as xg}from"react";import tk from"string-width";import{z as nw}from"zod";var Ls=e=>`/community/${e.kind==="user"?"users":"staff"}/${encodeURIComponent(e.username)}`,Os=()=>A(nw.array(kc),"/community/categories"),sr=()=>A(Qu,"/community/me"),Zp=e=>A(mt(vc),Fe("/community/posts",{...e})),Ds=e=>A(Cc,`/community/posts/${e}`),ef=e=>A(se,`/community/posts/${e}/view`,{method:"POST"}),tf=(e,t)=>A(mt(Ui),Fe(`/community/posts/${e}/floors`,{page:t})),nf=(e,t)=>A(Ui,`/community/posts/${e}/floors/${t}`),of=(e,t)=>A(mt(Rc),Fe(`/community/comments/${e}/replies`,{page:t})),vl=e=>A(ed,Ls({kind:"user",username:e})),rf=e=>e.kind==="user"?vl(e.username):A(td,Ls(e)),sf=(e,t)=>A(mt(Br),Fe(`${Ls(e)}/posts`,{page:t})),af=(e,t)=>A(mt(ji),Fe(`${Ls(e)}/comments`,{page:t})),cf=e=>A(mt(vc),Fe("/community/mine/bookmarks",{page:e})),lf=e=>A(mt(Ac),Fe("/community/mine/drafts",{page:e})),mf=()=>A(Ju,"/community/mine/todo"),uf=e=>A(Ku,"/community/posts",{method:"POST",json:e}),df=(e,t)=>A(se,`/community/posts/${e}`,{method:"PATCH",json:t}),$s=e=>A(se,`/community/posts/${e}`,{method:"DELETE"}),pf=e=>A(Xu,"/community/drafts",{method:"POST",json:e}),ff=(e,t)=>A(se,`/community/drafts/${e}`,{method:"PATCH",json:t}),gf=(e,t)=>A(se,`/community/drafts/${e}/publish`,{method:"POST",json:t}),hf=(e,t)=>A(Yu,`/community/posts/${e}/comments`,{method:"POST",json:t}),yf=e=>A(se,`/community/comments/${e}`,{method:"DELETE"}),bf=(e,t)=>A(_c,`/community/posts/${e}/like`,{method:t?"PUT":"DELETE"}),Sf=(e,t)=>A(_c,`/community/comments/${e}/like`,{method:t?"PUT":"DELETE"}),xf=(e,t)=>A(se,`/community/posts/${e}/bookmark`,{method:t?"PUT":"DELETE"}),Tf=(e,t)=>A(se,`/community/posts/${e}/reports`,{method:"POST",json:t}),wf=(e,t)=>A(se,`/community/comments/${e}/reports`,{method:"POST",json:t});var En=()=>A(cu,"/auth/me"),kf=e=>A(se,"/auth/me",{method:"PATCH",json:e}),vf=e=>A(se,"/auth/me/password",{method:"POST",json:e}),Cf=e=>A(se,"/auth/me/email/code",{method:"POST",json:e}),Rf=e=>A(se,"/auth/me/email",{method:"POST",json:e}),_f=()=>A(lu,"/auth/me/sessions"),Pf=e=>A(se,`/auth/me/sessions/${e}`,{method:"DELETE"});async function Af(){await A(se,"/auth/me/sessions",{method:"DELETE"}),ts()}var Ef=()=>A(uu,"/auth/me/security"),Cl=e=>A(mu,"/auth/me/totp/setup",{method:"POST",json:e}),Mf=e=>A(lc,"/auth/me/totp/confirm",{method:"POST",json:e}),If=e=>A(se,"/auth/me/totp/disable",{method:"POST",json:e}),Nf=e=>A(lc,"/auth/me/totp/recovery-codes",{method:"POST",json:e}),Lf=(e,t)=>A(se,`/auth/me/passkeys/${e}`,{method:"PATCH",json:t}),Of=e=>A(se,`/auth/me/passkeys/${e}`,{method:"DELETE"});var Rl=12e4,ow=e=>A(Hu,Fe("/media",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Rl}),rw=e=>A(se,`/media/${e}`,{method:"DELETE"}),si={upload:async e=>({...await ow(e),fileName:e.fileName}),discard:rw};async function Df(e){let{bytes:t,headers:n}=await Kc(`/media/${e}`,{timeoutMs:Rl}),o=n.get("content-disposition")?.split("filename*=UTF-8''")[1];if(o===void 0)throw new U("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u9644\u4EF6\u6587\u4EF6\u540D");return{fileName:decodeURIComponent(o),bytes:t}}var $f=()=>A(Pc,"/auth/me/avatar"),Bf=e=>A(Pc,"/auth/me/avatar",{method:"PUT",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:Rl}),Ff=()=>A(se,"/auth/me/avatar",{method:"DELETE"});import{existsSync as Bs,readFileSync as iw,statSync as Uf,writeFileSync as sw}from"fs";import{homedir as _l}from"os";import en from"path";var aw={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif"},jf=e=>e.startsWith("~/")?en.join(_l(),e.slice(2)):e;function cw(e){return e.split(`
10
- `).map(t=>t.trim()).filter(t=>t!=="").map(jf)}function Hf(e,t,n){if(!Bs(e))throw new U(`${e} \u4E0D\u5B58\u5728`);let o=Uf(e);if(!o.isFile())throw new U(`${e} \u4E0D\u662F\u6587\u4EF6`);if(o.size===0)throw new U(`${e} \u662F\u7A7A\u6587\u4EF6\uFF0C\u65E0\u6CD5\u4E0A\u4F20`);if(o.size>t)throw new U(`${e} \u8D85\u8FC7\u5355\u4E2A${n}\u5927\u5C0F\u4E0A\u9650 ${Ko(t)}`);let r=en.basename(e);return{filePath:e,fileName:r,contentType:aw[en.extname(r).toLowerCase()]??"application/octet-stream"}}function qf(e){let t;try{t=iw(e.filePath)}catch(n){throw new U(`${e.filePath} \u8BFB\u53D6\u5931\u8D25\uFF1A${xe(n)}`,{cause:n})}return{fileName:e.fileName,contentType:e.contentType,bytes:t}}function Jn(e,t){let n=cw(e);if(n.length>t.maxCount)throw new U("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return n.map(o=>Hf(o,t.maxBytes,"\u9644\u4EF6"))}function Gf(e,t){let n=Hf(jf(e),t,"\u56FE\u7247");if(!n.contentType.startsWith("image/"))throw new U("\u4EC5\u652F\u6301 PNG\u3001JPG\u3001WebP\u3001GIF\u3001AVIF \u683C\u5F0F\u7684\u56FE\u7247");return qf(n)}async function Mn(e,t,n){let o=[];try{for(let r of e)o.push(await t.upload(qf(r)));return await n(o)}catch(r){let s=(await Promise.allSettled(o.map(l=>t.discard(l.id)))).filter(l=>l.status==="rejected").length;if(s===0)throw r;let a=`${s} \u4E2A\u5DF2\u4E0A\u4F20\u7684\u9644\u4EF6\u672A\u80FD\u6E05\u7406\uFF0C\u5C06\u5728 24 \u5C0F\u65F6\u540E\u81EA\u52A8\u5220\u9664`,c=r instanceof U?r:null;throw new U(xe(r),{hint:c?.hint===void 0?a:`${c.hint}\uFF1B${a}`,...c===null?{}:{exitCode:c.exitCode},cause:r})}}function lw(e,t){let n=en.basename(t),o=en.extname(n),r=n.slice(0,n.length-o.length),i=en.join(e,n);for(let s=1;Bs(i);s+=1)i=en.join(e,`${r}-${s}${o}`);return i}function mw(e,t){let n=e.trim();if(n==="")return{dir:process.cwd(),fileName:t};if(n==="~")return{dir:_l(),fileName:t};let o=n.startsWith("~/")||n.startsWith(`~${en.sep}`)?en.join(_l(),n.slice(2)):n;return n.endsWith("/")||n.endsWith(en.sep)||Bs(o)&&Uf(o).isDirectory()?{dir:o,fileName:t}:{dir:en.dirname(o),fileName:en.basename(o)}}function zf(e,t,n){let o=mw(e,t);if(!Bs(o.dir))throw new U(`${o.dir} \u76EE\u5F55\u4E0D\u5B58\u5728`);let r=lw(o.dir,o.fileName);try{sw(r,n)}catch(i){throw new U(`\u5199\u5165 ${r} \u5931\u8D25\uFF1A${xe(i)}`,{cause:i})}return r}import{Box as tn,measureElement as Zf,Text as Be,useInput as ig}from"ink";import{useEffect as eg,useRef as tg,useState as ar}from"react";import Ml from"string-width";import{Box as uw,Text as Xn,useInput as dw}from"ink";import{useRef as Wf,useState as Vf}from"react";import Al from"string-width";import{jsx as In,jsxs as Xf}from"react/jsx-runtime";var pw=e=>e.replace(/\r\n?/g,`
11
- `).replace(new RegExp("(?!\\n)\\p{Cc}","gu"),"");function Kf(e,t){let n=[],o=0,r=0;for(let i=0;i<e.length;i+=1){let s=e[i]??"";if(s===`
12
- `){n.push({start:o,end:i,nl:!0}),o=i+1,r=0;continue}let a=Al(s);r+a>t&&i>o&&(n.push({start:o,end:i,nl:!1}),o=i,r=0),r+=a}return n.push({start:o,end:e.length,nl:!1}),n}function Yf(e,t){for(let n=0;n<e.length;n+=1){let o=e[n];if(o!==void 0&&(o.nl?t<=o.end:t<o.end))return n}return e.length-1}function Jf(e,t,n){let o=0;for(let r=t.start;r<t.end;r+=1){let i=Al(e[r]??"");if(o+i>n)return r;o+=i}return t.end}var fw=(e,t,n)=>e.slice(t.start,n).reduce((o,r)=>o+Al(r),0);function Pl(e,t){let n=t;for(;n>0&&e[n-1]!==`
6
+ `){a();continue}let u=Zo(l);if(s+u>t&&i.length>n){if(l===" "){a();continue}let m=yT(i,l,n),p=m===null?[]:i.slice(m.carry),d=p.reduce((b,h)=>b+Zo(h.ch),0);m===null||n+d+u>t?a():(i=i.slice(0,m.end),a(),i=[...i,...p],s=n+d)}i.push(c),s+=u}return(i.length>0||r.length===0)&&r.push(yp(i)),r}var xp=(e,t)=>t==="docs"?e.replaceAll(`
7
+ `," "):e;function an(e,t,n){if(e===void 0)return[];let o=[];for(let r of e)switch(r.type){case"text":o.push(..."tokens"in r&&r.tokens!==void 0?an(r.tokens,t,n):[{text:xp(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"&&dT(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 bp=2,Sp=e=>e.reduce((t,n)=>t+Zo(n.text),0);function ST(e,t,n,o,r){let i=e.map(d=>({spans:an(d.tokens,{bold:!0,color:f.foreground},r),align:d.align})),s=t.map(d=>d.map(b=>({spans:an(b.tokens,{color:f.foreground},r),align:b.align}))),a=o-(e.length+1)-e.length*2;if(a<e.length*bp)return At([{text:n,color:f.foreground}],o);let c=e.map(()=>bp);for(let d of[i,...s])d.forEach((b,h)=>{for(let g of At(b.spans,Number.MAX_SAFE_INTEGER)){let x=c[h],T=Sp(g.spans);x!==void 0&&T>x&&(c[h]=T)}});let l=c.reduce((d,b)=>d+b,0);for(;l>a;){let d=0,b=0;c.forEach((h,g)=>{h>b&&(d=g,b=h)}),c[d]=b-1,l-=1}let u=d=>({text:d,color:f.faintForeground}),m=(d,b,h)=>({spans:[u(`${d}${c.map(g=>"\u2500".repeat(g+2)).join(b)}${h}`)]}),p=d=>{let b=c.map((x,T)=>{let k=d[T];return{width:x,align:k?.align??null,lines:At(k?.spans??[],x)}}),h=b.reduce((x,T)=>Math.max(x,T.lines.length),1),g=[];for(let x=0;x<h;x+=1){let T=[];for(let k of b){let S=k.lines[x]?.spans??[],y=k.width-Sp(S),R=k.align==="right"?y:k.align==="center"?Math.floor(y/2):0;T.push(u("\u2502"),{text:` ${" ".repeat(R)}`}),T.push(...S),T.push({text:`${" ".repeat(y-R)} `})}T.push(u("\u2502")),g.push({spans:T})}return g};return[m("\u250C","\u252C","\u2510"),...p(i),m("\u251C","\u253C","\u2524"),...s.flatMap(p),m("\u2514","\u2534","\u2518")]}function cl(e,t,n){let o=[],r=()=>{o.length>0&&!vs(o[o.length-1])&&o.push(pT)};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"?_u(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:xp(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=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=Zo(u),p=cl(c.tokens,Math.max(4,t-m),n);p.forEach((d,b)=>{vs(d)&&b===p.length-1||o.push({spans:b===0?[{text:u,color:f.mutedForeground},...d.spans]:[{text:" ".repeat(m)},...d.spans]})})}),r();break}case"hr":o.push({spans:[{text:"\u2500".repeat(Math.max(1,t)),color:f.faintForeground}]}),r();break;case"table":o.push(...ST(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=uT.lex(Vn(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 xT}from"ink";import{useImperativeHandle as TT,useRef as Tp,useEffect as wT,useState as kp}from"react";import ml from"string-width";import{jsx as yn,jsxs as ul}from"react/jsx-runtime";var kT=e=>e.replace(new RegExp("\\p{Cc}","gu"),"");function wp(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 er({value:e,onChange:t,onSubmit:n,placeholder:o,mask:r=!1,isActive:i=!0,width:s=40,ref:a}){let c=[...e],[l,u]=kp(c.length),m=Math.min(l,c.length),p=Math.max(8,s),d=Tp(e),b=Tp(m);d.current=e,b.current=m,gs(i);let h=y=>{b.current=y,u(y)},g=(y,R)=>{d.current=y,h(R),t(y)};if(TT(a,()=>({moveToColumn:y=>{let R=[...d.current],N=r?Array.from({length:R.length},()=>"\u2022"):R,W=wp(N,Math.min(b.current,R.length),p).start,M=0;for(;W<R.length;){let C=ml(N[W]??"");if(M+C>y)break;M+=C,W+=1}h(W)}})),xT((y,R)=>{let N=[...d.current],E=Math.min(b.current,N.length);if(R.return){n(d.current);return}if(R.tab||R.upArrow||R.downArrow)return;if(R.leftArrow){h(Math.max(0,E-1));return}if(R.rightArrow){h(Math.min(N.length,E+1));return}if(R.home){h(0);return}if(R.end){h(N.length);return}if(R.backspace){if(E===0)return;g([...N.slice(0,E-1),...N.slice(E)].join(""),E-1);return}if(R.delete){if(E>=N.length)return;g([...N.slice(0,E),...N.slice(E+1)].join(""),E);return}if(R.ctrl){if(y==="a")h(0);else if(y==="e")h(N.length);else if(y==="k")g(N.slice(0,E).join(""),E);else if(y==="u")g(N.slice(E).join(""),0);else if(y==="w"){let v=E;for(;v>0&&N[v-1]===" ";)v-=1;for(;v>0&&N[v-1]!==" ";)v-=1;g([...N.slice(0,v),...N.slice(E)].join(""),v)}return}if(R.meta||!y)return;let W=y.search(/[\r\n]/),M=kT(W===-1?y:y.slice(0,W)),C=[...N.slice(0,E),M,...N.slice(E)].join("");g(C,E+[...M].length),W!==-1&&n(C)},{isActive:i}),e===""){let y=[...o??""];return i?ul(cn,{children:[yn(ei,{char:y[0]??" "}),yn(cn,{color:f.faintForeground,children:y.slice(1).join("")})]}):yn(cn,{color:f.faintForeground,children:y.join("")})}let x=r?Array.from({length:c.length},()=>"\u2022"):c;if(!i)return yn(cn,{color:f.foreground,children:x.join("")});let{before:T,at:k,after:S}=wp(x,m,p);return ul(cn,{children:[yn(cn,{color:f.foreground,children:T}),yn(ei,{char:k}),yn(cn,{color:f.foreground,children:S})]})}function Oe({label:e}){let[t,n]=kp(0);return wT(()=>{let o=setInterval(()=>n(r=>(r+1)%Qo.length),ks);return()=>clearInterval(o)},[]),ul(cn,{children:[yn(cn,{color:f.accent,children:Qo[t]}),yn(cn,{color:f.mutedForeground,children:` ${e}`})]})}import{Box as Rp,Text as tr}from"ink";import{useEffect as Pp,useState as CT}from"react";import _p from"string-width";import{Box as vp,Text as Cs}from"ink";import vT from"string-width";import{jsx as ti,jsxs as Cp}from"react/jsx-runtime";var ge=2,Bt=1,Ge=1,Xe=Bt+Ge;function Rn({title:e,note:t,width:n}){let o=t===void 0?0:vT(t)+2,r=Math.max(0,n-ge-o);return Cp(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 pe({title:e,note:t,width:n,gap:o=Ge,children:r}){return Cp(vp,{flexDirection:"column",children:[ti(Rn,{title:e,note:t,width:n}),ti(vp,{flexDirection:"column",marginTop:o,paddingLeft:ge,children:r})]})}import{jsx as _n,jsxs as Ep}from"react/jsx-runtime";var yo=e=>!("heading"in e),RT=e=>e.flatMap(t=>!yo(t)&&t.heading!==""?[t,{heading:""}]:[t]),Ap=2,Rs=2,_T=(e,t)=>t===void 0?e:e>t?Math.max(1,t-1):t;function PT(e,t,n,o){let[r,i]=Me(o,()=>e.findIndex(u=>yo(u)&&u.disabled!==!0));Pp(()=>{i(u=>{let m=Math.min(u,e.length-1);for(let p=0;p<e.length;p+=1)for(let d of[m-p,m+p]){let b=e[d];if(b!==void 0&&yo(b)&&b.disabled!==!0)return d}return Math.max(0,m)})},[e.length]);let s=u=>{i(m=>{let p=e.length;if(p===0)return m;let d=m;for(let b=0;b<p;b+=1){d=(d+u+p)%p;let h=e[d];if(h!==void 0&&yo(h)&&h.disabled!==!0)return d}return m})},a=u=>{let m=e[u];return m!==void 0&&yo(m)&&m.disabled!==!0?m:null},c=u=>{a(u)!==null&&i(u)},l=u=>{let m=a(u);m!==null&&(i(u),n(m.value))};return G((u,m)=>{if(m.upArrow||u==="k"){s(-1);return}if(m.downArrow||u==="j"){s(1);return}m.return&&l(r)},t),{index:Math.max(0,r),step:s,pick:l,moveTo:c}}function dl(e,t){let[n,o]=CT(()=>e>=t?e-t+1:0);return Pp(()=>{o(r=>e<r?e:e>=r+t?e-t+1:r)},[e,t]),n}function AT(e,t){let n=e.filter(yo),o=Math.max(0,...n.map(s=>_p(s.label))),r=Math.max(0,...n.map(s=>s.badge===void 0?0:_p(s.badge))),i=Ap+o+(r>0?r+Rs:0)+Rs;return{label:o,badge:r,hint:Math.max(0,t-i)}}function ET({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 Ep(tr,{wrap:"truncate",children:[_n(tr,{color:f.accent,children:t?`${ae.cursor} `:" "}),_n(tr,{color:r,bold:t,children:Je(e.label,n.label)}),n.badge>0&&_n(tr,{color:e.badgeTone===void 0?f.faintForeground:et[e.badgeTone],children:`${" ".repeat(Rs)}${Je(e.badge??"",n.badge)}`}),e.hint!==void 0&&n.hint>0&&_n(tr,{color:o||!t?f.faintForeground:f.mutedForeground,children:`${" ".repeat(Rs)}${qe(e.hint,n.hint)}`})]})}function MT({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 b=m(d);b!==null&&s(b)},onHover:({row:d})=>{let b=m(d);b!==null&&a(b)}});return Ep(Rp,{ref:p,flexDirection:"column",children:[u.map((d,b)=>{let h=l+b;return yo(d)?_n(ET,{item:d,active:h===t&&i,metrics:n},h):d.heading===""?_n(Rp,{height:1},h):_n(Rn,{title:d.heading,width:r},h)}),e.length>o&&_n(tr,{color:f.faintForeground,children:`${" ".repeat(Ap)}${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=RT(e),a=PT(s,r,t,i);return _n(MT,{items:s,cursor:a.index,metrics:AT(s,n),window:_T(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 Mp={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:Vn(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=Mp[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(nr,{children:[Xt(nr,{color:i.color,children:l===0?`${i.glyph} `:a}),Xt(nr,{color:f.foreground,children:c})]},l)),n!==void 0&&s(n).map((c,l)=>Xt(nr,{color:f.faintForeground,children:`${a}${c}`},`detail-${l}`))]})}function Ft({message:e,hint:t,width:n}){return Xt(ye,{tone:"fail",title:e,detail:t,width:n})}var IT=2,NT=2;function Ip({tone:e,message:t,width:n,onDismiss:o}){let r=Mp[e],i=rt({onClick:o});return _s(ni,{ref:i,children:[Xt(nr,{backgroundColor:f.border,color:r.color,wrap:"truncate",children:` ${r.glyph} `}),Xt(nr,{backgroundColor:f.border,color:f.foreground,wrap:"truncate",children:`${qe(t,n-IT-NT)} `})]})}function Ae({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 LT,Text as Ps,useInput as OT}from"ink";import{useRef as DT}from"react";import{jsx as As,jsxs as $T}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=DT(l);if(l!==p.current||u>l){let g=u>=p.current;p.current=l;let x=o&&g?l:Math.min(u,l);x!==u&&m(x)}let d=g=>m(x=>Math.min(Math.max(0,x+g),l));OT((g,x)=>{x.pageUp?d(-c):x.pageDown?d(c):!r&&x.upArrow?d(-1):!r&&x.downArrow&&d(1)},{isActive:n&&a}),G(g=>{g==="k"?d(-1):g==="j"&&d(1)},n&&a&&!r);let b=rt({isActive:n&&a,onWheel:d}),h=e.slice(u,u+c);return $T(LT,{ref:b,flexDirection:"column",children:[h.map((g,x)=>As(Ps,{wrap:"truncate",children:g.spans.length===0?" ":g.spans.map((T,k)=>As(Ps,{color:T.color??f.foreground,bold:T.bold===!0,children:T.text},k))},u+x)),Array.from({length:Math.max(0,c-h.length)},(g,x)=>As(Ps,{children:" "},x)),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 BT,useState as Np}from"react";function ue(){let e=O(),[t,n]=Np(null),[o,r]=Np(null),i=BT(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 b={message:Se(d),hint:d instanceof F?d.hint:void 0};m.failToast===!0?e.toast("fail",b.message):r(b)})},[e]);return{busy:t,error:o,reset:s,fail:a,run:c}}import{Box as ir}from"ink";import{Box as FT,Text as Lp}from"ink";import Dp from"string-width";import{jsx as Op,jsxs as UT}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"],$p=Math.max(...Es.map(e=>Dp(e))),Ms=Es.length,Is=e=>$p<=e;function Ns({width:e}){let t=`v${Vt}`,n=$p+2+Dp(t)<=e;return Op(FT,{flexDirection:"column",children:Es.map((o,r)=>UT(Lp,{color:f.accent,children:[o,r===Es.length-1&&n&&Op(Lp,{color:f.faintForeground,children:` ${t}`})]},o))})}import{Box as Sl,Text as vt}from"ink";import{useState as Bp}from"react";import bo from"string-width";import{jsx as Qt,jsxs as rr}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+bo(d)+bo(yl),0),a=s+bo(r)<=t,c=a?s:0,[l,u]=Bp(!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?rr(vt,{children:[i.map((p,d)=>rr(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,or=2;function Fp({current:e,width:t,onPick:n,isActive:o,unread:r}){let i=Math.max(0,Xr(e)),[s,a]=Bp(null),c=y=>r[y.id]===!0,l=y=>c(y)?`${y.label} ${ae.dot}`:y.label,u=Math.max(...kt.map(y=>bo(y.label))),m=kt.some(c)?bo(` ${ae.dot}`):0,d=(y=>y*u+(y-1)*oi+bl+m)(kt.length)>t,b=d?t-or*2:t,h=d?Math.max(1,Math.floor((b-m+oi-bl)/(u+oi))):kt.length,g=Math.min(Math.max(0,i-Math.floor((h-1)/2)),kt.length-h),x=kt.slice(g,g+h),T=[],k=d?or:0;x.forEach((y,R)=>{R>0&&(k+=oi);let N=bo(l(y))+(y.id===e?bl:0);T.push({id:y.id,from:k,to:k+N}),k+=N});let S=rt({isActive:o,onHover:({column:y})=>{let R=T.find(N=>y>=N.from&&y<N.to);a(R?.id??null)},onHoverLeave:()=>a(null),onClick:({column:y})=>{let R=T.find(E=>y>=E.from&&y<E.to);if(R!==void 0){n(R.id);return}if(!d||y>=or&&y<k)return;let N=y<or?kt[g-1]:kt[g+h];N!==void 0&&n(N.id)}});return Qt(Sl,{ref:S,marginBottom:1,children:rr(vt,{wrap:"truncate",children:[d&&Qt(vt,{color:f.border,children:g>0?`${ae.prev} `:" ".repeat(or)}),x.map((y,R)=>{let N=c(y)&&Qt(vt,{color:f.danger,children:` ${ae.dot}`});return rr(vt,{children:[R>0&&" ".repeat(oi),y.id===e?rr(vt,{backgroundColor:f.foreground,color:f.background,bold:!0,children:[` ${y.label}`,N," "]}):rr(vt,{children:[Qt(vt,{color:o&&y.id===s?f.foreground:f.mutedForeground,children:y.label}),N]})]},y.id)}),d&&Qt(vt,{color:f.border,children:g+h<kt.length?` ${ae.next}`:" ".repeat(or)})]})})}var jT=2;function Up(e,t){let n=[];for(let o of e){let r=n[n.length-1];if(r!==void 0&&bo(_e([...r,o]))<=t)r.push(o);else if(n.length<jT)n.push([o]);else break}return n.map(_e)}function jp({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 HT,useCallback as qT,useContext as GT,useEffect as Wp,useMemo as zT,useRef as Vp,useState as WT}from"react";var Hp=e=>A(mt(rd),Ue("/inbox",{...e})),qp=()=>A(id,"/inbox/unread"),Gp=e=>A(se,`/inbox/${e}/read`,{method:"POST"}),zp=()=>A(se,"/inbox/read-all",{method:"POST"});import{jsx as KT}from"react/jsx-runtime";var VT=6e4,Kp=HT(null);function Yp({children:e}){let{revision:t,toast:n}=O(),[o,r]=WT(!1),i=Vp(0),s=Vp(!1),a=qT(()=>{let l=i.current+=1;if(wt().session===null){r(!1);return}qp().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]);Wp(a,[t,a]),Wp(()=>{let l=setInterval(a,VT);return()=>clearInterval(l)},[a]);let c=zT(()=>({any:o,refresh:a}),[o,a]);return KT(Kp.Provider,{value:c,children:e})}function Ds(){let e=GT(Kp);if(!e)throw new Error("useUnread \u5FC5\u987B\u5728 UnreadProvider \u5185\u4F7F\u7528");return e}import{Fragment as JT,jsx as Ct,jsxs as Qp}from"react/jsx-runtime";var Jp=3,YT=8;function ri(e){let{rows:t}=j();return Math.max(1,t-Zc-Jp-e)}function Xp(){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-Jp),s=Ms+X,a=r!==null&&Is(t)&&i-Ls-s>=YT;return{tab:r,mark:a,rows:a?Ls+s:Ls}}var Z=()=>ri(Xp().rows);function So({header:e,hints:t,children:n}){let{width:o}=j(),{message:r,dismissToast:i}=O(),s=Up(t,o);return Qp(ir,{flexDirection:"column",flexGrow:1,children:[Ct(ir,{flexDirection:"column",flexShrink:0,children:e}),Ct(ir,{flexDirection:"column",flexGrow:1,overflow:"hidden",children:Ct(ir,{flexDirection:"column",flexShrink:0,children:n})}),Ct(ir,{height:1,marginTop:s.length>1?0:1,flexShrink:0,justifyContent:"flex-end",children:r!==null&&Ct(Ip,{tone:r.tone,message:r.message,width:o,onDismiss:i})}),Ct(jp,{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}=Xp(),m=Ds(),p=hs(),d=ys(),b=op(),h=r&&!b,g=h?t:t.filter(y=>y!=="Esc \u8FD4\u56DE"),x=d||p?[]:[...r?["[] \u5207\u529F\u80FD"]:[],"q \u9000\u51FA","? \u5E2E\u52A9"],T=[...h?["Esc \u8FD4\u56DE"]:[],...d||p?[]:["? \u5E2E\u52A9"]];gn(o??a.pop,{isActive:r});let k=rp(),S=r&&!i&&!p;return G(y=>{if(l===null||y!=="["&&y!=="]")return;let R=kt[(Xr(l)+(y==="["?-1:1)+kt.length)%kt.length];R!==void 0&&a.select(R.id)},r&&!i&&!p&&!s),s?Ct(So,{header:null,hints:i?g:[...g,...T],children:n}):l!==null?Ct(So,{header:Qp(JT,{children:[u&&Ct(ir,{marginBottom:X,children:Ct(Ns,{width:c})}),Ct(Fp,{current:l,width:c,onPick:y=>{y===l?k():a.select(y)},isActive:S,unread:{inbox:m.any}})]}),hints:i?g:[...g,...x],children:n}):Ct(So,{header:Ct(Os,{trail:["CodeFlow",...e??[]],width:c,onBack:k,isActive:S}),hints:i?g:[...g,...T],children:n})}function V({state:e,loading:t,width:n,children:o}){return e.phase==="loading"?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 Zp({params:e}){let t=O(),{width:n}=j(),o=Z(),{item:r}=e,{busy:i,error:s,run:a}=ue();XT((m,p)=>{p.return&&a("\u6B63\u5728\u786E\u8BA4",()=>ms(r.id),{onSuccess:()=>t.pop()})},{isActive:i===null});let c=zr(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(xo,{wrap:"truncate",children:[Zt(xo,{bold:!0,color:f.foreground,children:r.title}),Zt(xo,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),Zt(xo,{color:f.faintForeground,children:` \u53D1\u5E03\u4E8E ${K(r.publishedAt)}`})]}),Zt($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(xo,{wrap:"truncate",children:[Zt(xo,{color:f.accent,children:`${ae.cursor} `}),Zt(xo,{bold:!0,color:f.accent,children:"\u6211\u77E5\u9053\u4E86"})]})})]})})}import{Box as Rl,Text as Bs}from"ink";import{useState as cw}from"react";import{Box as Tl,Text as Pn}from"ink";import{useEffect as wl,useRef as QT,useState as ef}from"react";import kl from"string-width";import{jsx as Yn,jsxs as si}from"react/jsx-runtime";var tf=e=>e===void 0?"":typeof e=="string"?e:e.text,vl=2,ZT=6;function ew(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 ew(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)>ZT).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 tw=(e,t,n)=>t.map((o,r)=>o.align==="right"?Kn(e[r]??"",n[r]??0):Je(e[r]??"",n[r]??0)).join(" ".repeat(vl)),ii=2,nw=2;function de({items:e,columns:t,row:n,width:o,height:r,onOpen:i,searchOf:s,isActive:a=!0,emptyLabel:c="\u6682\u65E0\u6570\u636E",emptyDescription:l,retain:u,select:m}){let p=$=>u===void 0?void 0:`${u}:${$}`,d=i!==void 0,[b,h]=Me(d?p("cursor"):void 0,()=>0),[g,x]=Me(p("query"),()=>""),[T,k]=ef(!1),S=g.trim().toLowerCase(),y=S===""||s===void 0?e:e.filter($=>s($).toLowerCase().includes(S)),R=T||S!=="",N=Math.max(1,r-1-(R?1:0)),E=y.length>N?Math.max(1,N-1):N,W=Math.max(0,y.length-E),[M,C]=ef(()=>b>=E?b-E+1:0);wl(()=>{h($=>Math.min($,Math.max(0,y.length-1)))},[y.length]);let v=m===void 0?-1:y.findIndex(m);wl(()=>{v>=0&&h(v)},[v]),wl(()=>{C($=>d?b<$?b:b>=$+E?b-E+1:$:Math.min($,W))},[b,E,W,d]);let _=$=>{if(!d){C(ne=>Math.min(Math.max(0,ne+$),W));return}y.length!==0&&h(ne=>(ne+$+y.length)%y.length)};G(($,ne)=>{if(ne.upArrow||$==="k"){_(-1);return}if(ne.downArrow||$==="j"){_(1);return}if(ne.return){let w=y[b];w!==void 0&&i?.(w,b);return}s!==void 0&&$.startsWith("/")&&(k(!0),$.length>1&&x($.slice(1)))},a&&!T),gn(()=>{k(!1),x("")},{isActive:T||S!=="",layer:T?Wn.input:Wn.panel});let L=R?1:0,P=QT(null),B=$=>{if($<=L)return null;let ne=M+$-L-1;return y[ne]===void 0?null:ne},J=rt({isActive:a,onWheel:_,onClick:({row:$,column:ne})=>{if(R&&$===0){k(!0),P.current?.moveToColumn(ne-nw);return}if(i===void 0)return;let w=B($);if(w===null)return;let U=y[w];U!==void 0&&(h(w),i(U,w))},onHover:d?({row:$})=>{let ne=B($);ne!==null&&h(ne)}:void 0}),oe=Cl(t,y.map($=>n($).map(tf)),o-ii),fe=y.slice(M,M+E);return si(Tl,{ref:J,flexDirection:"column",children:[R&&si(Tl,{children:[Yn(Pn,{color:f.accent,children:"/ "}),Yn(er,{ref:P,value:g,onChange:x,onSubmit:()=>k(!1),isActive:T,placeholder:"\u8F93\u5165\u5173\u952E\u8BCD\u8FC7\u6EE4",width:o-2-kl(` ${y.length}/${e.length}`)}),Yn(Pn,{color:f.faintForeground,children:` ${y.length}/${e.length}`})]}),si(Pn,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(ii),tw(t.map($=>$.label),t,oe)]}),y.length===0?si(Tl,{flexDirection:"column",children:[Yn(Pn,{wrap:"truncate",color:f.mutedForeground,children:`${" ".repeat(ii)}${S===""?c:"\u65E0\u5339\u914D\u7ED3\u679C"}`}),l!==void 0&&S===""&&N>1&&Yn(Pn,{wrap:"truncate",color:f.faintForeground,children:`${" ".repeat(ii)}${l}`})]}):fe.map(($,ne)=>{let w=M+ne,U=d&&w===b&&a,re=U?f.accent:a?f.foreground:f.mutedForeground,D=n($);return si(Pn,{wrap:"truncate",children:[Yn(Pn,{color:f.accent,children:U?`${ae.cursor} `:" "}),t.map((z,ee)=>{let he=D[ee],ie=tf(he),Qe=z.align==="right"?Kn(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 Yn(Pn,{color:Ze,bold:U,children:ee>0?`${" ".repeat(vl)}${Qe}`:Qe},z.label)})]},w)}),(M>0||M+E<y.length)&&Yn(Pn,{color:f.faintForeground,children:`${" ".repeat(ii)}${M+1}-${Math.min(M+E,y.length)} / ${y.length}`})]})}import{Text as ow}from"ink";import{useEffect as rw,useRef as iw,useState as sw}from"react";import{jsx as aw}from"react/jsx-runtime";function ze(e,t,{retain:n}={}){let[o,r]=Me(n,()=>1),[i,s]=sw({pages:1,total:0}),a=iw(!1),c=Q([...e,o],()=>t(o));rw(()=>{if(c.phase!=="ready")return;let p=Math.max(1,Math.ceil(c.data.total/ru));if(s({pages:p,total:c.data.total}),o>p){r(p);return}a.current&&(a.current=!1,o<p&&r(p))},[c]);let l=p=>{r(d=>Math.min(Math.max(1,d+p),i.pages))},u=()=>r(1),m=()=>{a.current=!0};return{state:c,page:o,pages:i.pages,total:i.total,go:l,reset:u,last:m}}function We({page:e,pages:t,total:n,width:o}){return aw(ow,{wrap:"truncate",color:f.faintForeground,children:qe(_e([`\u7B2C ${e} / ${t} \u9875`,`\u5171 ${n} \u6761`,"\u2190\u2192 \u7FFB\u9875"]),o)})}import{jsx as An,jsxs as _l}from"react/jsx-runtime";function nf(){let e=O(),{width:t}=j(),n=Z(),[o,r]=cw({name:"list"}),i=ze([e.revision],a=>Vd({page:a}),{retain:"page"});G((a,c)=>{o.name==="list"&&(a==="r"?e.reload():c.leftArrow?i.go(-1):c.rightArrow&&i.go(1))});let s=()=>{o.name==="list"?e.pop():r({name:"list"})};return An(Y,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"]:["\u2191\u2193 \u6EDA\u52A8","Esc \u8FD4\u56DE"],onEscape:s,children:An(V,{state:i.state,loading:"\u6B63\u5728\u8BFB\u53D6\u516C\u544A",width:t,children:a=>{if(o.name==="detail"){let c=zr(o.item.level),l=yt(c);return _l(Rl,{flexDirection:"column",children:[_l(Bs,{wrap:"truncate",children:[An(Bs,{bold:!0,color:f.foreground,children:o.item.title}),An(Bs,{color:l===void 0?f.mutedForeground:et[l],children:` ${c.label}`}),An(Bs,{color:f.faintForeground,children:` ${_e([`\u53D1\u5E03\u4E8E ${K(o.item.publishedAt)}`])}`})]}),An(Rl,{marginTop:1,children:An(pt,{lines:hn(o.item.content,t),height:Math.max(3,n-2)})})]})}return _l(Rl,{flexDirection:"column",children:[An(de,{retain:"list",items:a.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},{label:"\u7EA7\u522B"},{label:"\u53D1\u5E03\u4E8E",align:"right"}],row:c=>[c.title,bt(zr(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"}),An(We,{page:i.page,pages:i.pages,total:i.total,width:t})]})}})})}import{Box as at,Text as gi}from"ink";import{useState as vg}from"react";import ck from"string-width";import{z as lw}from"zod";var Fs=e=>`/community/${e.kind==="user"?"users":"staff"}/${encodeURIComponent(e.username)}`,Us=()=>A(lw.array(_c),"/community/categories"),sr=()=>A(Zu,"/community/me"),of=e=>A(mt(Pc),Ue("/community/posts",{...e})),js=e=>A(Ac,`/community/posts/${e}`),rf=e=>A(se,`/community/posts/${e}/view`,{method:"POST"}),sf=(e,t)=>A(mt(zi),Ue(`/community/posts/${e}/floors`,{page:t})),af=(e,t)=>A(zi,`/community/posts/${e}/floors/${t}`),cf=(e,t)=>A(mt(Ec),Ue(`/community/comments/${e}/replies`,{page:t})),Pl=e=>A(td,Fs({kind:"user",username:e})),lf=e=>e.kind==="user"?Pl(e.username):A(nd,Fs(e)),mf=(e,t)=>A(mt(Fr),Ue(`${Fs(e)}/posts`,{page:t})),uf=(e,t)=>A(mt(Wi),Ue(`${Fs(e)}/comments`,{page:t})),df=e=>A(mt(Pc),Ue("/community/mine/bookmarks",{page:e})),pf=e=>A(mt(Nc),Ue("/community/mine/drafts",{page:e})),ff=()=>A(Xu,"/community/mine/todo"),gf=e=>A(Yu,"/community/posts",{method:"POST",json:e}),hf=(e,t)=>A(se,`/community/posts/${e}`,{method:"PATCH",json:t}),Hs=e=>A(se,`/community/posts/${e}`,{method:"DELETE"}),yf=e=>A(Qu,"/community/drafts",{method:"POST",json:e}),bf=(e,t)=>A(se,`/community/drafts/${e}`,{method:"PATCH",json:t}),Sf=(e,t)=>A(se,`/community/drafts/${e}/publish`,{method:"POST",json:t}),xf=(e,t)=>A(Ju,`/community/posts/${e}/comments`,{method:"POST",json:t}),Tf=e=>A(se,`/community/comments/${e}`,{method:"DELETE"}),wf=(e,t)=>A(Mc,`/community/posts/${e}/like`,{method:t?"PUT":"DELETE"}),kf=(e,t)=>A(Mc,`/community/comments/${e}/like`,{method:t?"PUT":"DELETE"}),vf=(e,t)=>A(se,`/community/posts/${e}/bookmark`,{method:t?"PUT":"DELETE"}),Cf=(e,t)=>A(se,`/community/posts/${e}/reports`,{method:"POST",json:t}),Rf=(e,t)=>A(se,`/community/comments/${e}/reports`,{method:"POST",json:t});var En=()=>A(lu,"/auth/me"),_f=e=>A(se,"/auth/me",{method:"PATCH",json:e}),Pf=e=>A(se,"/auth/me/password",{method:"POST",json:e}),Af=e=>A(se,"/auth/me/email/code",{method:"POST",json:e}),Ef=e=>A(se,"/auth/me/email",{method:"POST",json:e}),Mf=()=>A(mu,"/auth/me/sessions"),If=e=>A(se,`/auth/me/sessions/${e}`,{method:"DELETE"});async function Nf(){await A(se,"/auth/me/sessions",{method:"DELETE"}),ss()}var Lf=()=>A(du,"/auth/me/security"),Al=e=>A(uu,"/auth/me/totp/setup",{method:"POST",json:e}),Of=e=>A(pc,"/auth/me/totp/confirm",{method:"POST",json:e}),Df=e=>A(se,"/auth/me/totp/disable",{method:"POST",json:e}),$f=e=>A(pc,"/auth/me/totp/recovery-codes",{method:"POST",json:e}),Bf=(e,t)=>A(se,`/auth/me/passkeys/${e}`,{method:"PATCH",json:t}),Ff=e=>A(se,`/auth/me/passkeys/${e}`,{method:"DELETE"});var El=12e4,mw=e=>A(qu,Ue("/media",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:El}),uw=e=>A(se,`/media/${e}`,{method:"DELETE"}),ai={upload:async e=>({...await mw(e),fileName:e.fileName}),discard:uw};async function Uf(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 jf=()=>A(Ic,"/auth/me/avatar"),Hf=e=>A(Ic,"/auth/me/avatar",{method:"PUT",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:El}),qf=()=>A(se,"/auth/me/avatar",{method:"DELETE"});import{existsSync as qs,readFileSync as dw,statSync as Gf,writeFileSync as pw}from"fs";import{homedir as Ml}from"os";import en from"path";var fw={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif"},zf=e=>e.startsWith("~/")?en.join(Ml(),e.slice(2)):e;function gw(e){return e.split(`
10
+ `).map(t=>t.trim()).filter(t=>t!=="").map(zf)}function Wf(e,t,n){if(!qs(e))throw new F(`${e} \u4E0D\u5B58\u5728`);let o=Gf(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 ${Ko(t)}`);let r=en.basename(e);return{filePath:e,fileName:r,contentType:fw[en.extname(r).toLowerCase()]??"application/octet-stream"}}function Vf(e){let t;try{t=dw(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 Jn(e,t){let n=gw(e);if(n.length>t.maxCount)throw new F("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return n.map(o=>Wf(o,t.maxBytes,"\u9644\u4EF6"))}function Kf(e,t){let n=Wf(zf(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 Vf(n)}async function Mn(e,t,n){let o=[];try{for(let r of e)o.push(await t.upload(Vf(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 hw(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;qs(i);s+=1)i=en.join(e,`${r}-${s}${o}`);return i}function yw(e,t){let n=e.trim();if(n==="")return{dir:process.cwd(),fileName:t};if(n==="~")return{dir:Ml(),fileName:t};let o=n.startsWith("~/")||n.startsWith(`~${en.sep}`)?en.join(Ml(),n.slice(2)):n;return n.endsWith("/")||n.endsWith(en.sep)||qs(o)&&Gf(o).isDirectory()?{dir:o,fileName:t}:{dir:en.dirname(o),fileName:en.basename(o)}}function Yf(e,t,n){let o=yw(e,t);if(!qs(o.dir))throw new F(`${o.dir} \u76EE\u5F55\u4E0D\u5B58\u5728`);let r=hw(o.dir,o.fileName);try{pw(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 og,Text as Fe,useInput as lg}from"ink";import{useEffect as rg,useRef as ig,useState as ar}from"react";import Ol from"string-width";import{Box as bw,Text as Xn,useInput as Sw}from"ink";import{useRef as Jf,useState as Xf}from"react";import Nl from"string-width";import{jsx as In,jsxs as tg}from"react/jsx-runtime";var xw=e=>e.replace(/\r\n?/g,`
11
+ `).replace(new RegExp("(?!\\n)\\p{Cc}","gu"),"");function Qf(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=Nl(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 Zf(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 eg(e,t,n){let o=0;for(let r=t.start;r<t.end;r+=1){let i=Nl(e[r]??"");if(o+i>n)return r;o+=i}return t.end}var Tw=(e,t,n)=>e.slice(t.start,n).reduce((o,r)=>o+Nl(r),0);function Il(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 Qf({value:e,onChange:t,isActive:n,width:o,rows:r,placeholder:i,maxLength:s,onEdge:a,onFocusRequest:c}){let l=[...e],[u,m]=Vf(l.length),p=Math.min(u,l.length),[d,b]=Vf(0),h=Wf(e),g=Wf(p);h.current=e,g.current=p,ms(n);let x=Math.max(4,o),T=C=>{g.current=C,m(C)},k=(C,v)=>{h.current=C,T(v),t(C)},S=C=>{let v=[...h.current],_=Math.min(g.current,v.length),L=Kf(v,x),P=Yf(L,_),B=L[P],J=L[P+C];return B===void 0||J===void 0?!1:(T(Jf(v,J,fw(v,B,_))),!0)},y=(C,v,_)=>{let L=pw(_);if(s!==void 0){let P=s-C.length;if(P<=0)return;L=[...L].slice(0,P).join("")}L!==""&&k([...C.slice(0,v),L,...C.slice(v)].join(""),v+[...L].length)};dw((C,v)=>{let _=[...h.current],L=Math.min(g.current,_.length);if(v.return){y(_,L,`
15
- `);return}if(!v.tab){if(v.upArrow||v.downArrow){let P=v.upArrow?-1:1;S(P)||a?.(v.upArrow?"up":"down");return}if(v.leftArrow){T(Math.max(0,L-1));return}if(v.rightArrow){T(Math.min(_.length,L+1));return}if(v.home){T(Pl(_,L).start);return}if(v.end){T(Pl(_,L).end);return}if(v.backspace){if(L===0)return;k([..._.slice(0,L-1),..._.slice(L)].join(""),L-1);return}if(v.delete){if(L>=_.length)return;k([..._.slice(0,L),..._.slice(L+1)].join(""),L);return}if(v.ctrl){let P=Pl(_,L);if(C==="a")T(P.start);else if(C==="e")T(P.end);else if(C==="k")k([..._.slice(0,L),..._.slice(P.end)].join(""),L);else if(C==="u")k([..._.slice(0,P.start),..._.slice(L)].join(""),P.start);else if(C==="w"){let B=L;for(;B>P.start&&_[B-1]===" ";)B-=1;for(;B>P.start&&_[B-1]!==" ";)B-=1;k([..._.slice(0,B),..._.slice(L)].join(""),B)}return}v.meta||!C||y(_,L,C)}},{isActive:n});let R=Kf(l,x),N=Yf(R,p),E=Math.min(d,Math.max(0,R.length-r));N<E&&(E=N),N>E+r-1&&(E=N-r+1),E!==d&&b(E);let W=[];for(let C=0;C<r;C+=1){let v=E+C,_=R[v];if(_===void 0){W.push(In(Xn,{children:" "},v));continue}let L=l.slice(_.start,_.end).join("");if(!n||v!==N){W.push(In(Xn,{wrap:"truncate",color:f.foreground,children:L===""?" ":L},v));continue}let P=l.slice(_.start,p).join(""),B=p<_.end?l[p]??" ":" ",J=p<_.end?l.slice(p+1,_.end).join(""):"";W.push(Xf(Xn,{wrap:"truncate",children:[In(Xn,{color:f.foreground,children:P}),In(Zr,{char:B}),In(Xn,{color:f.foreground,children:J})]},v))}if(e===""&&i!==void 0){let C=[...i];W[0]=n?Xf(Xn,{wrap:"truncate",children:[In(Zr,{char:C[0]??" "}),In(Xn,{color:f.faintForeground,children:C.slice(1).join("")})]},"placeholder"):In(Xn,{wrap:"truncate",color:f.faintForeground,children:i},"placeholder")}let M=rt({onWheel:C=>{S(C)},onClick:({row:C,column:v})=>{c?.();let _=R[E+C];T(_===void 0?l.length:Jf(l,_,v))}});return In(uw,{ref:M,flexDirection:"column",children:W})}import{Fragment as rg,jsx as ve,jsxs as At}from"react/jsx-runtime";var gw=e=>Object.fromEntries(e.map(t=>[t.name,"initial"in t?t.initial??"":""])),ng="\u9009\u586B",hw=(e,t)=>e.kind!=="text"&&e.kind!=="textarea"?!1:typeof e.optional=="function"?e.optional(t):e.optional===!0,yw=(e,t)=>{let n=typeof e.hint=="function"?e.hint(t[e.name]??""):e.hint;return hw(e,t)?n===void 0?ng:`${ng} \xB7 ${n}`:n},bw=(e,t)=>{let n=[];return e.forEach((o,r)=>{n.push({type:"field",index:r}),o.kind==="code"&&n.push({type:"send",index:r})}),n.push({type:"submit"}),t!==void 0&&n.push({type:"secondary",action:t}),n},Sw=6e4,xw=4,El=4,Tw=2,ai=(e,t)=>e?f.accent:t?f.foreground:f.mutedForeground;function te({title:e,fields:t,submitLabel:n,onSubmit:o,onCancel:r,onChange:i,secondary:s,width:a,busy:c,busyLabel:l="\u6B63\u5728\u63D0\u4EA4",error:u}){let[m,p]=ar(()=>gw(t)),[d,b]=ar(0),[h,g]=ar({}),[x,T]=ar(null),[,k]=ar(0),S=c===!0,y=bw(t,s),R=y[Math.min(d,y.length-1)],N=R?.type==="field"||R?.type==="send"?t[R.index]:void 0;eg(()=>{i?.(m)},[m]);let E=R?.type==="field"&&(N?.kind==="text"||N?.kind==="code"),W=R?.type==="field"&&N?.kind==="textarea",M=Object.values(h).some(D=>D.phase==="cooldown"&&D.until>Date.now());eg(()=>{if(!M)return;let D=setInterval(()=>k(z=>z+1),1e3);return()=>clearInterval(D)},[M]);let C=D=>b(z=>(z+D+y.length)%y.length),v=(D,z)=>{if(D.options.length===0)return;let ee=D.options.findIndex(ie=>ie.value===m[D.name]),he=D.options[(ee+z+D.options.length)%D.options.length];he!==void 0&&p(ie=>({...ie,[D.name]:he.value}))},_=D=>{R?.type!=="field"||N?.kind!=="select"||v(N,D)},L=D=>{let z=t[D];if(z===void 0||z.kind!=="code")return;let ee=(m[z.emailField]??"").trim();if(ee===""){g(ie=>({...ie,[z.name]:{phase:"error",message:"\u8BF7\u5148\u586B\u5199\u90AE\u7BB1"}}));return}let he=h[z.name];he?.phase!=="sending"&&(he?.phase==="cooldown"&&he.email===ee&&he.until>Date.now()||(g(ie=>({...ie,[z.name]:{phase:"sending"}})),z.send(ee).then(()=>g(ie=>({...ie,[z.name]:{phase:"cooldown",email:ee,until:Date.now()+Sw}}))).catch(ie=>g(Qe=>({...Qe,[z.name]:{phase:"error",message:xe(ie)}})))))};ig((D,z)=>{if(z.tab){C(z.shift?-1:1);return}if(!W){if(z.upArrow){C(-1);return}if(z.downArrow){C(1);return}if(!E){if(z.leftArrow){_(-1);return}if(z.rightArrow){_(1);return}z.return&&(R?.type==="submit"?o(m):R?.type==="secondary"?R.action.onSubmit(m):R?.type==="send"?L(R.index):C(1))}}},{isActive:!S}),gn(()=>{S||r(m)},{layer:Wn.panel}),Qd(S),Re(S);let P=Math.max(0,...t.map(D=>Ml(D.label))),B=a-ge,J=Math.max(8,B-P-8),oe=(D,z)=>y.findIndex(ee=>ee.type===D&&(ee.type==="field"||ee.type==="send"?ee.index===z:!0)),fe=tg(new Map).current,$=tg(new Map).current,ne=2+P+El,w=(D,z)=>{let ee=y[D];if(ee===void 0)return;if(b(D),ee.type==="submit"){o(m);return}if(ee.type==="secondary"){ee.action.onSubmit(m);return}if(ee.type==="send"){L(ee.index);return}let he=t[ee.index];if(he!==void 0){if(he.kind==="select"){let ie=he.options.find(xt=>xt.value===m[he.name]),Qe=He(ie?.label??"\u2014",J);z>=ne-Tw&&z<ne?v(he,-1):z>=ne+Ml(Qe)&&v(he,1);return}z>=ne&&$.get(ee.index)?.moveToColumn(z-ne)}},F=(D,z)=>{if(D===null)return null;let ee=Zf(D),he=null;for(let[ie,Qe]of fe){if(Qe===null)continue;let xt=Zf(Qe),Ze=xt.y-ee.y;z<Ze||z>=Ze+xt.height||(he===null||xt.height<he.box.height)&&(he={index:ie,box:xt})}return he===null?null:{...he,frameX:ee.x}},re=rt({isActive:!S,onClick:({row:D,column:z})=>{let ee=F(re.current,D);ee!==null&&w(ee.index,z-(ee.box.x-ee.frameX))},onHover:({row:D})=>T(F(re.current,D)?.index??null),onHoverLeave:()=>T(null)});return At(tn,{ref:re,flexDirection:"column",children:[ve(Rn,{title:e,width:a}),At(tn,{flexDirection:"column",marginTop:qe,paddingLeft:ge,children:[u!=null&&ve(tn,{marginBottom:1,children:ve(Ft,{message:u.message,hint:u.hint,width:B})}),t.map((D,z)=>{let ee=d===oe("field",z)&&!S,he=yw(D,m),ie=D.kind==="select"?D.options.find(Ze=>Ze.value===m[D.name]):void 0;if(D.kind==="textarea")return At(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",z),Ze)},children:[At(Be,{children:[ve(Be,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Be,{color:ai(ee,x===oe("field",z)),bold:ee,children:D.label})]}),ve(tn,{paddingLeft:2,children:ve(Qf,{value:m[D.name]??"",onChange:Ze=>p(Ha=>({...Ha,[D.name]:Ze})),isActive:ee,width:B-2,rows:D.rows??xw,placeholder:D.placeholder,maxLength:D.maxLength,onEdge:Ze=>C(Ze==="up"?-1:1),onFocusRequest:()=>b(oe("field",z))})}),ee&&he!==void 0&&ve(Be,{color:f.faintForeground,children:` ${He(he,B-2)}`})]},D.name);let Qe=D.kind==="code"&&d===oe("send",z)&&!S,xt=h[D.name];return At(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",z),Ze)},children:[At(Be,{children:[ve(Be,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Be,{color:ai(ee,x===oe("field",z)),bold:ee,children:Je(D.label,P)}),D.kind==="select"?At(rg,{children:[ve(Be,{color:ee?f.accent:f.border,children:` ${ae.prev} `}),ve(Be,{color:f.foreground,children:He(ie?.label??"\u2014",J)}),ve(Be,{color:ee?f.accent:f.border,children:` ${ae.next}`})]}):At(rg,{children:[ve(Be,{children:" ".repeat(El)}),ve(er,{ref:Ze=>{$.set(z,Ze)},value:m[D.name]??"",onChange:Ze=>p(Ha=>({...Ha,[D.name]:Ze})),onSubmit:()=>C(1),isActive:ee,placeholder:D.kind==="text"||D.kind==="code"?D.placeholder:void 0,mask:D.kind==="text"?D.mask:void 0,width:J})]})]}),ee&&he!==void 0&&ve(Be,{color:f.faintForeground,children:`${" ".repeat(2+P+El)}${He(he,J)}`}),D.kind==="code"&&ve(ww,{active:Qe,state:xt,email:(m[D.emailField]??"").trim(),indent:ne,width:J,hovered:x===oe("send",z),nodeRef:Ze=>{fe.set(oe("send",z),Ze)}})]},D.name)}),At(tn,{marginTop:1,flexDirection:"column",children:[ve(tn,{ref:D=>{fe.set(oe("submit"),D)},children:S?ve(Oe,{label:l}):At(Be,{children:[ve(Be,{color:f.accent,children:R?.type==="submit"?`${ae.cursor} `:" "}),ve(Be,{color:ai(R?.type==="submit",x===oe("submit")),bold:R?.type==="submit",children:n})]})}),s!==void 0&&!S&&ve(tn,{ref:D=>{fe.set(oe("secondary"),D)},children:At(Be,{children:[ve(Be,{color:f.accent,children:R?.type==="secondary"?`${ae.cursor} `:" "}),ve(Be,{color:ai(R?.type==="secondary",x===oe("secondary")),bold:R?.type==="secondary",children:s.label})]})})]})]})]})}function ww({active:e,state:t,email:n,indent:o,width:r,hovered:i,nodeRef:s}){if(t?.phase==="sending")return ve(tn,{paddingLeft:o,children:ve(Oe,{label:"\u6B63\u5728\u53D1\u9001\u9A8C\u8BC1\u7801"})});let a=t?.phase==="cooldown"&&t.email===n?Math.ceil((t.until-Date.now())/1e3):0,c=a>0?`${a} \u79D2\u540E\u53EF\u91CD\u53D1`:"\u53D1\u9001\u9A8C\u8BC1\u7801";return At(tn,{ref:s,flexDirection:"column",paddingLeft:o-2,children:[At(Be,{children:[ve(Be,{color:f.accent,children:e?`${ae.cursor} `:" "}),ve(Be,{color:a>0?f.faintForeground:ai(e,i),bold:e&&a===0,children:c})]}),t?.phase==="error"&&ve(Be,{color:f.danger,children:` ${He(t.message,r)}`})]})}var kw=2,og=2;function Fs({options:e,value:t,onChange:n,arrowKeys:o=!0}){let r=e.findIndex(m=>m.value===t),i=ds();ig((m,p)=>{if(!p.leftArrow&&!p.rightArrow)return;let d=p.leftArrow?-1:1,b=e[(r+d+e.length)%e.length];b!==void 0&&n(b.value)},{isActive:o&&!i});let s=[],a=0;e.forEach((m,p)=>{p>0&&(a+=og);let d=Ml(m.label)+kw;s.push({value:m.value,from:a,to:a+d}),a+=d});let[c,l]=ar(null),u=rt({onClick:({column:m})=>{let p=s.find(d=>m>=d.from&&m<d.to);p!==void 0&&n(p.value)},onHover:({column:m})=>{let p=s.find(d=>m>=d.from&&m<d.to);l(p?.value??null)},onHoverLeave:()=>l(null)});return ve(tn,{ref:u,children:ve(Be,{wrap:"truncate",children:e.map((m,p)=>{let d=m.value===t;return At(Be,{children:[p>0&&" ".repeat(og),ve(Be,{backgroundColor:d?f.foreground:f.border,color:d?f.background:m.value===c?f.foreground:f.mutedForeground,bold:d,children:` ${m.label} `})]},m.value)})})})}import{Box as sg,Text as Sn}from"ink";import vw from"string-width";import{jsx as bn,jsxs as Il}from"react/jsx-runtime";var Us=3,Nn=2,To=10,Cw=8,ag=e=>Math.floor((e-Us)/Nn),cr=e=>ag(e)>=Cw;function Rw(e,t){let n=new Map(e.days.map(l=>[l.day,t(l)])),o=[...n.values()].sort((l,u)=>l-u),r=l=>o[Math.floor((o.length-1)*l)]??0,[i,s,a]=[r(.25),r(.5),r(.75)],c=[];for(let l=e.start;l<=e.end;l=Gn(l,1)){let u=n.get(l)??0;c.push({day:l,level:u<=0?0:u<=i?1:u<=s?2:u<=a?3:4})}return c}function _w(e,t){let n=t*Nn,o="",r=0,i="";for(;r<n;){let s=r%Nn===0?e[r/Nn*7]:void 0;if(s!==void 0){let a=s.day.slice(0,7);if(a!==i){i=a;let c=`${Number(s.day.slice(5,7))}\u6708`,l=vw(c);if(r+l<=n){o+=c,r+=l;continue}}}o+=" ",r+=1}return o}var Pw={1:"\u4E00",3:"\u4E09",5:"\u4E94"};function Aw({cells:e,day:t,weeks:n}){return Il(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.faintForeground,children:Je(Pw[t]??"",Us)}),Array.from({length:n},(o,r)=>{let i=e[r*7+t];return i===void 0?bn(Sn,{children:" ".repeat(Nn)},r):bn(Sn,{backgroundColor:hs[i.level],children:" ".repeat(Nn)},r)})]})}function lr({data:e,value:t,caption:n,width:o}){let r=Rw(e,t),i=Math.ceil(r.length/7),s=Math.min(i,ag(o)),a=r.slice((i-s)*7),c=3+hs.length*Nn+3,l=Math.max(0,Us+s*Nn-c-2);return Il(sg,{flexDirection:"column",children:[bn(Sn,{wrap:"truncate",color:f.faintForeground,children:" ".repeat(Us)+_w(a,s)}),Array.from({length:7},(u,m)=>bn(Aw,{cells:a,day:m,weeks:s},m)),bn(sg,{marginTop:1,children:Il(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.mutedForeground,children:Je(n??"",l)})," ",bn(Sn,{color:f.faintForeground,children:"\u5C11 "}),hs.map(u=>bn(Sn,{backgroundColor:u,children:" ".repeat(Nn)},u)),bn(Sn,{color:f.faintForeground,children:" \u591A"})]})})]})}import{Box as Ol,Text as cg}from"ink";import Ew from"qrcode";import{jsx as ci,jsxs as Dw}from"react/jsx-runtime";var Mw="#000000",Iw="#ffffff",Nl=2,mg=2,Dl=1,lg,Ll;function ug(e){if(e===lg&&Ll!==void 0)return Ll;let t=Ew.create(e,{errorCorrectionLevel:"L"}),n=t.modules.size,o=t.modules.data,r=n+Nl*2,i=Array.from({length:r},()=>Array.from({length:r},()=>!1));for(let s=0;s<n;s+=1)for(let a=0;a<n;a+=1){let c=i[s+Nl];c!==void 0&&(c[a+Nl]=o[s*n+a]===1)}return lg=e,Ll=i,i}function Nw(e){let t=ug(e).length;return{columns:t*mg,rows:t}}function js(e,t,n,o){let r=Nw(e),i=t.rows-r.rows-Dl;return r.columns<=t.width&&i>=n.rows?{fits:!0,qr:r,asideWidth:t.width,asideRows:i}:{fits:!1,target:{columns:Math.max(r.columns,n.columns)+o.columns,rows:r.rows+Dl+n.rows+o.rows}}}function Lw(e,t){let n=[],o=0;for(let r=1;r<=e.length;r+=1)r<e.length&&e[r]===e[o]||(n.push(ci(cg,{backgroundColor:e[o]??!1?Mw:Iw,children:" ".repeat((r-o)*mg)},o)),o=r);return ci(cg,{children:n},t)}function Ow({value:e}){return ci(Ol,{flexDirection:"column",flexShrink:0,children:ug(e).map((t,n)=>Lw(t,n))})}function Hs({value:e,aside:t}){return Dw(Ol,{flexDirection:"column",flexShrink:0,children:[ci(Ow,{value:e}),ci(Ol,{marginTop:Dl,flexDirection:"column",children:t})]})}import{Box as qs,Text as Et}from"ink";import dg from"string-width";import{jsx as Mt,jsxs as li}from"react/jsx-runtime";var Gs=2,$l=4,pg=e=>" ".repeat(e),Bl=13,fg=4,gg=(e,t,n)=>Math.max(1,Math.min(e,n,Math.floor((t+Gs)/(Bl+Gs)))),Ut=(e,t,n=fg)=>Math.ceil(e/gg(e,t,n))*2;function it({tiles:e,width:t,maxPerRow:n=fg}){let o=gg(e.length,t,n),r=Math.floor((t-Gs*(o-1))/o),i=[];for(let s=0;s<e.length;s+=o)i.push(e.slice(s,s+o));return Mt(qs,{flexDirection:"column",children:i.map((s,a)=>Mt(qs,{flexDirection:"column",children:["label","value"].map(c=>Mt(Et,{wrap:"truncate",children:s.map((l,u)=>li(Et,{children:[u>0&&pg(Gs),Mt(Et,{color:c==="label"?f.mutedForeground:f.foreground,bold:c==="value",children:Je(l[c],r)})]},l.label))},c))},a))})}function hg({used:e,total:t,width:n=20}){let o=t<=0?1:Math.min(1,e/t),r=Math.round(o*n),i=o>=1?f.danger:o>=.8?f.warning:f.foreground;return li(Et,{children:[Mt(Et,{color:i,children:ae.barFilled.repeat(r)}),Mt(Et,{color:f.border,children:ae.barEmpty.repeat(n-r)})]})}function $w({items:e,width:t}){let n=Math.max(0,...e.map(([r])=>dg(r))),o=Math.max(0,t-n-3);return Mt(qs,{flexDirection:"column",children:e.map(([r,i])=>li(Et,{wrap:"truncate",children:[Mt(Et,{color:f.mutedForeground,children:Je(r,n)})," ",Mt(Et,{color:f.foreground,children:He(i,o)})]},r))})}var zs=(e,t)=>Math.floor((t-$l)/2)<Bl*2?e:Math.ceil(e/2);function Ve({items:e,width:t}){let n=Math.floor((t-$l)/2);if(n<Bl*2)return Mt($w,{items:e,width:t});let o=Math.max(0,...e.map(([a])=>dg(a))),r=n-o-2,i=[];for(let a=0;a<e.length;a+=2)i.push(e.slice(a,a+2));let s=a=>a===void 0?Mt(Et,{children:" ".repeat(n)}):li(Et,{children:[Mt(Et,{color:f.mutedForeground,children:Je(a[0],o)})," ",Mt(Et,{color:f.foreground,children:Je(a[1],r)})]});return Mt(qs,{flexDirection:"column",children:i.map((a,c)=>li(Et,{wrap:"truncate",children:[s(a[0]),pg($l),s(a[1])]},c))})}import{Lexer as Bw}from"marked";var Fw=new RegExp("\\p{Cc}","gu"),Uw=/[\\[\]]/g,jw=/[\\`*_{}[\]()#+\-.!|<>~]/g,Hw=/[\uD800-\uDBFF]$/,qw=400,Gw=12,zw=20,mr={label:"\u677F\u5757",cap:Gw},Qn={label:"\u4F5C\u8005",cap:zw},Ws={maxCount:Bu,maxBytes:Dr},Vs={maxCount:Fu,maxBytes:Dr},st=e=>e.replace(Fw,""),mi=e=>({kind:e.kind,username:e.username});function vt(e){let t=st(e.username);return e.kind==="user"?`${t} Lv.${Hi(e.points).level}`:`${t} [${zi}]`}var Ks=e=>`@${st(e.username)}`,yg=e=>e.flatMap(t=>[{reply:t.reply,mention:t.mention,prefix:""},...bg(t.children,"")]);function bg(e,t){return e.flatMap((n,o)=>{let r=o===e.length-1;return[{reply:n.reply,mention:n.mention,prefix:`${t}${r?"\u2514\u2500 ":"\u251C\u2500 "}`},...bg(n.children,`${t}${r?" ":"\u2502 "}`)]})}var Ln=(e,t)=>e.kind==="user"&&e.username===t,Fl=e=>`${e.image?"[\u56FE\u7247]":"[\u9644\u4EF6]"} ${st(e.name)}`;function jt(e){let t=new Set;return Wu(e).filter(n=>t.has(n.id)?!1:(t.add(n.id),!0))}var Ww=e=>Sc(e,t=>Fl(t).replace(jw,"\\$&")),ui=(e,t)=>hn(Ww(e),t);function wo(e){let t=Sc(e,n=>n.image?"[\u56FE\u7247]":`[\u9644\u4EF6] ${n.name}`).slice(0,qw).replace(Hw,"");return st(gd(Bw.lex(t,{gfm:!0,breaks:!0}))).trim()}var Vw=e=>st(e).trim().replace(Uw,"\\$&");function di(e,t){if(t.length===0)return e;let n=t.map(o=>`${o.image===null?"":"!"}[${Vw(o.fileName)}](${Uu(o.id)})`).join(`
14
+ `;)o+=1;return{start:n,end:o}}function ng({value:e,onChange:t,isActive:n,width:o,rows:r,placeholder:i,maxLength:s,onEdge:a,onFocusRequest:c}){let l=[...e],[u,m]=Xf(l.length),p=Math.min(u,l.length),[d,b]=Xf(0),h=Jf(e),g=Jf(p);h.current=e,g.current=p,gs(n);let x=Math.max(4,o),T=C=>{g.current=C,m(C)},k=(C,v)=>{h.current=C,T(v),t(C)},S=C=>{let v=[...h.current],_=Math.min(g.current,v.length),L=Qf(v,x),P=Zf(L,_),B=L[P],J=L[P+C];return B===void 0||J===void 0?!1:(T(eg(v,J,Tw(v,B,_))),!0)},y=(C,v,_)=>{let L=xw(_);if(s!==void 0){let P=s-C.length;if(P<=0)return;L=[...L].slice(0,P).join("")}L!==""&&k([...C.slice(0,v),L,...C.slice(v)].join(""),v+[...L].length)};Sw((C,v)=>{let _=[...h.current],L=Math.min(g.current,_.length);if(v.return){y(_,L,`
15
+ `);return}if(!v.tab){if(v.upArrow||v.downArrow){let P=v.upArrow?-1:1;S(P)||a?.(v.upArrow?"up":"down");return}if(v.leftArrow){T(Math.max(0,L-1));return}if(v.rightArrow){T(Math.min(_.length,L+1));return}if(v.home){T(Il(_,L).start);return}if(v.end){T(Il(_,L).end);return}if(v.backspace){if(L===0)return;k([..._.slice(0,L-1),..._.slice(L)].join(""),L-1);return}if(v.delete){if(L>=_.length)return;k([..._.slice(0,L),..._.slice(L+1)].join(""),L);return}if(v.ctrl){let P=Il(_,L);if(C==="a")T(P.start);else if(C==="e")T(P.end);else if(C==="k")k([..._.slice(0,L),..._.slice(P.end)].join(""),L);else if(C==="u")k([..._.slice(0,P.start),..._.slice(L)].join(""),P.start);else if(C==="w"){let B=L;for(;B>P.start&&_[B-1]===" ";)B-=1;for(;B>P.start&&_[B-1]!==" ";)B-=1;k([..._.slice(0,B),..._.slice(L)].join(""),B)}return}v.meta||!C||y(_,L,C)}},{isActive:n});let R=Qf(l,x),N=Zf(R,p),E=Math.min(d,Math.max(0,R.length-r));N<E&&(E=N),N>E+r-1&&(E=N-r+1),E!==d&&b(E);let W=[];for(let C=0;C<r;C+=1){let v=E+C,_=R[v];if(_===void 0){W.push(In(Xn,{children:" "},v));continue}let L=l.slice(_.start,_.end).join("");if(!n||v!==N){W.push(In(Xn,{wrap:"truncate",color:f.foreground,children:L===""?" ":L},v));continue}let P=l.slice(_.start,p).join(""),B=p<_.end?l[p]??" ":" ",J=p<_.end?l.slice(p+1,_.end).join(""):"";W.push(tg(Xn,{wrap:"truncate",children:[In(Xn,{color:f.foreground,children:P}),In(ei,{char:B}),In(Xn,{color:f.foreground,children:J})]},v))}if(e===""&&i!==void 0){let C=[...i];W[0]=n?tg(Xn,{wrap:"truncate",children:[In(ei,{char:C[0]??" "}),In(Xn,{color:f.faintForeground,children:C.slice(1).join("")})]},"placeholder"):In(Xn,{wrap:"truncate",color:f.faintForeground,children:i},"placeholder")}let M=rt({onWheel:C=>{S(C)},onClick:({row:C,column:v})=>{c?.();let _=R[E+C];T(_===void 0?l.length:eg(l,_,v))}});return In(bw,{ref:M,flexDirection:"column",children:W})}import{Fragment as cg,jsx as ve,jsxs as Et}from"react/jsx-runtime";var ww=e=>Object.fromEntries(e.map(t=>[t.name,"initial"in t?t.initial??"":""])),sg="\u9009\u586B",kw=(e,t)=>e.kind!=="text"&&e.kind!=="textarea"?!1:typeof e.optional=="function"?e.optional(t):e.optional===!0,vw=(e,t)=>{let n=typeof e.hint=="function"?e.hint(t[e.name]??""):e.hint;return kw(e,t)?n===void 0?sg:`${sg} \xB7 ${n}`:n},Cw=(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},Rw=6e4,_w=4,Ll=4,Pw=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]=ar(()=>ww(t)),[d,b]=ar(0),[h,g]=ar({}),[x,T]=ar(null),[,k]=ar(0),S=c===!0,y=Cw(t,s),R=y[Math.min(d,y.length-1)],N=R?.type==="field"||R?.type==="send"?t[R.index]:void 0;rg(()=>{i?.(m)},[m]);let E=R?.type==="field"&&(N?.kind==="text"||N?.kind==="code"),W=R?.type==="field"&&N?.kind==="textarea",M=Object.values(h).some(D=>D.phase==="cooldown"&&D.until>Date.now());rg(()=>{if(!M)return;let D=setInterval(()=>k(z=>z+1),1e3);return()=>clearInterval(D)},[M]);let C=D=>b(z=>(z+D+y.length)%y.length),v=(D,z)=>{if(D.options.length===0)return;let ee=D.options.findIndex(ie=>ie.value===m[D.name]),he=D.options[(ee+z+D.options.length)%D.options.length];he!==void 0&&p(ie=>({...ie,[D.name]:he.value}))},_=D=>{R?.type!=="field"||N?.kind!=="select"||v(N,D)},L=D=>{let z=t[D];if(z===void 0||z.kind!=="code")return;let ee=(m[z.emailField]??"").trim();if(ee===""){g(ie=>({...ie,[z.name]:{phase:"error",message:"\u8BF7\u5148\u586B\u5199\u90AE\u7BB1"}}));return}let he=h[z.name];he?.phase!=="sending"&&(he?.phase==="cooldown"&&he.email===ee&&he.until>Date.now()||(g(ie=>({...ie,[z.name]:{phase:"sending"}})),z.send(ee).then(()=>g(ie=>({...ie,[z.name]:{phase:"cooldown",email:ee,until:Date.now()+Rw}}))).catch(ie=>g(Qe=>({...Qe,[z.name]:{phase:"error",message:Se(ie)}})))))};lg((D,z)=>{if(z.tab){C(z.shift?-1:1);return}if(!W){if(z.upArrow){C(-1);return}if(z.downArrow){C(1);return}if(!E){if(z.leftArrow){_(-1);return}if(z.rightArrow){_(1);return}z.return&&(R?.type==="submit"?o(m):R?.type==="secondary"?R.action.onSubmit(m):R?.type==="send"?L(R.index):C(1))}}},{isActive:!S}),gn(()=>{S||r(m)},{layer:Wn.panel}),np(S),Re(S);let P=Math.max(0,...t.map(D=>Ol(D.label))),B=a-ge,J=Math.max(8,B-P-8),oe=(D,z)=>y.findIndex(ee=>ee.type===D&&(ee.type==="field"||ee.type==="send"?ee.index===z:!0)),fe=ig(new Map).current,$=ig(new Map).current,ne=2+P+Ll,w=(D,z)=>{let ee=y[D];if(ee===void 0)return;if(b(D),ee.type==="submit"){o(m);return}if(ee.type==="secondary"){ee.action.onSubmit(m);return}if(ee.type==="send"){L(ee.index);return}let he=t[ee.index];if(he!==void 0){if(he.kind==="select"){let ie=he.options.find(Tt=>Tt.value===m[he.name]),Qe=qe(ie?.label??"\u2014",J);z>=ne-Pw&&z<ne?v(he,-1):z>=ne+Ol(Qe)&&v(he,1);return}z>=ne&&$.get(ee.index)?.moveToColumn(z-ne)}},U=(D,z)=>{if(D===null)return null;let ee=og(D),he=null;for(let[ie,Qe]of fe){if(Qe===null)continue;let Tt=og(Qe),Ze=Tt.y-ee.y;z<Ze||z>=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:!S,onClick:({row:D,column:z})=>{let ee=U(re.current,D);ee!==null&&w(ee.index,z-(ee.box.x-ee.frameX))},onHover:({row:D})=>T(U(re.current,D)?.index??null),onHoverLeave:()=>T(null)});return Et(tn,{ref:re,flexDirection:"column",children:[ve(Rn,{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,z)=>{let ee=d===oe("field",z)&&!S,he=vw(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",z),Ze)},children:[Et(Fe,{children:[ve(Fe,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Fe,{color:ci(ee,x===oe("field",z)),bold:ee,children:D.label})]}),ve(tn,{paddingLeft:2,children:ve(ng,{value:m[D.name]??"",onChange:Ze=>p(Va=>({...Va,[D.name]:Ze})),isActive:ee,width:B-2,rows:D.rows??_w,placeholder:D.placeholder,maxLength:D.maxLength,onEdge:Ze=>C(Ze==="up"?-1:1),onFocusRequest:()=>b(oe("field",z))})}),ee&&he!==void 0&&ve(Fe,{color:f.faintForeground,children:` ${qe(he,B-2)}`})]},D.name);let Qe=D.kind==="code"&&d===oe("send",z)&&!S,Tt=h[D.name];return Et(tn,{flexDirection:"column",ref:Ze=>{fe.set(oe("field",z),Ze)},children:[Et(Fe,{children:[ve(Fe,{color:f.accent,children:ee?`${ae.cursor} `:" "}),ve(Fe,{color:ci(ee,x===oe("field",z)),bold:ee,children:Je(D.label,P)}),D.kind==="select"?Et(cg,{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(cg,{children:[ve(Fe,{children:" ".repeat(Ll)}),ve(er,{ref:Ze=>{$.set(z,Ze)},value:m[D.name]??"",onChange:Ze=>p(Va=>({...Va,[D.name]:Ze})),onSubmit:()=>C(1),isActive:ee,placeholder:D.kind==="text"||D.kind==="code"?D.placeholder:void 0,mask:D.kind==="text"?D.mask:void 0,width:J})]})]}),ee&&he!==void 0&&ve(Fe,{color:f.faintForeground,children:`${" ".repeat(2+P+Ll)}${qe(he,J)}`}),D.kind==="code"&&ve(Aw,{active:Qe,state:Tt,email:(m[D.emailField]??"").trim(),indent:ne,width:J,hovered:x===oe("send",z),nodeRef:Ze=>{fe.set(oe("send",z),Ze)}})]},D.name)}),Et(tn,{marginTop:1,flexDirection:"column",children:[ve(tn,{ref:D=>{fe.set(oe("submit"),D)},children:S?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",x===oe("submit")),bold:R?.type==="submit",children:n})]})}),s!==void 0&&!S&&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",x===oe("secondary")),bold:R?.type==="secondary",children:s.label})]})})]})]})]})}function Aw({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 Ew=2,ag=2;function Gs({options:e,value:t,onChange:n,arrowKeys:o=!0}){let r=e.findIndex(m=>m.value===t),i=ys();lg((m,p)=>{if(!p.leftArrow&&!p.rightArrow)return;let d=p.leftArrow?-1:1,b=e[(r+d+e.length)%e.length];b!==void 0&&n(b.value)},{isActive:o&&!i});let s=[],a=0;e.forEach((m,p)=>{p>0&&(a+=ag);let d=Ol(m.label)+Ew;s.push({value:m.value,from:a,to:a+d}),a+=d});let[c,l]=ar(null),u=rt({onClick:({column:m})=>{let p=s.find(d=>m>=d.from&&m<d.to);p!==void 0&&n(p.value)},onHover:({column:m})=>{let p=s.find(d=>m>=d.from&&m<d.to);l(p?.value??null)},onHoverLeave:()=>l(null)});return ve(tn,{ref:u,children:ve(Fe,{wrap:"truncate",children:e.map((m,p)=>{let d=m.value===t;return Et(Fe,{children:[p>0&&" ".repeat(ag),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 mg,Text as Sn}from"ink";import Mw from"string-width";import{jsx as bn,jsxs as Dl}from"react/jsx-runtime";var zs=3,Nn=2,To=10,Iw=8,ug=e=>Math.floor((e-zs)/Nn),cr=e=>ug(e)>=Iw;function Nw(e,t){let n=new Map(e.days.map(l=>[l.day,t(l)])),o=[...n.values()].sort((l,u)=>l-u),r=l=>o[Math.floor((o.length-1)*l)]??0,[i,s,a]=[r(.25),r(.5),r(.75)],c=[];for(let l=e.start;l<=e.end;l=Gn(l,1)){let u=n.get(l)??0;c.push({day:l,level:u<=0?0:u<=i?1:u<=s?2:u<=a?3:4})}return c}function Lw(e,t){let n=t*Nn,o="",r=0,i="";for(;r<n;){let s=r%Nn===0?e[r/Nn*7]:void 0;if(s!==void 0){let a=s.day.slice(0,7);if(a!==i){i=a;let c=`${Number(s.day.slice(5,7))}\u6708`,l=Mw(c);if(r+l<=n){o+=c,r+=l;continue}}}o+=" ",r+=1}return o}var Ow={1:"\u4E00",3:"\u4E09",5:"\u4E94"};function Dw({cells:e,day:t,weeks:n}){return Dl(Sn,{wrap:"truncate",children:[bn(Sn,{color:f.faintForeground,children:Je(Ow[t]??"",zs)}),Array.from({length:n},(o,r)=>{let i=e[r*7+t];return i===void 0?bn(Sn,{children:" ".repeat(Nn)},r):bn(Sn,{backgroundColor:Ts[i.level],children:" ".repeat(Nn)},r)})]})}function lr({data:e,value:t,caption:n,width:o}){let r=Nw(e,t),i=Math.ceil(r.length/7),s=Math.min(i,ug(o)),a=r.slice((i-s)*7),c=3+Ts.length*Nn+3,l=Math.max(0,zs+s*Nn-c-2);return Dl(mg,{flexDirection:"column",children:[bn(Sn,{wrap:"truncate",color:f.faintForeground,children:" ".repeat(zs)+Lw(a,s)}),Array.from({length:7},(u,m)=>bn(Dw,{cells:a,day:m,weeks:s},m)),bn(mg,{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(Nn)},u)),bn(Sn,{color:f.faintForeground,children:" \u591A"})]})})]})}import{Box as Fl,Text as dg}from"ink";import $w from"qrcode";import{jsx as li,jsxs as qw}from"react/jsx-runtime";var Bw="#000000",Fw="#ffffff",$l=2,fg=2,Ul=1,pg,Bl;function gg(e){if(e===pg&&Bl!==void 0)return Bl;let t=$w.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 pg=e,Bl=i,i}function Uw(e){let t=gg(e).length;return{columns:t*fg,rows:t}}function Ws(e,t,n,o){let r=Uw(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 jw(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(dg,{backgroundColor:e[o]??!1?Bw:Fw,children:" ".repeat((r-o)*fg)},o)),o=r);return li(dg,{children:n},t)}function Hw({value:e}){return li(Fl,{flexDirection:"column",flexShrink:0,children:gg(e).map((t,n)=>jw(t,n))})}function Vs({value:e,aside:t}){return qw(Fl,{flexDirection:"column",flexShrink:0,children:[li(Hw,{value:e}),li(Fl,{marginTop:Ul,flexDirection:"column",children:t})]})}import{Box as Ks,Text as Mt}from"ink";import hg from"string-width";import{jsx as It,jsxs as mi}from"react/jsx-runtime";var Ys=2,jl=4,yg=e=>" ".repeat(e),Hl=13,bg=4,Sg=(e,t,n)=>Math.max(1,Math.min(e,n,Math.floor((t+Ys)/(Hl+Ys)))),Ut=(e,t,n=bg)=>Math.ceil(e/Sg(e,t,n))*2;function it({tiles:e,width:t,maxPerRow:n=bg}){let o=Sg(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&&yg(Ys),It(Mt,{color:c==="label"?f.mutedForeground:f.foreground,bold:c==="value",children:Je(l[c],r)})]},l.label))},c))},a))})}function xg({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 Gw({items:e,width:t}){let n=Math.max(0,...e.map(([r])=>hg(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(Gw,{items:e,width:t});let o=Math.max(0,...e.map(([a])=>hg(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]),yg(jl),s(a[1])]},c))})}import{Lexer as zw}from"marked";var Ww=new RegExp("\\p{Cc}","gu"),Vw=/[\\[\]]/g,Kw=/[\\`*_{}[\]()#+\-.!|<>~]/g,Yw=/[\uD800-\uDBFF]$/,Jw=400,Xw=12,Qw=20,mr={label:"\u677F\u5757",cap:Xw},Qn={label:"\u4F5C\u8005",cap:Qw},Xs={maxCount:Fu,maxBytes:$r},Qs={maxCount:Uu,maxBytes:$r},st=e=>e.replace(Ww,""),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)}`,Tg=e=>e.flatMap(t=>[{reply:t.reply,mention:t.mention,prefix:""},...wg(t.children,"")]);function wg(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 "}`},...wg(n.children,`${t}${r?" ":"\u2502 "}`)]})}var Ln=(e,t)=>e.kind==="user"&&e.username===t,ql=e=>`${e.image?"[\u56FE\u7247]":"[\u9644\u4EF6]"} ${st(e.name)}`;function jt(e){let t=new Set;return Vu(e).filter(n=>t.has(n.id)?!1:(t.add(n.id),!0))}var Zw=e=>kc(e,t=>ql(t).replace(Kw,"\\$&")),di=(e,t)=>hn(Zw(e),t);function wo(e){let t=kc(e,n=>n.image?"[\u56FE\u7247]":`[\u9644\u4EF6] ${n.name}`).slice(0,Jw).replace(Yw,"");return st(hd(zw.lex(t,{gfm:!0,breaks:!0}))).trim()}var ek=e=>st(e).trim().replace(Vw,"\\$&");function pi(e,t){if(t.length===0)return e;let n=t.map(o=>`${o.image===null?"":"!"}[${ek(o.fileName)}](${ju(o.id)})`).join(`
16
16
  `);return e===""?n:`${e}
17
17
 
18
- ${n}`}import{Box as Sg,Text as Yw}from"ink";import{useState as Ys}from"react";import{jsx as Kw}from"react/jsx-runtime";function ur({title:e,width:t,download:n,onCancel:o,onSaved:r}){let{busy:i,error:s,run:a}=ue();return Kw(te,{title:e,width:t,submitLabel:"\u4E0B\u8F7D",busy:i!==null,busyLabel:"\u6B63\u5728\u4E0B\u8F7D",error:s,fields:[{kind:"text",name:"path",label:"\u4FDD\u5B58\u8DEF\u5F84",placeholder:"\u7559\u7A7A\u4FDD\u5B58\u5230\u5F53\u524D\u76EE\u5F55",hint:"\u53EF\u586B\u76EE\u5F55\u6216\u5E26\u6587\u4EF6\u540D\u7684\u5B8C\u6574\u8DEF\u5F84",optional:!0}],onCancel:o,onSubmit:c=>{a("\u6B63\u5728\u4E0B\u8F7D",async()=>{let l=await n();return zf(c.path??"",l.fileName,l.bytes)},{onSuccess:r})}})}var dr={maxCount:Su,maxBytes:bu},Zn=e=>({kind:"textarea",name:"attachments",label:"\u9644\u4EF6\u8DEF\u5F84",rows:2,placeholder:"\u6BCF\u884C\u4E00\u4E2A\u672C\u5730\u6587\u4EF6\u8DEF\u5F84\uFF0C\u53EF\u7559\u7A7A",hint:`\u6700\u591A ${e.maxCount} \u4E2A\uFF0C\u5355\u4E2A\u4E0D\u8D85\u8FC7 ${e.maxBytes/1024/1024}MB`,optional:!0});import{jsx as On,jsxs as ek}from"react/jsx-runtime";var Js=e=>e===null?void 0:`\u539F\u56E0\uFF1A${e}`,pr=(e,t)=>e===null?0:ul(Lc(e.until),Js(e.reason),t)+1;function ko({muted:e,width:t}){return e===null?null:On(Sg,{marginBottom:1,children:On(ye,{tone:"warn",width:t,title:Lc(e.until),detail:Js(e.reason),wrap:!0})})}var Xs=(e,t,n,o)=>t==="published"?0:ul(e[t],Js(n),o);function vo({notices:e,status:t,reason:n,width:o}){return t==="published"?null:On(ye,{tone:t==="pending"?"warn":"fail",title:e[t],detail:Js(n),width:o,wrap:!0})}var pi=e=>e===null?0:(e.hint===void 0?1:2)+1,Jw=["content","attachments"],Xw=9,Qw=3,Zw=8;function Qs({postId:e,replyTo:t,width:n,height:o,onDone:r,onCancel:i}){let{busy:s,error:a,fail:c,run:l}=ue(),[u,m]=Ys({content:"",attachments:""}),[p,d]=Ys(!1),b=Jw.some(g=>(u[g]??"").trim()!==""),h=Math.min(Zw,Math.max(Qw,o-Xw-pi(a)));return Re(b),gn(()=>d(!1),{isActive:p,layer:Wn.panel}),G(g=>{g==="q"&&b&&d(!0)},!p&&s===null),p?On(Ae,{width:n,title:t===null?"\u653E\u5F03\u8BC4\u8BBA":"\u653E\u5F03\u56DE\u590D",detail:t===null?"\u8BC4\u8BBA\u5C1A\u672A\u53D1\u8868\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F":"\u56DE\u590D\u5C1A\u672A\u53D1\u8868\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F",confirmLabel:"\u653E\u5F03",onConfirm:i,onCancel:()=>d(!1)}):On(te,{title:t===null?"\u53D1\u8868\u8BC4\u8BBA":`\u56DE\u590D ${t.mention}`,width:n,submitLabel:t===null?"\u53D1\u8868\u8BC4\u8BBA":"\u53D1\u8868\u56DE\u590D",busy:s!==null,busyLabel:s??"\u6B63\u5728\u63D0\u4EA4",error:a,fields:[{kind:"textarea",name:"content",label:"\u5185\u5BB9",rows:h,maxLength:xc,initial:u.content,placeholder:t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9\uFF0C\u652F\u6301 Markdown":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9"},{...Zn(Vs),initial:u.attachments}],onChange:m,onCancel:()=>b?d(!0):i(),onSubmit:g=>{let x=(g.content??"").trim(),T;try{T=Jn(g.attachments??"",Vs)}catch(k){c(xe(k));return}if(x===""&&T.length===0){c(t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9");return}if(jt(x).length+T.length>Vs.maxCount){c("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return}l("\u6B63\u5728\u63D0\u4EA4",()=>Mn(T,si,k=>hf(e,{content:di(x,k),...t===null?{}:{replyToId:t.id}})),{onSuccess:k=>r(k.id)})}})}function Zs({target:e,width:t,onDone:n,onCancel:o}){let{busy:r,error:i,fail:s,run:a}=ue();return On(te,{title:e.kind==="post"?"\u4E3E\u62A5\u5E16\u5B50":"\u4E3E\u62A5\u8BC4\u8BBA",width:t,submitLabel:"\u63D0\u4EA4\u4E3E\u62A5",busy:r!==null,busyLabel:r??"\u6B63\u5728\u63D0\u4EA4",error:i,fields:[{kind:"select",name:"reason",label:"\u4E3E\u62A5\u539F\u56E0",options:[{value:"",label:"\u8BF7\u9009\u62E9\u4E3E\u62A5\u539F\u56E0"},...Pi.map(c=>({value:c,label:kd(c)}))],initial:""},{kind:"text",name:"detail",label:"\u8865\u5145\u8BF4\u660E",placeholder:"\u8BF4\u660E\u5177\u4F53\u95EE\u9898\uFF0C\u4FBF\u4E8E\u7BA1\u7406\u5458\u6838\u5B9E",optional:!0}],onCancel:o,onSubmit:c=>{let l=Pi.find(p=>p===c.reason);if(l===void 0){s("\u8BF7\u9009\u62E9\u4E3E\u62A5\u539F\u56E0");return}let u=(c.detail??"").trim();if(u.length>$i){s(`\u8865\u5145\u8BF4\u660E\u6700\u591A ${$i} \u4E2A\u5B57\u7B26`);return}let m={reason:l,detail:u===""?null:u};a("\u6B63\u5728\u63D0\u4EA4",()=>e.kind==="post"?Tf(e.id,m):wf(e.id,m),{onSuccess:n})}})}function ea({refs:e,width:t,height:n}){let o=O(),[r,i]=Ys(null),[s,a]=Ys(null);return r!==null?On(ur,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${st(r.name)}`,width:t,download:async()=>{let c=await Df(r.id);return{fileName:st(c.fileName),bytes:c.bytes}},onCancel:()=>i(null),onSaved:c=>{i(null),a(c),o.toast("ok","\u9644\u4EF6\u5DF2\u4FDD\u5B58")}}):ek(Sg,{flexDirection:"column",children:[On(le,{width:t,height:Math.max(3,n-(s===null?0:1)),items:[{heading:"\u9644\u4EF6"},...e.map(c=>({value:c,label:Fl(c)}))],onSelect:c=>{a(null),i(c)}}),s!==null&&On(Yw,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${st(s)}`})]})}import{Fragment as ck,jsx as me,jsxs as xn}from"react/jsx-runtime";var nk={cli:"\u547D\u4EE4\u884C",mobile:"\u624B\u673A",tablet:"\u5E73\u677F",smarttv:"\u667A\u80FD\u7535\u89C6",console:"\u6E38\u620F\u4E3B\u673A",wearable:"\u53EF\u7A7F\u6234\u8BBE\u5907",embedded:"\u5D4C\u5165\u5F0F\u8BBE\u5907"},Tg="\u5BC6\u94A5 ",ok=10,rk={rebind:{title:"\u91CD\u65B0\u7ED1\u5B9A\u4E24\u6B65\u9A8C\u8BC1",submit:"\u7EE7\u7EED",hint:"\u786E\u8BA4\u540E\u751F\u6210\u65B0\u5BC6\u94A5\uFF0C\u9A8C\u8BC1\u5668\u4E2D\u539F\u6709\u6761\u76EE\u5C06\u5931\u6548\uFF0C\u6062\u590D\u7801\u4E5F\u4F1A\u66F4\u6362"},regenerate:{title:"\u91CD\u65B0\u751F\u6210\u6062\u590D\u7801",submit:"\u751F\u6210",hint:"\u751F\u6210\u540E\u539F\u6709\u6062\u590D\u7801\u5168\u90E8\u4F5C\u5E9F"},disable:{title:"\u505C\u7528\u4E24\u6B65\u9A8C\u8BC1",submit:"\u505C\u7528",hint:"\u505C\u7528\u540E\u767B\u5F55\u4E0D\u518D\u8981\u6C42\u52A8\u6001\u7801\uFF0C\u6062\u590D\u7801\u540C\u65F6\u4F5C\u5E9F"}},ik=3,sk=8;function ak({codes:e,width:t}){let n=Math.max(...e.map(r=>r.length))+4,o=[];for(let r=0;r<e.length;r+=2)o.push(xn(fi,{wrap:"truncate",color:f.accent,children:[Je(e[r]??"",Math.min(n,t)),e[r+1]??""]},r));return me(at,{flexDirection:"column",children:o})}function wg(){let e=O(),{width:t,columns:n,rows:o}=j(),r=Z(),[i,s]=xg({name:"menu"}),[a,c]=xg(!1),{busy:l,error:u,reset:m,fail:p,run:d}=ue(),b=Q([e.revision],async()=>{let[S,y,R,N]=await Promise.all([En(),Ef(),_f(),$f()]);return{user:S.user,security:y,sessions:R.sessions,avatarReview:N.review}}),h=Q([e.revision],async()=>{let[S,y]=await Promise.all([En(),mf()]);return{homepage:await vl(S.user.username),todo:y}});G(S=>{i.name==="menu"&&l===null&&S==="r"&&e.reload()}),Re(i.name==="codes"||l!==null);let g=()=>{if(i.name!=="codes"){if(i.name==="menu"){e.pop();return}m(),i.name==="passkey-rename"||i.name==="passkey-delete"?s({name:"passkey",item:i.item}):i.name==="confirm-revoke"?s({name:"session",item:i.item}):s({name:"menu"})}},x=S=>{s({name:"menu"}),e.reload(),e.toast("ok",S)},T=(S,y)=>{c(!1),s({name:"codes",codes:S,message:y})},k=(S,y)=>{S==="rebind"?d("\u6B63\u5728\u751F\u6210\u65B0\u5BC6\u94A5",()=>Cl({code:y}),{onSuccess:R=>s({name:"enroll",setup:R})}):S==="regenerate"?d("\u6B63\u5728\u751F\u6210\u6062\u590D\u7801",()=>Nf({code:y}),{onSuccess:({recoveryCodes:R})=>T(R,"\u6062\u590D\u7801\u5DF2\u66F4\u65B0")}):d("\u6B63\u5728\u505C\u7528",()=>If({code:y}),{onSuccess:()=>x("\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u505C\u7528")})};return me(Y,{hints:i.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","r \u5237\u65B0"]:i.name==="codes"?["\u2191\u2193 \u79FB\u52A8","Enter \u786E\u8BA4"]:["Esc \u8FD4\u56DE"],locked:i.name==="codes",onEscape:g,isActive:l===null,children:me(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u8D26\u6237\u4FE1\u606F",width:t,children:({user:S,security:y,sessions:R,avatarReview:N})=>{if(i.name==="avatar")return xn(at,{flexDirection:"column",children:[N!==null&&me(at,{marginBottom:1,children:me(vo,{notices:Ic,status:N.status,reason:N.reviewReason,width:t})}),me(te,{title:"\u4FEE\u6539\u5934\u50CF",width:t,submitLabel:"\u4E0A\u4F20",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4E0A\u4F20",error:u,fields:[{kind:"text",name:"path",label:"\u56FE\u7247\u8DEF\u5F84",placeholder:"\u672C\u5730\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84"}],onCancel:g,onSubmit:w=>{let F=(w.path??"").trim();if(F===""){p("\u8BF7\u8F93\u5165\u56FE\u7247\u8DEF\u5F84");return}let re;try{re=Gf(F,Dr)}catch(D){p(xe(D));return}d("\u6B63\u5728\u4E0A\u4F20",()=>Bf(re),{onSuccess:()=>x("\u5DF2\u63D0\u4EA4\u5BA1\u6838")})}})]});if(i.name==="avatar-delete")return me(Ae,{width:t,title:"\u786E\u8BA4\u5220\u9664\u5934\u50CF\uFF1F",detail:"\u5220\u9664\u540E\u663E\u793A\u9ED8\u8BA4\u5934\u50CF",confirmLabel:"\u5220\u9664",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>Ff(),{onSuccess:()=>x("\u5934\u50CF\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="rename")return me(te,{title:"\u4FEE\u6539\u7528\u6237\u540D",width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"username",label:"\u7528\u6237\u540D",initial:S.username,placeholder:"\u8BF7\u8F93\u5165\u65B0\u7528\u6237\u540D"}],onCancel:g,onSubmit:w=>{let F=(w.username??"").trim();if(F===""||F.length>Kt){p(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}d("\u6B63\u5728\u4FDD\u5B58",()=>kf({username:F}),{onSuccess:()=>x("\u5DF2\u4FDD\u5B58")})}});if(i.name==="email")return me(te,{title:"\u4FEE\u6539\u90AE\u7BB1",width:t,submitLabel:"\u786E\u8BA4\u4FEE\u6539",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"email",label:"\u65B0\u90AE\u7BB1",placeholder:"\u7528\u4E8E\u767B\u5F55\u4E0E\u63A5\u6536\u901A\u77E5\u7684\u65B0\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",emailField:"email",send:w=>Cf({email:w})},{kind:"text",name:"password",label:"\u5F53\u524D\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5F53\u524D\u5BC6\u7801",hint:"\u4FEE\u6539\u540E\u7ACB\u5373\u4EE5\u65B0\u90AE\u7BB1\u767B\u5F55\u548C\u63A5\u6536\u901A\u77E5\uFF0C\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55"}],onCancel:g,onSubmit:w=>{let F=(w.email??"").trim(),re=(w.code??"").trim(),D=w.password??"";if(F===""||re===""||D===""){p("\u8BF7\u586B\u5199\u65B0\u90AE\u7BB1\u3001\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801");return}d("\u6B63\u5728\u4FDD\u5B58",()=>Rf({email:F,code:re,password:D}),{onSuccess:()=>x("\u90AE\u7BB1\u5DF2\u4FEE\u6539")})}});if(i.name==="password")return me(te,{title:"\u4FEE\u6539\u5BC6\u7801",width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"old",label:"\u5F53\u524D\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5F53\u524D\u5BC6\u7801"},{kind:"text",name:"next",label:"\u65B0\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u65B0\u5BC6\u7801",hint:`\u81F3\u5C11 ${Ot} \u4F4D\uFF0C\u4FDD\u5B58\u540E\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55`}],onCancel:g,onSubmit:w=>{let F=w.old??"",re=w.next??"";if(F===""){p("\u8BF7\u586B\u5199\u5F53\u524D\u5BC6\u7801");return}if(re.length<Ot){p(`\u65B0\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}d("\u6B63\u5728\u4FDD\u5B58",()=>vf({oldPassword:F,newPassword:re}),{onSuccess:()=>x("\u5BC6\u7801\u5DF2\u4FEE\u6539")})}});if(i.name==="confirm-logout-all")return me(Ae,{width:t,title:"\u786E\u8BA4\u9000\u51FA\u6240\u6709\u8BBE\u5907\u7684\u767B\u5F55\uFF1F",detail:"\u5F53\u524D\u8BBE\u5907\u4E5F\u4F1A\u4E00\u5E76\u9000\u51FA",confirmLabel:"\u9000\u51FA",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u9000\u51FA",()=>Af(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u6240\u6709\u8BBE\u5907"),e.home()}}),onCancel:g});if(i.name==="code"){let w=rk[i.intent];return me(te,{title:w.title,width:t,submitLabel:w.submit,busy:l!==null,busyLabel:l??"\u6B63\u5728\u5904\u7406",error:u,fields:[{kind:"text",name:"code",label:"\u52A8\u6001\u9A8C\u8BC1\u7801",placeholder:"\u9A8C\u8BC1\u5668\u663E\u793A\u7684 6 \u4F4D\u6570\u5B57",hint:w.hint}],onCancel:g,onSubmit:F=>{let re=(F.code??"").trim();if(re===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}k(i.intent,re)}})}if(i.name==="enroll"){let w=(re,D)=>xn(ck,{children:[D&&me(fi,{color:f.mutedForeground,children:"\u4F7F\u7528 Google Authenticator \u7B49\u9A8C\u8BC1\u5668 App \u626B\u7801\u6DFB\u52A0"}),xn(fi,{children:[me(fi,{color:f.mutedForeground,children:Tg}),me(fi,{color:f.accent,children:i.setup.secret})]}),me(at,{marginTop:1,children:me(te,{title:"\u586B\u5165\u52A8\u6001\u9A8C\u8BC1\u7801\u5B8C\u6210\u7ED1\u5B9A",width:re,submitLabel:"\u7ED1\u5B9A",busy:l!==null,busyLabel:l??"\u6B63\u5728\u7ED1\u5B9A",error:u,fields:[{kind:"text",name:"code",label:"\u52A8\u6001\u9A8C\u8BC1\u7801"}],onCancel:g,onSubmit:z=>{let ee=(z.code??"").trim();if(ee===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}d("\u6B63\u5728\u7ED1\u5B9A",()=>Mf({code:ee}),{onSuccess:({recoveryCodes:he})=>T(he,"\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u7ED1\u5B9A")})}})})]}),F=js(i.setup.otpauthUri,{width:t,rows:r},{columns:tk(Tg)+i.setup.secret.length,rows:ok},{columns:n-t,rows:o-r});return F.fits?me(Hs,{value:i.setup.otpauthUri,aside:w(F.asideWidth,!0)}):xn(at,{flexDirection:"column",children:[me(ye,{tone:"info",width:t,title:"\u7EC8\u7AEF\u5C3A\u5BF8\u4E0D\u8DB3\uFF0C\u6539\u4E3A\u624B\u52A8\u5F55\u5165",detail:"\u5728\u9A8C\u8BC1\u5668\u4E2D\u9009\u62E9\u624B\u52A8\u8F93\u5165\uFF0C\u586B\u5165\u4E0B\u65B9\u5BC6\u94A5"}),w(t,!1)]})}if(i.name==="codes")return xn(at,{flexDirection:"column",children:[me(ye,{tone:"warn",width:t,title:"\u6062\u590D\u7801\u4EC5\u6B64\u4E00\u6B21\u5C55\u793A\uFF0C\u8BF7\u7ACB\u5373\u4FDD\u5B58\u5230\u5B89\u5168\u7684\u4F4D\u7F6E",detail:"\u6BCF\u679A\u6062\u590D\u7801\u53EA\u80FD\u4F7F\u7528\u4E00\u6B21\uFF0C\u53EF\u5728\u9A8C\u8BC1\u5668\u4E0D\u53EF\u7528\u65F6\u4EE3\u66FF\u52A8\u6001\u9A8C\u8BC1\u7801\u767B\u5F55"}),me(at,{marginTop:1,children:me(ak,{codes:i.codes,width:t})}),me(at,{marginTop:1,children:me(le,{width:t,items:[{value:"ack",label:`${a?"[x]":"[ ]"} \u6211\u5DF2\u59A5\u5584\u4FDD\u5B58\u8FD9\u4E9B\u6062\u590D\u7801`},{value:"done",label:"\u5B8C\u6210",disabled:!a}],onSelect:w=>{if(w==="ack"){c(re=>!re);return}let F=i.message;s({name:"menu"}),e.reload(),e.toast("ok",F)}})})]});if(i.name==="passkey-add")return me(ye,{tone:"info",width:t,title:`\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00 ${e.ctx.site} \u7684\u300C\u4E2A\u4EBA\u4E3B\u9875\u300D\u5B8C\u6210\u6DFB\u52A0`,detail:"\u6DFB\u52A0\u4E0E\u4F7F\u7528 Passkey \u4F9D\u8D56\u6D4F\u89C8\u5668\u7684 WebAuthn \u80FD\u529B\uFF0C\u7EC8\u7AEF\u65E0\u6CD5\u5B8C\u6210"});if(i.name==="passkey-rename")return me(te,{title:`\u91CD\u547D\u540D Passkey ${i.item.name}`,width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"name",label:"\u540D\u79F0",initial:i.item.name,placeholder:"\u6807\u8BB0\u6240\u5728\u8BBE\u5907\uFF0C\u5982 MacBook \u6307\u7EB9"}],onCancel:g,onSubmit:w=>{let F=(w.name??"").trim();if(F===""){p("\u8BF7\u8F93\u5165\u540D\u79F0");return}d("\u6B63\u5728\u4FDD\u5B58",()=>Lf(i.item.id,{name:F}),{onSuccess:()=>x("\u5DF2\u4FDD\u5B58")})}});if(i.name==="passkey-delete")return me(Ae,{width:t,title:`\u786E\u8BA4\u5220\u9664 Passkey\u300C${i.item.name}\u300D\uFF1F`,detail:"\u5220\u9664\u540E\u65E0\u6CD5\u518D\u7528\u5B83\u767B\u5F55",confirmLabel:"\u5220\u9664",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>Of(i.item.id),{onSuccess:()=>x("\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="passkey"){let w=i.item;return me(at,{flexDirection:"column",children:xn(pe,{title:`Passkey ${w.name}`,width:t,children:[me(Ve,{width:t-ge,items:[["\u540D\u79F0",w.name],["\u6DFB\u52A0\u65F6\u95F4",K(w.createdAt)],["\u6700\u8FD1\u4F7F\u7528",w.lastUsedAt===null?"\u2014":K(w.lastUsedAt)]]}),me(at,{marginTop:1,children:me(le,{width:t-ge,items:[{value:"rename",label:"\u91CD\u547D\u540D"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:F=>{m(),s(F==="rename"?{name:"passkey-rename",item:w}:{name:"passkey-delete",item:w})}})})]})})}if(i.name==="confirm-revoke"){let w=i.item;return me(Ae,{width:t,title:"\u786E\u8BA4\u9000\u51FA\u8BE5\u8BBE\u5907\u7684\u767B\u5F55\uFF1F",confirmLabel:"\u9000\u51FA",busy:l,error:u,onConfirm:()=>{if(w.current){d("\u6B63\u5728\u9000\u51FA",()=>ns(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u767B\u5F55"),e.home()}});return}d("\u6B63\u5728\u9000\u51FA\u8BE5\u8BBE\u5907",()=>Pf(w.id),{onSuccess:()=>x("\u5DF2\u9000\u51FA\u8BE5\u8BBE\u5907")})},onCancel:g})}if(i.name==="session"){let w=i.item;return xn(at,{flexDirection:"column",children:[me(pe,{title:Go(w.device),note:w.current?"\u5F53\u524D\u8BBE\u5907":void 0,width:t,children:me(Ve,{width:t-ge,items:[["\u8BBE\u5907\u7C7B\u578B",w.device?.type!=null?nk[w.device.type]??w.device.type:"\u684C\u9762\u8BBE\u5907"],["\u5BA2\u6237\u7AEF",w.device?.client!=null?`${w.device.client} ${w.device.clientVersion??""}`.trim():"\u2014"],["\u64CD\u4F5C\u7CFB\u7EDF",w.device?.os!=null?`${w.device.os} ${w.device.osVersion??""}`.trim():"\u2014"],["\u8BBE\u5907\u578B\u53F7",w.device?.model!=null?`${w.device.vendor??""} ${w.device.model}`.trim():"\u2014"],["IP \u5730\u5740",w.ip],["\u767B\u5F55\u65F6\u95F4",K(w.loginAt)],["\u6700\u540E\u6D3B\u8DC3",K(w.lastActiveAt)],["\u767B\u5F55\u6709\u6548\u671F\u81F3",K(w.expiresAt)],["\u5BA2\u6237\u7AEF\u6807\u8BC6",w.userAgent??"\u2014"]]})}),l===null&&me(at,{marginTop:1,children:me(le,{width:t,items:[{value:"revoke",label:"\u9000\u51FA\u8BE5\u8BBE\u5907",labelTone:"danger"}],onSelect:()=>{m(),s({name:"confirm-revoke",item:w})}})})]})}let E=y.totp,W=h.phase==="ready"?h.data:null,M=W===null?null:W.todo,C=M===null?0:M.posts.filter(w=>w.status==="pending").length,v=M===null?0:M.posts.filter(w=>w.status==="rejected").length,_=_e([C>0&&`${C} \u7BC7\u5BA1\u6838\u4E2D`,v>0&&`${v} \u7BC7\u672A\u901A\u8FC7`]),L=[{heading:"\u793E\u533A"},{value:{kind:"my-posts"},label:"\u6211\u7684\u5E16\u5B50",hint:_===""?void 0:_},{value:{kind:"my-comments"},label:"\u6211\u7684\u8BC4\u8BBA"},{value:{kind:"bookmarks"},label:"\u6211\u7684\u6536\u85CF"},{value:{kind:"drafts"},label:"\u6211\u7684\u8349\u7A3F",hint:M!==null&&M.drafts>0?`${M.drafts} \u7BC7\u672A\u53D1\u5E03`:void 0},{heading:""},{heading:"\u8D26\u6237"},{value:{kind:"avatar"},label:"\u4FEE\u6539\u5934\u50CF",hint:N===null?"\u663E\u793A\u5728\u4E2A\u4EBA\u4E3B\u9875\u548C\u4F60\u7684\u53D1\u8A00\u4E2D":ad(N)},{value:{kind:"rename"},label:"\u4FEE\u6539\u7528\u6237\u540D",hint:"\u4FEE\u6539\u540E\u4E2A\u4EBA\u4E3B\u9875\u5730\u5740\u968F\u4E4B\u6539\u53D8"},{value:{kind:"email"},label:"\u4FEE\u6539\u90AE\u7BB1",hint:"\u9700\u8981\u90AE\u7BB1\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801"},{value:{kind:"password"},label:"\u4FEE\u6539\u5BC6\u7801",hint:"\u4FEE\u6539\u540E\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55"},...S.avatarUrl===null?[]:[{value:{kind:"avatar-delete"},label:"\u5220\u9664\u5934\u50CF",labelTone:"danger"}],{heading:""},{heading:"\u4E24\u6B65\u9A8C\u8BC1"},...E.enabled?[{value:{kind:"code",intent:"rebind"},label:"\u91CD\u65B0\u7ED1\u5B9A",hint:"\u751F\u6210\u65B0\u5BC6\u94A5\u5E76\u66F4\u6362\u6062\u590D\u7801"},{value:{kind:"code",intent:"regenerate"},label:"\u91CD\u65B0\u751F\u6210\u6062\u590D\u7801",hint:"\u539F\u6709\u6062\u590D\u7801\u5168\u90E8\u4F5C\u5E9F"},{value:{kind:"code",intent:"disable"},label:"\u505C\u7528",labelTone:"danger"}]:[{value:{kind:"enable"},label:"\u542F\u7528\u4E24\u6B65\u9A8C\u8BC1",hint:"\u767B\u5F55\u65F6\u8981\u6C42\u989D\u5916\u8F93\u5165\u9A8C\u8BC1\u5668\u52A8\u6001\u7801"}],{heading:""},{heading:"Passkey"},...y.passkeys.length===0?[{value:{kind:"none"},label:"\u6682\u65E0 Passkey",hint:"\u6DFB\u52A0\u540E\u53EF\u4F7F\u7528\u6307\u7EB9\u3001\u9762\u5BB9\u6216\u786C\u4EF6\u5BC6\u94A5\u4E00\u6B65\u767B\u5F55",disabled:!0}]:[],...y.passkeys.map(w=>({value:{kind:"passkey",item:w},label:w.name,hint:`\u6700\u8FD1\u4F7F\u7528 ${w.lastUsedAt===null?"\u2014":K(w.lastUsedAt)}`})),{value:{kind:"add-passkey"},label:"\u6DFB\u52A0 Passkey",hint:"\u9700\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"},{heading:""},{heading:"\u767B\u5F55\u8BBE\u5907"},...R.map(w=>({value:{kind:"session",item:w},label:w.current?`${Go(w.device)}\uFF08\u5F53\u524D\u8BBE\u5907\uFF09`:Go(w.device),...w.current?{labelTone:"accent"}:{},hint:`${w.ip} \xB7 \u6700\u540E\u6D3B\u8DC3 ${K(w.lastActiveAt)}`})),{value:{kind:"logout-all"},label:"\u9000\u51FA\u6240\u6709\u8BBE\u5907",labelTone:"danger",hint:"\u5F53\u524D\u8BBE\u5907\u4E5F\u4F1A\u4E00\u5E76\u9000\u51FA"}],P=W===null?null:W.homepage,B=[["\u7528\u6237\u540D",st(S.username)],["\u90AE\u7BB1",S.email],...E.enabled?[["\u4E24\u6B65\u9A8C\u8BC1",`\u542F\u7528\u4E8E ${E.enabledAt===null?"\u2014":K(E.enabledAt)}`],["\u6062\u590D\u7801",E.recoveryCodesRemaining===0?"\u5DF2\u5168\u90E8\u7528\u5B8C\uFF0C\u8BF7\u91CD\u65B0\u751F\u6210":`\u5269\u4F59 ${E.recoveryCodesRemaining} \u679A\uFF0C\u9A8C\u8BC1\u5668\u4E0D\u53EF\u7528\u65F6\u53EF\u4EE3\u66FF\u52A8\u6001\u7801\u767B\u5F55`]]:[],...P===null?[]:[["\u7B49\u7EA7",qi(P.identity.points)],["\u79EF\u5206",`${P.identity.points} \xB7 ${Gi(P.identity.points)}`],["\u52A0\u5165\u65F6\u95F4",Ur(P.joinedAt)]]],J=h.phase==="error"?h:null,oe=P!==null?Ut(ik,t)+X:J!==null?(J.hint===void 0?1:2)+X:0,fe=zs(B.length,t)+X+oe,$=X+Xe+To,ne=P!==null&&cr(t)&&r-fe-$>=sk;return xn(at,{flexDirection:"column",children:[me(Ve,{width:t,items:B}),P!==null&&me(at,{marginTop:X,children:me(it,{width:t,tiles:[{label:"\u5E16\u5B50",value:String(P.stats.posts)},{label:"\u8BC4\u8BBA",value:String(P.stats.comments)},{label:"\u83B7\u8D5E",value:String(P.stats.likesReceived)}]})}),J!==null&&me(at,{marginTop:X,children:me(Ft,{message:`\u793E\u533A\u6570\u636E\u8BFB\u53D6\u5931\u8D25\uFF1A${J.message}`,hint:J.hint,width:t})}),ne&&xn(at,{marginTop:X,flexDirection:"column",children:[me(Rn,{title:"\u793E\u533A\u8DB3\u8FF9",width:t}),me(at,{marginTop:qe,flexDirection:"column",children:me(lr,{data:P.activity,value:w=>w.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${P.activity.days.reduce((w,F)=>w+F.count,0)} \u6B21`,width:t})})]}),me(at,{marginTop:X,children:me(le,{width:t,height:Math.max(3,r-fe-(ne?$:0)),isActive:l===null,items:L,retain:"menu",onSelect:w=>{m(),w.kind==="my-posts"?e.push("my-posts",{username:S.username}):w.kind==="my-comments"?e.push("my-comments",{username:S.username}):w.kind==="bookmarks"?e.push("bookmarks"):w.kind==="drafts"?e.push("drafts"):w.kind==="avatar"?s({name:"avatar"}):w.kind==="avatar-delete"?s({name:"avatar-delete"}):w.kind==="rename"?s({name:"rename"}):w.kind==="email"?s({name:"email"}):w.kind==="password"?s({name:"password"}):w.kind==="logout-all"?s({name:"confirm-logout-all"}):w.kind==="enable"?d("\u6B63\u5728\u751F\u6210\u5BC6\u94A5",()=>Cl({}),{failToast:!0,onSuccess:F=>s({name:"enroll",setup:F})}):w.kind==="code"?s({name:"code",intent:w.intent}):w.kind==="add-passkey"?s({name:"passkey-add"}):w.kind==="passkey"?s({name:"passkey",item:w.item}):w.kind==="session"&&s({name:"session",item:w.item})}})})]})}})})}import{Box as oa,Text as ra,useInput as gk}from"ink";import{useRef as Mg,useState as fr}from"react";import hk from"string-width";import{z as Ct}from"zod";var lk=Ct.object({siteName:Ct.string(),apiLines:Ct.array(Ct.object({name:Ct.string(),description:Ct.string(),url:Ct.string()})),quotaPerUsd:Ct.number(),ticketAutoCloseMinutes:Ct.number(),legal:Ct.object({termsConfigured:Ct.boolean(),privacyConfigured:Ct.boolean()})});function Ge(e,t){return fn(lk,`${e}/api/site-config`,{...t===void 0?{}:{timeoutMs:t}})}var mk=Ct.object({content:Ct.string(),configured:Ct.boolean()});function kg(e,t){return fn(mk,`${e}/api/agreements/${t}`)}var vg=12e4,Cg=e=>A(mt(Ii),Fe("/tickets",{...e})),Rg=e=>A(yu,"/tickets",{method:"POST",json:e}),Ul=e=>A(wu,`/tickets/${e}`),_g=(e,t,n)=>A(se,`/tickets/${e}/messages`,{method:"POST",json:{content:t,attachmentIds:n}}),uk=e=>A(Tu,Fe("/tickets/attachments",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:vg}),dk=e=>A(se,`/tickets/attachments/${e}`,{method:"DELETE"}),ta={upload:uk,discard:dk},Pg=(e,t)=>rs(`/tickets/${e}/attachments/${t}`,{timeoutMs:vg}),Ag=e=>A(se,`/tickets/${e}/close`,{method:"POST"}),Eg=e=>A(se,`/tickets/${e}/reopen`,{method:"POST"});import{useEffect as pk,useRef as fk}from"react";function na(e,t,n=!0){let o=fk(t);o.current=t,pk(()=>{if(!n)return;let r=!1,i=setInterval(()=>{r||(r=!0,o.current().catch(()=>{}).finally(()=>{r=!1}))},e);return()=>clearInterval(i)},[e,n])}import{jsx as Ht,jsxs as jl}from"react/jsx-runtime";var yk=5e3,bk=11,Sk=3,Ig=1;function xk(e,t){let n=[],o=r=>{let i=r.spans.reduce((a,c)=>a+hk(c.text),0),s=Math.max(0,t-i);return s===0?r:{spans:[{text:" ".repeat(s)},...r.spans]}};return e.forEach((r,i)=>{i>0&&n.push({spans:[]});let s=r.author.kind==="user",a={spans:[{text:vt(r.author),color:s?f.accent:f.mutedForeground},{text:` ${K(r.createdAt)}`,color:f.faintForeground}]},c=r.content===""?[]:Pt([{text:Vn(r.content),color:f.foreground}],Math.max(8,t-4)),l=r.attachments.map(u=>({spans:[{text:"[\u9644\u4EF6] ",color:f.faintForeground},{text:u.fileName,color:f.foreground},{text:` (${Ko(u.fileSize)})`,color:f.mutedForeground}]}));s?n.push(o(a),...c.map(o),...l.map(o)):n.push(a,...c,...l)}),n}function Ng({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=fr("main"),[s,a]=fr(!1),[c,l]=fr(null),[u,m]=fr(null),[p,d]=fr(0),{busy:b,error:h,reset:g,fail:x,run:T}=ue();Re(b!==null);let k=Q([e.id,t.revision],async()=>{let[L,P]=await Promise.all([Ul(e.id),Ge(t.ctx.site)]);return{detail:L,site:P}}),[S,y]=fr(null),R=Mg(0),N=Mg(t.revision);N.current!==t.revision&&(N.current=t.revision,R.current+=1,S!==null&&y(null));let E=k.phase==="ready"?k.data:null,W=S??E?.detail??null;na(yk,async()=>{if(W===null||b!==null)return;let L=R.current,P=await Ul(e.id);L===R.current&&(P.ticket.updatedAt!==W.ticket.updatedAt||P.messages.length!==W.messages.length)&&y(P)},r==="main"&&E!==null);let M=W?.messages.some(L=>L.attachments.length>0)??!1;G(L=>{r!=="main"||s||b!==null||(L==="r"?t.reload():L==="x"&&W!==null&&W.ticket.status!=="closed"?(g(),i("confirm-close")):L==="a"&&M&&(g(),l(null),m(null),i("attachments")))}),gk((L,P)=>{P.tab&&r==="main"&&!s&&W?.ticket.status!=="closed"&&a(!0)},{isActive:r==="main"&&!s&&b===null});let C=()=>{if(r!=="main"){g(),i("main");return}if(s){a(!1);return}t.pop()},v=(L,P)=>{T("\u6B63\u5728\u53D1\u9001",()=>Mn(P,ta,B=>_g(e.id,L,B.map(J=>J.id))),{onSuccess:()=>{a(!1),d(B=>B+1),t.reload(),t.toast("ok","\u5DF2\u53D1\u9001")}})},_=r==="main"&&!s?["\u2191\u2193 \u6EDA\u52A8",...W?.ticket.status==="closed"?[]:["Tab \u56DE\u590D"],...M?["a \u9644\u4EF6"]:[],...W?.ticket.status==="closed"?[]:["x \u5173\u95ED\u5DE5\u5355"],"r \u5237\u65B0"]:[];return Ht(Y,{trail:["\u5DE5\u5355\u652F\u6301",W?.ticket.title??"\u5DE5\u5355\u8BE6\u60C5"],hints:_,onEscape:C,isActive:b===null,children:Ht(V,{state:k,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:n,children:({site:L,detail:P})=>{let B=S??P,J=B.ticket,oe=J.status==="closed";if(r==="confirm-close")return Ht(Ae,{width:n,title:"\u5173\u95ED\u5DE5\u5355",detail:`\u786E\u5B9A\u5173\u95ED\u5DE5\u5355\u300C${J.title}\u300D\u5417\uFF1F\u5173\u95ED\u540E\u53EF\u91CD\u65B0\u6253\u5F00`,confirmLabel:"\u5173\u95ED\u5DE5\u5355",busy:b,error:h,onConfirm:()=>T("\u6B63\u5728\u5173\u95ED",()=>Ag(e.id),{onSuccess:()=>{i("main"),t.reload(),t.toast("ok","\u5DF2\u5173\u95ED")}}),onCancel:C});if(r==="attachments")return u!==null?Ht(ur,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${u.fileName}`,width:n,download:async()=>({fileName:u.fileName,bytes:await Pg(e.id,u.id)}),onCancel:()=>m(null),onSaved:w=>{m(null),l(w),t.toast("ok","\u9644\u4EF6\u5DF2\u4FDD\u5B58")}}):jl(oa,{flexDirection:"column",children:[Ht(le,{width:n,height:Math.max(3,o-1),isActive:b===null,items:[{heading:"\u9644\u4EF6"},...B.messages.flatMap(w=>w.attachments.map(F=>({value:F,label:F.fileName,hint:`${vt(w.author)} \xB7 ${Ko(F.fileSize)} \xB7 ${K(w.createdAt)}`})))],onSelect:w=>{l(null),m(w)}}),c!==null&&Ht(ra,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${c}`})]});let fe=L.ticketAutoCloseMinutes>0?Ig:0,$=oe?Sk:s?bk:Ig,ne=Math.max(3,o-fe-$-X);return jl(oa,{flexDirection:"column",children:[fe>0&&Ht(ra,{wrap:"truncate",color:f.faintForeground,children:`\u7BA1\u7406\u5458\u56DE\u590D\u540E\u8D85\u8FC7 ${L.ticketAutoCloseMinutes} \u5206\u949F\u672A\u56DE\u5E94\uFF0C\u5DE5\u5355\u5C06\u81EA\u52A8\u5173\u95ED\uFF1B\u5DF2\u5173\u95ED\u7684\u5DE5\u5355\u53EF\u968F\u65F6\u91CD\u65B0\u6253\u5F00`}),Ht(pt,{lines:xk(B.messages,n),height:ne,isActive:!s&&b===null,pinBottom:!0}),Ht(oa,{marginTop:1,flexDirection:"column",children:oe?jl(oa,{flexDirection:"column",children:[Ht(ra,{color:f.mutedForeground,children:"\u5DE5\u5355\u5DF2\u5173\u95ED\uFF0C\u5982\u9700\u7EE7\u7EED\u6C9F\u901A\u53EF\u91CD\u65B0\u6253\u5F00"}),Ht(le,{width:n,isActive:b===null,items:[{value:"reopen",label:"\u91CD\u65B0\u6253\u5F00"}],onSelect:()=>T("\u6B63\u5728\u91CD\u65B0\u6253\u5F00",()=>Eg(e.id),{failToast:!0,onSuccess:()=>{t.reload(),t.toast("ok","\u5DF2\u91CD\u65B0\u6253\u5F00")}})})]}):s?Ht(te,{title:"\u56DE\u590D\u5DE5\u5355",width:n,submitLabel:"\u53D1\u9001\u56DE\u590D",busy:b!==null,busyLabel:b??"\u6B63\u5728\u53D1\u9001",error:h,fields:[{kind:"textarea",name:"content",label:"\u56DE\u590D\u5185\u5BB9",rows:3,maxLength:5e3,placeholder:"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9",optional:!0},Zn(dr)],onCancel:()=>a(!1),onSubmit:w=>{let F=(w.content??"").trim(),re;try{re=Jn(w.attachments??"",dr)}catch(D){x(xe(D));return}if(F===""&&re.length===0){x("\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9\u6216\u9644\u4EF6\u8DEF\u5F84");return}v(F,re)}},p):Ht(ra,{color:f.faintForeground,children:"\u6309 Tab \u64B0\u5199\u56DE\u590D"})})]})}})})}import{Box as Tk}from"ink";import{useState as wk}from"react";import{jsx as Co,jsxs as Ck}from"react/jsx-runtime";var kk=_t(ec,Hc,"\u5168\u90E8\u72B6\u6001"),vk={title:"\u7B80\u8981\u63CF\u8FF0\u4F60\u7684\u95EE\u9898",content:"\u8BE6\u7EC6\u63CF\u8FF0\u9047\u5230\u7684\u95EE\u9898\uFF0C\u4FBF\u4E8E\u7BA1\u7406\u5458\u5FEB\u901F\u5B9A\u4F4D"},Hl={billing:{title:"\u7B80\u8FF0\u8BA1\u8D39\u6216\u989D\u5EA6\u7591\u95EE",content:"\u8BF4\u660E\u7591\u95EE\u6D89\u53CA\u7684\u65F6\u95F4\u6BB5\u3001\u6A21\u578B\u4E0E\u9884\u671F\u5DEE\u5F02\uFF0C\u53EF\u9644\u989D\u5EA6\u6D41\u6C34\u6216\u4F7F\u7528\u65E5\u5FD7\u4E2D\u7684\u8BB0\u5F55"},technical:{title:"\u7B80\u8FF0\u63A5\u53E3\u6216\u8C03\u7528\u95EE\u9898",content:"\u63CF\u8FF0\u62A5\u9519\u73B0\u8C61\u4E0E\u590D\u73B0\u6B65\u9AA4\uFF0C\u9644\u8BF7\u6C42 ID\u3001\u6A21\u578B\u540D\u3001\u53D1\u751F\u65F6\u95F4\u7B49\u4FE1\u606F"},account:{title:"\u7B80\u8FF0\u8D26\u53F7\u76F8\u5173\u95EE\u9898",content:"\u63CF\u8FF0\u767B\u5F55\u3001\u90AE\u7BB1\u6216\u5B89\u5168\u76F8\u5173\u7684\u5177\u4F53\u95EE\u9898\uFF0C\u5207\u52FF\u586B\u5199\u5BC6\u7801\u7B49\u654F\u611F\u4FE1\u606F"},other:vk};function Lg(){let e=O(),{width:t}=j(),n=Z(),[o,r]=wk({name:"list"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=ue(),p=ze([e.revision,i],h=>Cg({page:h,...i===""?{}:{status:i}}),{retain:"page"}),d=o.name==="list";G((h,g)=>{d&&(h==="r"?e.reload():h==="f"?r({name:"filter"}):h==="n"?r({name:"create-category"}):g.leftArrow?p.go(-1):g.rightArrow&&p.go(1))});let b=()=>{o.name==="list"?e.pop():o.name==="create"?r({name:"create-category"}):(l(),r({name:"list"}))};return Co(Y,{hints:d?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","n \u65B0\u5EFA","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:b,children:o.name==="filter"?Co(te,{title:"\u7B5B\u9009\u5DE5\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:kk,initial:i}],onCancel:b,onSubmit:h=>{s(h.status??""),p.reset(),r({name:"list"})}}):o.name==="create-category"?Co(le,{width:t,height:n,items:[{heading:"\u5206\u7C7B"},...tc.map(h=>({value:h,label:Ji(h),hint:Hl[h].title}))],onSelect:h=>r({name:"create",category:h})}):o.name==="create"?Co(te,{title:`\u65B0\u5EFA\u5DE5\u5355 \u2014 ${Ji(o.category)}`,width:t,submitLabel:"\u63D0\u4EA4",busy:a!==null,busyLabel:a??"\u6B63\u5728\u63D0\u4EA4",error:c,fields:[{kind:"select",name:"priority",label:"\u4F18\u5148\u7EA7",options:nc.map(h=>({value:h,label:qc(h).label})),initial:"normal"},{kind:"text",name:"title",label:"\u6807\u9898",placeholder:Hl[o.category].title},{kind:"textarea",name:"content",label:"\u95EE\u9898\u63CF\u8FF0",rows:5,maxLength:5e3,placeholder:Hl[o.category].content},Zn(dr)],onCancel:b,onSubmit:h=>{let g=(h.title??"").trim(),x=(h.content??"").trim();if(g===""){u("\u8BF7\u586B\u5199\u6807\u9898");return}if(x===""){u("\u8BF7\u586B\u5199\u95EE\u9898\u63CF\u8FF0");return}let T;try{T=Jn(h.attachments??"",dr)}catch(k){u(xe(k));return}m("\u6B63\u5728\u63D0\u4EA4\u5DE5\u5355",()=>Mn(T,ta,k=>Rg({title:g,category:o.category,priority:h.priority??"normal",content:x,attachmentIds:k.map(S=>S.id)})),{onSuccess:k=>{r({name:"list"}),p.reset(),e.reload(),e.push("ticket",{id:k.id}),e.toast("ok","\u5DE5\u5355\u5DF2\u63D0\u4EA4")}})}}):Co(V,{state:p.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:t,children:h=>Ck(Tk,{flexDirection:"column",children:[Co(de,{retain:"list",items:h.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},{label:"\u4F18\u5148\u7EA7"},{label:"\u5206\u7C7B"},{label:"\u6700\u540E\u66F4\u65B0"},{label:"\u72B6\u6001",align:"right"}],row:g=>[g.title,yt(qc(g.priority)),Ji(g.category),K(g.updatedAt),yt(Hc(g.status))],onOpen:g=>e.push("ticket",{id:g.id}),emptyLabel:i===""?"\u6682\u65E0\u5DE5\u5355":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u9047\u5230\u95EE\u9898\u65F6\u53EF\u65B0\u5EFA\u5DE5\u5355\uFF0C\u7BA1\u7406\u5458\u4F1A\u5C3D\u5FEB\u56DE\u590D":void 0}),Co(We,{page:p.page,pages:p.pages,total:p.total,width:t})]})})})}import{Box as Rk}from"ink";import{jsx as gi}from"react/jsx-runtime";function Og({params:e}){let t=O(),{width:n}=j(),o=Z(),r=Q([e.type,t.revision],()=>kg(t.ctx.site,e.type));return gi(Y,{trail:["\u6CD5\u5F8B\u6761\u6B3E",e.type==="terms"?"\u7528\u6237\u534F\u8BAE":"\u9690\u79C1\u653F\u7B56"],hints:["\u2191\u2193 \u6EDA\u52A8"],children:gi(V,{state:r,loading:"\u6B63\u5728\u8BFB\u53D6\u6761\u6B3E",width:n,children:i=>i.configured?gi(Rk,{flexDirection:"column",children:gi(pt,{lines:hn(i.content,n),height:o})}):gi(ye,{tone:"info",width:n,title:"\u8BE5\u6761\u6B3E\u5C1A\u672A\u914D\u7F6E"})})})}var Dg=(e,t)=>fn(se,`${e}/api/auth/send-code`,{json:t});async function $g(e,t){let n=await Jt(`${e}/api/auth/register`,{json:t});sn(n);let o=zo.parse(n.data);return Wr(e,zr({refresh:null,device:null},n.headers),o)}var Bg=(e,t)=>fn(se,`${e}/api/auth/forgot-password`,{json:t}),Fg=(e,t)=>fn(se,`${e}/api/auth/reset-password`,{json:t});import{jsx as Ug}from"react/jsx-runtime";function jg(){let e=O(),{width:t}=j(),{busy:n,error:o,fail:r,run:i}=ue();return Re(n!==null),Ug(Y,{trail:["\u627E\u56DE\u5BC6\u7801"],isActive:n===null,children:Ug(te,{title:"\u91CD\u7F6E\u5BC6\u7801",width:t,submitLabel:"\u63D0\u4EA4",busy:n!==null,busyLabel:n??"\u6B63\u5728\u91CD\u7F6E",error:o,fields:[{kind:"text",name:"email",label:"\u90AE\u7BB1",placeholder:"\u8BF7\u8F93\u5165\u6CE8\u518C\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",placeholder:"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801",emailField:"email",send:s=>Bg(e.ctx.site,{email:s})},{kind:"text",name:"password",label:"\u65B0\u5BC6\u7801",mask:!0,placeholder:`\u81F3\u5C11 ${Ot} \u4F4D`,hint:"\u91CD\u7F6E\u540E\u6240\u6709\u8BBE\u5907\u90FD\u9700\u91CD\u65B0\u767B\u5F55"}],onCancel:()=>e.pop(),onSubmit:s=>{let a=(s.email??"").trim(),c=(s.code??"").trim(),l=s.password??"";if(a===""||c===""){r("\u8BF7\u586B\u5199\u90AE\u7BB1\u4E0E\u9A8C\u8BC1\u7801");return}if(l.length<Ot){r(`\u65B0\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}i("\u6B63\u5728\u91CD\u7F6E",()=>Fg(e.ctx.site,{email:a,code:c,password:l}),{onSuccess:()=>{e.toast("ok","\u5BC6\u7801\u5DF2\u91CD\u7F6E\uFF0C\u8BF7\u767B\u5F55"),e.pop()}})}})})}import{Box as Gl,Text as Pk}from"ink";import{useState as qg}from"react";import{Box as Hg}from"ink";import{jsx as ql,jsxs as _k}from"react/jsx-runtime";var ia=e=>e.termsConfigured||e.privacyConfigured;function sa({legal:e,width:t,onAgree:n}){let o=O(),r=[e.termsConfigured?"\u300A\u7528\u6237\u534F\u8BAE\u300B":"",e.privacyConfigured?"\u300A\u9690\u79C1\u653F\u7B56\u300B":""].filter(s=>s!==""),i=[{value:"agree",label:"\u6211\u5DF2\u9605\u8BFB\u5E76\u540C\u610F\uFF0C\u7EE7\u7EED",hint:r.join("\u4E0E")},...e.termsConfigured?[{value:"terms",label:"\u67E5\u770B\u7528\u6237\u534F\u8BAE"}]:[],...e.privacyConfigured?[{value:"privacy",label:"\u67E5\u770B\u9690\u79C1\u653F\u7B56"}]:[],{value:"back",label:"\u8FD4\u56DE"}];return _k(Hg,{flexDirection:"column",children:[ql(ye,{tone:"info",width:t,title:`\u7EE7\u7EED\u524D\u8BF7\u9605\u8BFB\u5E76\u540C\u610F${r.join("\u4E0E")}`}),ql(Hg,{marginTop:1,children:ql(le,{items:i,width:t,onSelect:s=>{s==="agree"?n():s==="terms"?o.push("agreement",{type:"terms"}):s==="privacy"?o.push("agreement",{type:"privacy"}):o.pop()}})})]})}import{jsx as eo,jsxs as Gg}from"react/jsx-runtime";function zg(){let e=O(),{width:t}=j(),[n,o]=qg({name:"credentials"}),[r,i]=qg(!1),{busy:s,error:a,reset:c,fail:l,run:u}=ue(),m=Q([e.revision],()=>Ge(e.ctx.site)),p=g=>{e.gate.announcementsChecked=!1,e.gate.announcementsShown=!1,e.toast("ok",`\u5DF2\u767B\u5F55\uFF1A${g}`),e.home()},d=(g,x)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Od(e.ctx.site,g,x),{onSuccess:T=>{if(T.status==="totp_required"){o({name:"factor",ticket:T.ticket,jar:T.jar});return}p(T.session.username)}})},b=(g,x)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Dd(e.ctx.site,g.jar,g.ticket,x,g.kind),{onSuccess:T=>p(T.username)})},h=()=>{n.name==="credentials"?e.pop():(c(),o({name:"credentials"}))};return Gg(Y,{trail:n.name==="credentials"?["\u767B\u5F55\u8D26\u53F7"]:["\u767B\u5F55\u8D26\u53F7","\u4E24\u6B65\u9A8C\u8BC1"],onEscape:h,isActive:s===null,children:[n.name==="credentials"&&eo(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:g=>ia(g.legal)&&!r?eo(sa,{legal:g.legal,width:t,onAgree:()=>i(!0)}):Gg(Gl,{flexDirection:"column",children:[eo(te,{title:"\u767B\u5F55",width:t,submitLabel:"\u767B\u5F55",error:a,busy:s!==null,busyLabel:s??"\u6B63\u5728\u9A8C\u8BC1",fields:[{kind:"text",name:"account",label:"\u8D26\u53F7",placeholder:"\u8BF7\u8F93\u5165\u7528\u6237\u540D\u6216\u90AE\u7BB1"},{kind:"text",name:"password",label:"\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5BC6\u7801"}],onCancel:h,onSubmit:x=>{let T=(x.account??"").trim(),k=x.password??"";if(T===""||k===""){l("\u8BF7\u586B\u5199\u8D26\u53F7\u4E0E\u5BC6\u7801");return}d(T,k)}}),eo(Gl,{marginTop:1,children:eo(Pk,{color:f.faintForeground,children:"Passkey \u767B\u5F55\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"})})]})}),n.name==="factor"&&eo(le,{width:t,items:[{value:"totp",label:"\u52A8\u6001\u9A8C\u8BC1\u7801",hint:"\u8F93\u5165\u9A8C\u8BC1\u5668 App \u4E2D\u663E\u793A\u7684\u52A8\u6001\u9A8C\u8BC1\u7801"},{value:"recovery-code",label:"\u6062\u590D\u7801",hint:"\u8F93\u5165\u672A\u4F7F\u7528\u8FC7\u7684\u4E00\u6B21\u6027\u6062\u590D\u7801"}],onSelect:g=>o({name:"code",ticket:n.ticket,jar:n.jar,kind:g})}),n.name==="code"&&eo(Gl,{flexDirection:"column",children:eo(te,{title:"\u4E24\u6B65\u9A8C\u8BC1",width:t,submitLabel:"\u9A8C\u8BC1\u5E76\u767B\u5F55",error:a,busy:s!==null,busyLabel:s??"\u6B63\u5728\u9A8C\u8BC1",fields:[{kind:"text",name:"code",label:n.kind==="totp"?"\u52A8\u6001\u9A8C\u8BC1\u7801":"\u6062\u590D\u7801",placeholder:n.kind==="totp"?"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801":"\u8BF7\u8F93\u5165\u6062\u590D\u7801",hint:n.kind==="totp"?"\u8F93\u5165\u9A8C\u8BC1\u5668 App \u4E2D\u663E\u793A\u7684\u52A8\u6001\u9A8C\u8BC1\u7801":"\u8F93\u5165\u672A\u4F7F\u7528\u8FC7\u7684\u4E00\u6B21\u6027\u6062\u590D\u7801"}],onCancel:h,onSubmit:g=>{let x=(g.code??"").trim();if(x===""){l("\u8BF7\u586B\u5199\u9A8C\u8BC1\u7801");return}b(n,x)}})})]})}import{useState as Ak}from"react";import{jsx as aa}from"react/jsx-runtime";function Wg(){let e=O(),{width:t}=j(),[n,o]=Ak(!1),{busy:r,error:i,fail:s,run:a}=ue(),c=Q([e.revision],()=>Ge(e.ctx.site));return aa(Y,{trail:["\u6CE8\u518C\u8D26\u53F7"],isActive:r===null,children:aa(V,{state:c,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:l=>ia(l.legal)&&!n?aa(sa,{legal:l.legal,width:t,onAgree:()=>o(!0)}):aa(te,{title:"\u6CE8\u518C",width:t,submitLabel:"\u6CE8\u518C",busy:r!==null,busyLabel:r??"\u6B63\u5728\u6CE8\u518C",error:i,fields:[{kind:"text",name:"username",label:"\u7528\u6237\u540D",placeholder:"\u8BF7\u8F93\u5165\u7528\u6237\u540D"},{kind:"text",name:"email",label:"\u90AE\u7BB1",placeholder:"\u8BF7\u8F93\u5165\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",placeholder:"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801",emailField:"email",send:u=>Dg(e.ctx.site,{email:u})},{kind:"text",name:"password",label:"\u5BC6\u7801",mask:!0,placeholder:`\u81F3\u5C11 ${Ot} \u4F4D`},{kind:"text",name:"invite",label:"\u9080\u8BF7\u7801",placeholder:"\u8BF7\u8F93\u5165\u9080\u8BF7\u7801",optional:!0}],onCancel:()=>e.pop(),onSubmit:u=>{let m=(u.username??"").trim(),p=(u.email??"").trim(),d=(u.code??"").trim(),b=u.password??"",h=(u.invite??"").trim();if(m===""||m.length>Kt){s(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}if(p===""||d===""){s("\u8BF7\u586B\u5199\u90AE\u7BB1\u4E0E\u9A8C\u8BC1\u7801");return}if(b.length<Ot){s(`\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}a("\u6B63\u5728\u6CE8\u518C",()=>$g(e.ctx.site,{username:m,email:p,password:b,code:d,...h===""?{}:{inviteCode:h}}),{onSuccess:g=>{e.gate.announcementsChecked=!1,e.gate.announcementsShown=!1,e.toast("ok",`\u6CE8\u518C\u6210\u529F\uFF1A${g.username}`),e.home()}})}})})})}import{Box as hi}from"ink";import{useState as Ek}from"react";import{jsx as It,jsxs as Kg}from"react/jsx-runtime";var Mk=["category","title","content","attachments"],Ik=11,Nk=2,Lk=3,Ok=16,Vg={new:"\u53D1\u5E03\u5E16\u5B50",draft:"\u7F16\u8F91\u8349\u7A3F",edit:"\u7F16\u8F91\u5E16\u5B50"};function Dk(e){return e.kind==="edit"?{category:String(e.post.category.id),title:e.post.title,content:e.post.content,attachments:""}:e.kind==="draft"?{category:e.draft.category===null?"":String(e.draft.category.id),title:e.draft.title,content:e.draft.content,attachments:""}:{category:"",title:"",content:"",attachments:""}}function $k(e,t){return e.find(n=>String(n.id)===t)?.description}function Yg({mode:e}){let t=O(),{width:n}=j(),o=Z(),r=Dk(e),[i,s]=Me("values",()=>r),[a,c]=Ek(!1),{busy:l,error:u,fail:m,reset:p,run:d}=ue(),b=Q([],Os),h=Mk.some(E=>(i[E]??"")!==(r[E]??""));Re(h||l!==null);let g=E=>{let W=E.category??"";return{categoryId:W===""?null:Number(W),title:(E.title??"").trim(),content:(E.content??"").trim()}},x=(E,W)=>{let M;try{M=Jn(E.attachments??"",Ws)}catch(C){return m(xe(C)),null}return jt(W).length+M.length>Ws.maxCount?(m("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650"),null):M},T=async E=>{switch(e.kind){case"new":return(await uf(E)).id;case"draft":return await gf(e.draft.id,E),e.draft.id;case"edit":return await df(e.post.id,E),e.post.id}},k=E=>{if(e.kind==="edit"&&!h){m("\u5185\u5BB9\u672A\u4FEE\u6539");return}let{categoryId:W,title:M,content:C}=g(E);if(W===null){m("\u8BF7\u9009\u62E9\u677F\u5757");return}if(M===""){m("\u8BF7\u586B\u5199\u6807\u9898");return}if(M.length>mo){m(`\u6807\u9898\u6700\u591A ${mo} \u4E2A\u5B57\u7B26`);return}let v=x(E,C);if(v!==null){if(C===""&&v.length===0){m("\u8BF7\u586B\u5199\u6B63\u6587");return}d("\u6B63\u5728\u63D0\u4EA4",()=>Mn(v,si,_=>T({categoryId:W,title:M,content:di(C,_)})),{onSuccess:_=>{t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838"),t.pop(),e.kind!=="edit"&&t.push("post",{id:_})}})}},S=(E,W)=>{let{categoryId:M,title:C,content:v}=g(E);if(C.length>mo){m(`\u6807\u9898\u6700\u591A ${mo} \u4E2A\u5B57\u7B26`);return}let _=x(E,v);_!==null&&d("\u6B63\u5728\u4FDD\u5B58\u8349\u7A3F",()=>Mn(_,si,async L=>{let P={categoryId:M,title:C,content:di(v,L)};W===null?await pf(P):await ff(W,P)}),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5B58\u8349\u7A3F")}})},y=e.kind==="draft"?e.draft.id:null,R=()=>{if(!h){t.pop();return}p(),c(!0)},N=()=>{if(!a){t.pop();return}p(),c(!1)};return G(E=>{E==="q"&&h&&R()},!a&&l===null),It(Y,{trail:["\u793E\u533A\u8BBA\u575B",Vg[e.kind]],onEscape:N,isActive:l===null,children:It(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u677F\u5757",width:n,children:E=>{if(a&&e.kind==="edit")return It(Ae,{width:n,title:"\u653E\u5F03\u4FEE\u6539",detail:"\u4FEE\u6539\u5C1A\u672A\u63D0\u4EA4\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F",confirmLabel:"\u653E\u5F03\u4FEE\u6539",onConfirm:t.pop,onCancel:N});if(a)return Kg(hi,{flexDirection:"column",children:[It(ye,{tone:"warn",width:n,title:"\u4FDD\u5B58\u8349\u7A3F",detail:"\u5185\u5BB9\u5C1A\u672A\u53D1\u5E03\uFF0C\u662F\u5426\u5B58\u4E3A\u8349\u7A3F\uFF1F"}),u!==null&&It(hi,{marginTop:1,children:It(Ft,{message:u.message,hint:u.hint,width:n})}),It(hi,{marginTop:1,children:l!==null?It(Oe,{label:l}):It(le,{width:n,items:[{value:"save",label:"\u5B58\u8349\u7A3F"},{value:"stay",label:"\u7EE7\u7EED\u7F16\u8F91"},{value:"discard",label:"\u4E0D\u4FDD\u5B58",labelTone:"danger"}],onSelect:L=>{L==="save"?S(i,y):L==="stay"?N():t.pop()}})})]});let W=e.kind==="edit"?0:1,M=e.kind==="edit"&&e.post.status==="published",C=M?Nk:0,v=Math.min(Ok,Math.max(Lk,o-Ik-W-C-pi(u))),_=i.category??"";return Kg(hi,{flexDirection:"column",children:[M&&It(hi,{marginBottom:1,children:It(ye,{tone:"info",width:n,title:"\u4FEE\u6539\u540E\u9700\u91CD\u65B0\u5BA1\u6838\uFF0C\u5BA1\u6838\u671F\u95F4\u5E16\u5B50\u6682\u65F6\u9690\u85CF"})}),It(te,{title:Vg[e.kind],width:n,submitLabel:e.kind==="edit"?"\u63D0\u4EA4\u4FEE\u6539":"\u53D1\u5E03",busy:l!==null,busyLabel:l??"\u6B63\u5728\u63D0\u4EA4",error:u,fields:[{kind:"select",name:"category",label:"\u677F\u5757",options:[..._===""?[{value:"",label:"\u8BF7\u9009\u62E9\u677F\u5757"}]:[],...E.map(L=>({value:String(L.id),label:L.name}))],initial:i.category,hint:L=>$k(E,L)},{kind:"text",name:"title",label:"\u6807\u9898",initial:i.title,placeholder:"\u8BF7\u8F93\u5165\u5E16\u5B50\u6807\u9898"},{kind:"textarea",name:"content",label:"\u6B63\u6587",rows:v,maxLength:Di,initial:i.content,placeholder:"\u8BF7\u8F93\u5165\u6B63\u6587\uFF0C\u652F\u6301 Markdown"},{...Zn(Ws),initial:i.attachments}],secondary:e.kind==="edit"?void 0:{label:"\u5B58\u8349\u7A3F",onSubmit:L=>S(L,y)},onChange:s,onCancel:R,onSubmit:k})]})}})})}function Jg({params:e}){return It(Yg,{mode:e.draft===null?{kind:"new"}:{kind:"draft",draft:e.draft}})}function Xg({params:e}){return It(Yg,{mode:{kind:"edit",post:e.post}})}import{Box as to,Text as zl}from"ink";import{useEffect as Wl,useMemo as Qg,useState as ca}from"react";import{useRef as Bk}from"react";function qt(e){let t=Bk(null);return e.phase==="ready"&&(t.current={data:e.data}),e.phase==="error"&&(t.current=null),e.phase==="loading"&&t.current!==null?{phase:"ready",data:t.current.data}:e}import{jsx as Ee,jsxs as Vl}from"react/jsx-runtime";var la={kind:"floor"},Fk=2,Zg=3,Uk=4,nh=2,eh=3,th="PgUp PgDn \u6EDA\u52A8\u6B63\u6587",ma=(e,t)=>{let n=Xs(Jo,e.status,e.reviewReason,t);return n===0?0:n+1};function jk(e,t,n,o,r){let i=Math.max(nh+eh,o-Fk-ma(e,r)-3),s=Math.max(eh,Math.min(Uk,i-Zg)),a=Math.min(Zg,i-s),c=Math.min(1+Math.max(2,n),Math.max(s,Math.floor(i/2))),l=Math.min(t.length,Math.max(a,i-c));return{bodyRows:l,listRows:i-l}}function Hk(e,t,n,o,r){let i=o-Xe-1-ma(e,r)-2-n;return Math.min(t.length,Math.max(nh,i))}function qk(e,t,n,o){let r=e.status==="published"&&t.status==="published"&&n.status==="published",i=Ln(n.author,o);return[...r&&!i?[{value:"like",label:n.liked?"\u53D6\u6D88\u70B9\u8D5E":"\u70B9\u8D5E"}]:[],...r?[{value:"reply",label:"\u56DE\u590D"}]:[],...r&&!i?[{value:"report",label:"\u4E3E\u62A5"}]:[],...jt(n.content).length>0?[{value:"attachments",label:"\u9644\u4EF6"}]:[],{value:"author",label:"\u7528\u6237\u4E3B\u9875",hint:vt(n.author)},...i?[{value:"delete",label:"\u5220\u9664",labelTone:"danger"}]:[]]}function oh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=ca({name:"main"}),[s,a]=ca(null),{busy:c,error:l,reset:u,run:m}=ue();Re(r.name==="confirm-delete"&&c!==null);let p=qt(Q([e.postId,e.floorId,t.revision],async()=>{let[w,F,re,D]=await Promise.all([Ds(e.postId),nf(e.postId,e.floorId),En(),sr()]);return{post:w,floor:F,me:re.user,muted:D.muted}})),d=ze([e.floorId,t.revision],w=>of(e.floorId,w),{retain:"replies-page"}),b=qt(d.state),h=p.phase==="ready"?p.data:null,g=b.phase==="ready"?b.data:null,[x,T]=ca(void 0);Wl(()=>T(void 0),[h]);let[k,S]=ca(new Map);Wl(()=>S(new Map),[g]);let y=h===null?null:{...h,floor:{...h.floor,...x}},R=g===null?[]:g.items.map(w=>({...w,...k.get(w.id)})),N=yg(cd(R)),E=r.name==="actions"?R.find(w=>w.id===r.id)??null:null,W=s!==null&&R.some(w=>w.id===s);Wl(()=>{W&&a(null)},[W]);let M=y===null?null:y.floor.content,C=Qg(()=>M===null?[]:ui(M,n),[M,n]),v=E===null?null:E.content,_=Qg(()=>v===null?[]:ui(v,n-ge),[v,n]),L=y===null?null:jk(y.floor,C,R.length,o-pr(y.muted,n),n),P=y===null||E===null?null:qk(y.post,y.floor,E,y.me.username),B=E===null||P===null?null:Hk(E,_,P.length,o,n-ge),J=w=>y===null?null:w.kind==="floor"?y.floor:R.find(F=>F.id===w.id)??null,oe=(w,F)=>{m(w.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>Sf(w.id,!w.liked),{failToast:!0,onSuccess:({likeCount:re})=>F({liked:!w.liked,likeCount:re})})};G((w,F)=>{if(y===null||r.name!=="main"||c!==null)return;let{post:re,floor:D,me:z}=y,ee=re.status==="published"&&D.status==="published",he=Ln(D.author,z.username);w==="r"?t.reload():F.leftArrow?d.go(-1):F.rightArrow?d.go(1):w==="c"&&ee?i({name:"reply",target:la}):w==="l"&&ee&&!he?oe(D,T):w==="p"&&ee&&!he?i({name:"report",target:la}):w==="a"&&jt(D.content).length>0?i({name:"attachments",target:la}):w==="u"?t.push("homepage",{author:mi(D.author)}):w==="d"&&he&&(u(),i({name:"confirm-delete",target:la}))});let fe=()=>{if(r.name==="main"){t.pop();return}if(u(),r.name!=="actions"&&r.target.kind==="reply"){i({name:"actions",id:r.target.id});return}i({name:"main"})},$=(w,F)=>{let re={kind:"reply",id:w.id};F==="like"?oe(w,D=>S(z=>new Map(z).set(w.id,D))):F==="reply"?i({name:"reply",target:re}):F==="report"?i({name:"report",target:re}):F==="attachments"?i({name:"attachments",target:re}):F==="author"?t.push("homepage",{author:mi(w.author)}):(u(),i({name:"confirm-delete",target:re}))};return Ee(Y,{trail:["\u793E\u533A\u8BBA\u575B","\u697C\u5C42\u8BE6\u60C5"],hints:(()=>{if(y===null)return[];if(r.name==="actions")return B===null?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C",..._.length>B?[th]:[]];if(r.name!=="main"||L===null)return[];let{post:w,floor:F,me:re}=y,D=w.status==="published"&&F.status==="published",z=Ln(F.author,re.username);return[...R.length>0?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C"]:[],...C.length>L.bodyRows?[th]:[],...D?["c \u56DE\u590D"]:[],...D&&!z?[F.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E","p \u4E3E\u62A5"]:[],...jt(F.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...z?["d \u5220\u9664"]:[],"r \u5237\u65B0"]})(),onEscape:fe,isActive:r.name==="main"||c===null,children:Ee(V,{state:p,loading:"\u6B63\u5728\u8BFB\u53D6\u697C\u5C42",width:n,children:({post:w,floor:F,me:re,muted:D})=>{let z={...F,...x},ee=ie=>`${Ln(ie.author,re.username)?"\u83B7\u8D5E":ie.liked?"\u5DF2\u8D5E":"\u70B9\u8D5E"} ${ie.likeCount}`;if(r.name==="actions"){if(E===null||P===null||B===null)return Ee(ye,{tone:"info",width:n,title:"\u8BE5\u56DE\u590D\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"});let ie=n-ge;return Vl(pe,{title:vt(E.author),note:K(E.createdAt),width:n,children:[Ee(zl,{wrap:"truncate",color:f.mutedForeground,children:_e([E.replyTo!==null&&`\u56DE\u590D ${Ks(E.replyTo.author)}`,ee(E)])}),ma(E,ie)>0&&Ee(to,{marginTop:1,children:Ee(vo,{notices:Jo,status:E.status,reason:E.reviewReason,width:ie})}),Ee(to,{marginTop:1,children:Ee(pt,{lines:_,height:B,isActive:c===null,pageKeysOnly:!0})}),Ee(to,{marginTop:1,children:c!==null?Ee(Oe,{label:c}):Ee(le,{width:ie,items:P,onSelect:Qe=>$(E,Qe)})})]})}if(r.name!=="main"){let ie=J(r.target);if(ie===null)return Ee(ye,{tone:"info",width:n,title:"\u8BE5\u56DE\u590D\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"});if(r.name==="reply")return Ee(Qs,{postId:w.id,replyTo:{id:ie.id,mention:Ks(ie.author)},width:n,height:o,onCancel:fe,onDone:xt=>{i({name:"main"}),a(xt),d.last(),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838")}});if(r.name==="report")return Ee(Zs,{target:{kind:"comment",id:ie.id},width:n,onCancel:fe,onDone:()=>{fe(),t.toast("ok","\u5DF2\u63D0\u4EA4\u4E3E\u62A5")}});if(r.name==="attachments")return Ee(ea,{refs:jt(ie.content),width:n,height:o});let Qe=r.target.kind==="floor";return Ee(Ae,{width:n,title:Qe?"\u5220\u9664\u8BC4\u8BBA":"\u5220\u9664\u56DE\u590D",detail:Qe?"\u5220\u9664\u540E\u8BE5\u697C\u5C42\u53CA\u5176\u5168\u90E8\u56DE\u590D\u5C06\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u5417\uFF1F":"\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u8FD9\u6761\u56DE\u590D\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:c,error:l,onConfirm:()=>m("\u6B63\u5728\u5220\u9664",()=>yf(ie.id),{onSuccess:()=>{Qe?t.pop():(i({name:"main"}),t.reload()),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:fe})}if(L===null)return null;let he=c===null;return Vl(to,{flexDirection:"column",children:[Ee(ko,{muted:D,width:n}),Ee(zl,{bold:!0,wrap:"truncate",color:f.foreground,children:w.title}),c!==null?Ee(Oe,{label:c}):Ee(zl,{wrap:"truncate",color:f.mutedForeground,children:_e([z.floor!==null&&`#${z.floor}`,vt(z.author),K(z.createdAt),`\u56DE\u590D ${z.replyCount}`,ee(z)])}),ma(z,n)>0&&Ee(to,{marginTop:1,children:Ee(vo,{notices:Jo,status:z.status,reason:z.reviewReason,width:n})}),Ee(to,{marginTop:1,children:Ee(pt,{lines:C,height:L.bodyRows,isActive:he,pageKeysOnly:!0})}),Ee(to,{marginTop:1,children:Ee(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u56DE\u590D",width:n,children:()=>Vl(to,{flexDirection:"column",children:[Ee(de,{retain:"replies",items:N,width:n,height:L.listRows,isActive:he,columns:[Qn,{label:"\u56DE\u590D",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:({reply:ie,mention:Qe,prefix:xt})=>[`${xt}${vt(ie.author)}`,Qe===null?wo(ie.content):`\u56DE\u590D ${Ks(Qe)}\uFF1A${wo(ie.content)}`,String(ie.likeCount),K(ie.createdAt),ie.status==="published"?"":yt(po(ie.status))],onOpen:({reply:ie})=>i({name:"actions",id:ie.id}),select:s===null?void 0:({reply:ie})=>ie.id===s,emptyLabel:"\u6682\u65E0\u56DE\u590D",emptyDescription:w.status==="published"&&z.status==="published"?"\u6309 c \u56DE\u590D\u672C\u697C":void 0}),Ee(We,{page:d.page,pages:d.pages,total:d.total,width:n})]})})})]})}})})}import{Box as Ro,Text as pa}from"ink";import{Box as rh}from"ink";import{jsx as gr,jsxs as ih}from"react/jsx-runtime";function ua({author:e,owner:t,width:n,height:o}){let r=O(),i=ze([e.kind,e.username,r.revision],a=>sf(e,a),{retain:"posts-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),gr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:a=>ih(rh,{flexDirection:"column",children:[gr(de,{retain:"posts",items:a.items,width:n,height:Math.max(3,o-1),columns:[{label:"\u6807\u9898",shrink:!0},...t?[{label:"\u8BF4\u660E",shrink:!0}]:[],mr,{label:"\u56DE\u590D",align:"right"},{label:"\u6D4F\u89C8",align:"right"},{label:"\u70B9\u8D5E",align:"right"},t?{label:"\u65F6\u95F4"}:{label:"\u65F6\u95F4",align:"right"},...t?[{label:"\u72B6\u6001",align:"right"}]:[]],row:c=>[c.title,...t?[Nc(jr,c)??""]:[],c.category.name,String(c.commentCount),String(c.viewCount),String(c.likeCount),K(c.publishedAt??c.createdAt),...t?[yt(po(c.status))]:[]],onOpen:c=>r.push("post",{id:c.id}),emptyLabel:"\u6682\u65E0\u5E16\u5B50"}),gr(We,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}function da({author:e,owner:t,width:n,height:o}){let r=O(),i=ze([e.kind,e.username,r.revision],a=>af(e,a),{retain:"comments-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),gr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u8BC4\u8BBA",width:n,children:a=>ih(rh,{flexDirection:"column",children:[gr(de,{retain:"comments",items:a.items,width:n,height:Math.max(3,o-1),columns:[{label:"\u8BC4\u8BBA",shrink:!0},...t?[{label:"\u8BF4\u660E",shrink:!0}]:[],{label:"\u5E16\u5B50",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},...t?[{label:"\u72B6\u6001",align:"right"}]:[]],row:c=>[wo(c.content),...t?[Nc(Jo,c)??""]:[],c.post.title??Wi,String(c.likeCount),K(c.createdAt),...t?[yt(po(c.status))]:[]],onOpen:c=>r.push("floor",{postId:c.post.id,floorId:c.floorId}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA"}),gr(We,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}import{jsx as bt,jsxs as fa}from"react/jsx-runtime";var Gk=[{value:"posts",label:"\u5E16\u5B50"},{value:"comments",label:"\u8BC4\u8BBA"}],zk=3,Wk=2,Vk=5;function Kk({profile:e,owner:t,width:n,heatmapOn:o}){let{identity:r,stats:i}=e,s=e.activity.days.reduce((a,c)=>a+c.count,0);return fa(Ro,{flexDirection:"column",children:[fa(pa,{wrap:"truncate",children:[bt(pa,{bold:!0,color:f.foreground,children:st(r.username)}),bt(pa,{color:f.accent,children:` ${r.kind==="user"?qi(r.points):`[${zi}]`}`})]}),bt(pa,{wrap:"truncate",color:f.mutedForeground,children:_e([r.kind==="user"&&`${r.points} \u79EF\u5206`,t&&r.kind==="user"&&Gi(r.points),`\u52A0\u5165\u4E8E ${Ur(e.joinedAt)}`])}),bt(Ro,{marginTop:1,children:bt(it,{width:n,tiles:[{label:"\u5E16\u5B50",value:String(i.posts)},{label:"\u8BC4\u8BBA",value:String(i.comments)},{label:"\u83B7\u8D5E",value:String(i.likesReceived)}]})}),o&&fa(Ro,{marginTop:X,flexDirection:"column",children:[bt(Rn,{title:"\u793E\u533A\u8DB3\u8FF9",width:n}),bt(Ro,{marginTop:qe,flexDirection:"column",children:bt(lr,{data:e.activity,value:a=>a.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${s} \u6B21`,width:n})})]})]})}function sh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=Me("content",()=>"posts"),s=Q([e.author.kind,e.author.username,t.revision],async()=>{let[p,d]=await Promise.all([rf(e.author),En()]),b=e.author.kind==="user"&&e.author.username===d.user.username;return{profile:p,owner:b}});G(p=>{p==="r"?t.reload():p==="t"&&i(d=>d==="posts"?"comments":"posts")});let a=Wk+1+Ut(zk,n),c=o-a-2-1,l=X+Xe+To,u=cr(n)&&c-l>=Vk,m=Math.max(3,c-(u?l:0));return bt(Y,{trail:["\u793E\u533A\u8BBA\u575B","\u7528\u6237\u4E3B\u9875"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","t \u5207\u6362","r \u5237\u65B0"],children:bt(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u6237\u4E3B\u9875",width:n,children:({profile:p,owner:d})=>fa(Ro,{flexDirection:"column",children:[bt(Kk,{profile:p,owner:d,width:n,heatmapOn:u}),bt(Ro,{marginTop:1,children:bt(Fs,{options:Gk,value:r,onChange:i,arrowKeys:!1})}),bt(Ro,{marginTop:1,children:r==="posts"?bt(ua,{author:e.author,owner:d,width:n,height:m}):bt(da,{author:e.author,owner:d,width:n,height:m})})]})})})}import{Box as ah}from"ink";import{useState as Yk}from"react";import{jsx as _o,jsxs as lh}from"react/jsx-runtime";var Jk={sort:"activity",categoryId:"",q:"",author:""},ch=e=>e.categoryId!==""||e.q!==""||e.author!=="",Xk=(e,t)=>({page:t,sort:e.sort,...e.categoryId===""?{}:{categoryId:Number(e.categoryId)},...e.q===""?{}:{q:e.q},...e.author===""?{}:{author:e.author}});function mh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Yk(!1),[i,s]=Me("filters",()=>Jk),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[d,b]=await Promise.all([sr(),Os()]);return{muted:d.muted,categories:b}}),m=ze([e.revision,JSON.stringify(i)],d=>Zp(Xk(i,d)),{retain:"page"});G((d,b)=>{o||(d==="r"?e.reload():d==="f"?r(!0):d==="n"?e.push("compose",{draft:null}):b.leftArrow?m.go(-1):b.rightArrow&&m.go(1))});let p=()=>{if(!o){e.pop();return}l(),r(!1)};return _o(Y,{hints:o?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","n \u53D1\u5E03\u5E16\u5B50","f \u7B5B\u9009","r \u5237\u65B0"],onEscape:p,children:_o(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u793E\u533A",width:t,children:({muted:d,categories:b})=>o?_o(te,{title:"\u7B5B\u9009\u5E16\u5B50",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"select",name:"sort",label:"\u6392\u5E8F",options:oc.map(h=>({value:h,label:vd(h)})),initial:i.sort},{kind:"select",name:"category",label:"\u677F\u5757",options:[{value:"",label:"\u5168\u90E8\u677F\u5757"},...b.map(h=>({value:String(h.id),label:h.name}))],initial:i.categoryId},{kind:"text",name:"q",label:"\u5173\u952E\u8BCD",initial:i.q,placeholder:"\u641C\u7D22\u6807\u9898\u6216\u6B63\u6587"},{kind:"text",name:"author",label:"\u4F5C\u8005",initial:i.author,placeholder:"\u8F93\u5165\u4F5C\u8005\u5B8C\u6574\u7528\u6237\u540D"}],onCancel:p,onSubmit:h=>{let g=(h.q??"").trim(),x=(h.author??"").trim();if(g.length>Bi){c(`\u5173\u952E\u8BCD\u6700\u591A ${Bi} \u4E2A\u5B57\u7B26`);return}if(x.length>Kt){c(`\u7528\u6237\u540D\u6700\u591A ${Kt} \u4E2A\u5B57\u7B26`);return}s({sort:h.sort,categoryId:h.category??"",q:g,author:x}),m.reset(),l(),r(!1)}}):lh(ah,{flexDirection:"column",children:[_o(ko,{muted:d,width:t}),_o(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:t,children:h=>lh(ah,{flexDirection:"column",children:[_o(de,{retain:"list",items:h.items,width:t,height:Math.max(3,n-1-pr(d,t)),columns:[{label:"\u4E3B\u9898",shrink:!0},Qn,mr,{label:"\u56DE\u590D",align:"right"},{label:"\u6D4F\u89C8",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:g=>[g.title,vt(g.author),g.category.name,String(g.commentCount),String(g.viewCount),String(g.likeCount),K(g.lastActivityAt)],onOpen:g=>e.push("post",{id:g.id}),emptyLabel:ch(i)?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u5E16\u5B50",emptyDescription:ch(i)?void 0:"\u6309 n \u53D1\u5E03\u7B2C\u4E00\u7BC7\u5E16\u5B50"}),_o(We,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})})})}import{Box as ga}from"ink";import{useState as Qk}from"react";import{jsx as ft,jsxs as yh}from"react/jsx-runtime";var Zk=X+Xe+2,ev=X+2+1+2;function dh(){let e=O();G(t=>{t==="r"&&e.reload()})}function ph({params:e}){let{width:t}=j(),n=Z();return dh(),ft(Y,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u5E16\u5B50"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:ft(ua,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function fh({params:e}){let{width:t}=j(),n=Z();return dh(),ft(Y,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u8BC4\u8BBA"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:ft(da,{author:{kind:"user",username:e.username},owner:!0,width:t,height:n})})}function gh(){let e=O(),{width:t}=j(),n=Z(),o=ze([e.revision],r=>cf(r),{retain:"page"});return G((r,i)=>{r==="r"?e.reload():i.leftArrow?o.go(-1):i.rightArrow&&o.go(1)}),ft(Y,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u6536\u85CF"],hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"],children:ft(V,{state:o.state,loading:"\u6B63\u5728\u8BFB\u53D6\u6536\u85CF",width:t,children:r=>yh(ga,{flexDirection:"column",children:[ft(de,{retain:"list",items:r.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},Qn,{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:i=>[i.title,vt(i.author),String(i.commentCount),String(i.likeCount),K(i.lastActivityAt)],onOpen:i=>e.push("post",{id:i.id}),emptyLabel:"\u6682\u65E0\u6536\u85CF"}),ft(We,{page:o.page,pages:o.pages,total:o.total,width:t})]})})})}var uh=e=>e.title===""?"\u672A\u547D\u540D\u8349\u7A3F":e.title;function hh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Qk({name:"list"}),{busy:i,error:s,reset:a,run:c}=ue();Re(i!==null);let l=ze([e.revision],d=>lf(d),{retain:"page"}),u=o.name==="list";G((d,b)=>{u&&(d==="r"?e.reload():b.leftArrow?l.go(-1):b.rightArrow&&l.go(1))});let m=()=>{if(u){e.pop();return}a(),r({name:"list"})},p=o.name==="actions"?Zk:o.name==="confirm-delete"?ev+pi(s):0;return ft(Y,{trail:["\u4E2A\u4EBA\u4E3B\u9875","\u6211\u7684\u8349\u7A3F"],hints:u?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","\u2190\u2192 \u7FFB\u9875","r \u5237\u65B0"]:[],onEscape:m,isActive:i===null,children:ft(V,{state:l.state,loading:"\u6B63\u5728\u8BFB\u53D6\u8349\u7A3F",width:t,children:d=>yh(ga,{flexDirection:"column",children:[ft(de,{retain:"list",items:d.items,width:t,height:Math.max(3,n-1-p),isActive:u,columns:[{label:"\u6807\u9898",shrink:!0},mr,{label:"\u521B\u5EFA\u65F6\u95F4",align:"right"}],row:b=>[uh(b),b.category===null?"\u2014":b.category.name,K(b.createdAt)],onOpen:b=>r({name:"actions",draft:b}),emptyLabel:"\u6682\u65E0\u8349\u7A3F",emptyDescription:"\u53D1\u5E03\u5E16\u5B50\u65F6\u53EF\u9009\u62E9\u5B58\u4E3A\u8349\u7A3F"}),ft(We,{page:l.page,pages:l.pages,total:l.total,width:t}),o.name==="actions"&&ft(ga,{marginTop:X,children:ft(pe,{title:uh(o.draft),width:t,children:ft(le,{width:t-ge,items:[{value:"edit",label:"\u7EE7\u7EED\u7F16\u8F91"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:b=>{if(b==="edit"){r({name:"list"}),e.push("compose",{draft:o.draft});return}a(),r({name:"confirm-delete",draft:o.draft})}})})}),o.name==="confirm-delete"&&ft(ga,{marginTop:X,children:ft(Ae,{width:t,title:"\u5220\u9664\u8349\u7A3F",detail:"\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u8FD9\u7BC7\u8349\u7A3F\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:i,error:s,onConfirm:()=>c("\u6B63\u5728\u5220\u9664",()=>$s(o.draft.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:m})})]})})})}import{Box as Po,Text as Kl}from"ink";import{useEffect as ha,useMemo as tv,useRef as nv,useState as Yl}from"react";import{jsx as Ke,jsxs as Jl}from"react/jsx-runtime";var bh=2,ov=2,rv=2;function iv({post:e,width:t,height:n,isActive:o,follow:r,onFollowed:i}){let s=O(),a=ze([e.id,s.revision],u=>tf(e.id,u),{retain:"floors-page"}),c=qt(a.state),l=r!==null&&c.phase==="ready"&&c.data.items.some(u=>u.id===r);return ha(()=>{r!==null&&a.last()},[r]),ha(()=>{l&&i()},[l]),G((u,m)=>{m.leftArrow?a.go(-1):m.rightArrow&&a.go(1)},o),Ke(V,{state:c,loading:"\u6B63\u5728\u8BFB\u53D6\u697C\u5C42",width:t,children:u=>Jl(Po,{flexDirection:"column",children:[Ke(de,{retain:"floors",items:u.items,width:t,height:Math.max(3,n-1),isActive:o,columns:[{label:"\u697C\u5C42"},Qn,{label:"\u5185\u5BB9",shrink:!0},{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:m=>[m.floor===null?"\u2014":`#${m.floor}`,vt(m.author),wo(m.content),String(m.replyCount),String(m.likeCount),m.status==="published"?"":yt(po(m.status))],onOpen:m=>s.push("floor",{postId:e.id,floorId:m.id}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA",emptyDescription:e.status==="published"?"\u6309 c \u53D1\u8868\u7B2C\u4E00\u6761\u8BC4\u8BBA":void 0,select:r===null?void 0:m=>m.id===r}),Ke(We,{page:a.page,pages:a.pages,total:a.total,width:t})]})})}function Sh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=Me("mode",()=>"body"),[s,a]=Yl({name:"main"}),[c,l]=Yl(null),{busy:u,error:m,reset:p,run:d}=ue();Re(s.name==="confirm-delete"&&u!==null);let b=nv(null),h=qt(Q([e.id,t.revision],async()=>{let[M,C,v]=await Promise.all([Ds(e.id),En(),sr()]);return{post:M,me:C.user,muted:v.muted}})),g=h.phase==="ready"?h.data:null,[x,T]=Yl(null);ha(()=>T(null),[g]);let k=g===null?null:{...g,post:{...g.post,...x}},S=k!==null&&k.post.status==="published";ha(()=>{!S||b.current===e.id||(b.current=e.id,ef(e.id).catch(()=>t.toast("warn","\u6D4F\u89C8\u8BA1\u6570\u53D1\u9001\u5931\u8D25")))},[e.id,S]);let y=s.name==="main"&&u===null,R=k===null?null:k.post.content,N=tv(()=>R===null?[]:ui(R,n),[R,n]);G(M=>{if(k===null||!y)return;let{post:C,me:v}=k;if(M==="r"){t.reload();return}if(M==="v"){i(r==="body"?"floors":"body");return}if(M==="c"&&S){a({name:"comment"});return}if(r!=="body")return;let _=Ln(C.author,v.username),L={liked:C.liked,likeCount:C.likeCount,bookmarked:C.bookmarked};M==="l"&&S&&!_?d(C.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>bf(C.id,!C.liked),{failToast:!0,onSuccess:({likeCount:P})=>T({...L,liked:!C.liked,likeCount:P})}):M==="b"&&S?d(C.bookmarked?"\u6B63\u5728\u53D6\u6D88\u6536\u85CF":"\u6B63\u5728\u6536\u85CF",()=>xf(C.id,!C.bookmarked),{failToast:!0,onSuccess:()=>{T({...L,bookmarked:!C.bookmarked}),t.toast("ok",C.bookmarked?"\u5DF2\u53D6\u6D88\u6536\u85CF":"\u5DF2\u6536\u85CF")}}):M==="p"&&S&&!_?a({name:"report"}):M==="a"&&jt(C.content).length>0?a({name:"attachments"}):M==="u"?t.push("homepage",{author:mi(C.author)}):M==="e"&&_&&C.status!=="removed"?t.push("post-edit",{post:C}):M==="d"&&_&&(p(),a({name:"confirm-delete"}))});let E=()=>{if(s.name!=="main"){p(),a({name:"main"});return}if(r==="floors"){i("body");return}t.pop()},W=()=>{if(k===null||s.name!=="main")return[];let{post:M,me:C}=k;if(r==="floors")return["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...S?["c \u8BC4\u8BBA"]:[],"v \u6B63\u6587","r \u5237\u65B0"];let v=Ln(M.author,C.username);return["\u2191\u2193 \u6EDA\u52A8","v \u697C\u5C42\u5217\u8868",...S?["c \u8BC4\u8BBA",...v?[]:[M.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E"],M.bookmarked?"b \u53D6\u6D88\u6536\u85CF":"b \u6536\u85CF",...v?[]:["p \u4E3E\u62A5"]]:[],...jt(M.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...v&&M.status!=="removed"?["e \u7F16\u8F91\u5E16\u5B50"]:[],...v?["d \u5220\u9664"]:[],"r \u5237\u65B0"]};return Ke(Y,{trail:["\u793E\u533A\u8BBA\u575B",k===null?"\u5E16\u5B50\u8BE6\u60C5":k.post.category.name,...r==="floors"&&s.name==="main"?["\u697C\u5C42\u5217\u8868"]:[]],hints:W(),onEscape:E,isActive:s.name==="main"||u===null,children:Ke(V,{state:h,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:({post:M,me:C,muted:v})=>{let _={...M,...x},L=Ln(_.author,C.username);if(s.name==="comment")return Ke(Qs,{postId:_.id,replyTo:null,width:n,height:o,onCancel:E,onDone:fe=>{a({name:"main"}),i("floors"),l(fe),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838")}});if(s.name==="report")return Ke(Zs,{target:{kind:"post",id:_.id},width:n,onCancel:E,onDone:()=>{a({name:"main"}),t.toast("ok","\u5DF2\u63D0\u4EA4\u4E3E\u62A5")}});if(s.name==="attachments")return Ke(ea,{refs:jt(_.content),width:n,height:o});if(s.name==="confirm-delete")return Ke(Ae,{width:n,title:"\u5220\u9664\u5E16\u5B50",detail:"\u5220\u9664\u540E\u5E16\u5B50\u53CA\u5176\u5168\u90E8\u8BC4\u8BBA\u5C06\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:u,error:m,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>$s(_.id),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:E});let P=Ke(Kl,{bold:!0,wrap:"truncate",color:f.foreground,children:_.title}),B=pr(v,n);if(r==="floors")return Jl(Po,{flexDirection:"column",children:[Ke(ko,{muted:v,width:n}),P,Ke(Po,{marginTop:1,children:Ke(iv,{post:_,width:n,height:o-bh-B,isActive:y,follow:c,onFollowed:()=>l(null)})})]});let J=Xs(jr,_.status,_.reviewReason,n),oe=Math.max(rv,o-B-bh-(J===0?0:J+1)-1-ov);return Jl(Po,{flexDirection:"column",children:[Ke(ko,{muted:v,width:n}),P,Ke(Kl,{wrap:"truncate",color:f.mutedForeground,children:_e([vt(_.author),K(_.publishedAt??_.createdAt),_.editedAt!==null&&`\u7F16\u8F91\u4E8E ${K(_.editedAt)}`,`\u6D4F\u89C8 ${_.viewCount}`])}),J>0&&Ke(Po,{marginTop:1,children:Ke(vo,{notices:jr,status:_.status,reason:_.reviewReason,width:n})}),Ke(Po,{marginTop:1,children:Ke(pt,{lines:N,height:oe,isActive:y})}),Ke(Po,{marginTop:1,children:u!==null?Ke(Oe,{label:u}):Ke(Kl,{wrap:"truncate",color:f.mutedForeground,children:_e([`\u8BC4\u8BBA ${_.commentCount}`,`${L?"\u83B7\u8D5E":_.liked?"\u5DF2\u8D5E":"\u70B9\u8D5E"} ${_.likeCount}`,_.bookmarked&&"\u5DF2\u6536\u85CF"])})})]})}})})}import{Box as Eo}from"ink";import{useEffect as gv,useRef as hv,useState as Zl}from"react";import{z as H}from"zod";var sv=H.object({balance:H.number(),today:H.object({requests:H.number(),tokens:H.number(),cost:H.number()})}),xh=()=>A(sv,"/dashboard/summary"),Th=["all","30d","7d"],av=H.object({totals:H.object({requests:H.number(),tokens:H.number(),cost:H.number()}),hourly:H.array(H.number()),models:H.array(H.object({model:H.string(),displayName:H.string(),tokens:H.number(),inTokens:H.number(),outTokens:H.number()})),chart:H.object({start:H.string(),end:H.string(),points:H.array(H.object({day:H.string(),model:H.string(),tokens:H.number()}))}),heatmap:H.object({start:H.string(),end:H.string(),days:H.array(H.object({day:H.string(),cost:H.number()}))}),activeDays:H.number(),currentStreak:H.number(),longestStreak:H.number()}),Xl=e=>A(av,Fe("/dashboard/stats",{range:e})),cv=H.object({id:H.number().int(),requestId:H.string(),tokenName:H.string(),protocol:Bm,model:H.string(),modelDisplayName:H.string(),groupName:H.string(),promptTokens:H.number(),completionTokens:H.number(),cachedTokens:H.number(),cacheWriteTokens:H.number(),cacheWrite1hTokens:H.number(),webSearchRequests:H.number(),imageGenerationCalls:H.number(),totalTokens:H.number(),quotaCost:H.number(),subscriptionPlanName:H.string().nullable(),multiplier:H.number(),tierOver:H.number().int().nullable(),paramMultipliers:Mu,status:Wm,httpStatus:H.number().int(),stopReason:H.string().nullable(),latencyMs:H.number(),firstByteMs:H.number().nullable(),stream:H.boolean(),ip:H.string(),createdAt:H.string()}),wh=e=>A(mt(cv),Fe("/logs",{...e})),lv=H.object({quotaCost:H.number(),rpm:H.number(),tpm:H.number(),concurrency:H.number()}),kh=e=>A(lv,Fe("/logs/stats",{...e})),mv=H.object({id:H.number().int(),type:qm,amount:H.number(),balanceAfter:H.number(),refType:Gm,refId:H.string().nullable(),createdAt:H.string()}),vh=e=>A(mt(mv),Fe("/quota-ledger",{...e}));import{Box as uv,Text as ln}from"ink";import yi from"string-width";import{Fragment as Rh,jsx as mn,jsxs as Ql}from"react/jsx-runtime";var Ao=1,dv=4,pv=1,hr=8,fv=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587"],Ch=e=>`${Number(e.slice(5,7))}\u6708${Number(e.slice(8,10))}\u65E5`;function _h({data:e,order:t,width:n,rows:o}){let r=o-pv,i=[];for(let M=e.start;M<=e.end;M=Gn(M,1))i.push(M);let s=Math.min(dv,Math.floor((n+Ao)/i.length)-Ao);s<1&&(s=1,i=i.slice(-Math.floor((n+Ao)/(1+Ao))));let a=i[0],c=i[i.length-1];if(a===void 0||c===void 0)return null;let l=new Map(t.slice(0,ys.length).map((M,C)=>[M,C])),u=ys.length,m=M=>ys[M]??f.faintForeground,p=new Map(i.map((M,C)=>[M,C])),d=i.map(()=>Array.from({length:u+1},()=>0));for(let M of e.points){let C=p.get(M.day);if(C===void 0)continue;let v=d[C];if(v===void 0)continue;let _=l.get(M.model)??u;v[_]=(v[_]??0)+M.tokens}let b=d.map(M=>M.reduce((C,v)=>C+v,0)),h=Math.max(0,...b),g=r*hr,x=d.map((M,C)=>{let v=Array.from({length:r},()=>null),_=b[C]??0;if(_<=0)return v;let L=Math.max(1,Math.round(_/h*g)),P=[],B=0,J=0;M.forEach((oe,fe)=>{B+=oe;let $=Math.round(B/_*L);for(let ne=J;ne<$;ne+=1)P[ne]=m(fe);J=$});for(let oe=0;oe<r;oe+=1){let fe=Math.min(hr,L-oe*hr);if(fe<=0)break;let $=new Map;for(let F=oe*hr;F<oe*hr+fe;F+=1){let re=P[F];re!==void 0&&$.set(re,($.get(re)??0)+1)}let ne=null,w=0;for(let[F,re]of $)re>w&&(ne=F,w=re);if(ne===null)break;v[oe]={color:ne,glyph:fe===hr?null:fv[fe-1]??null}}return v}),T=M=>{let C=[],v=(_,L,P)=>{let B=C[C.length-1];B!==void 0&&B.color===_&&B.glyph===L?B.width+=P:C.push({color:_,glyph:L,width:P})};return x.forEach((_,L)=>{L>0&&v(null,null,Ao);let P=_[M]??null;P===null?v(null,null,s):v(P.color,P.glyph,s)}),C},k=i.length*(s+Ao)-Ao,S=Ch(a),y=Ch(c),R=h>0?`\u5355\u65E5\u5CF0\u503C ${qn(h)}`:"",N=k-yi(S)-yi(y),E=R!==""&&N>=yi(R)+4,W=E?Math.floor((N-yi(R))/2):N;return Ql(uv,{flexDirection:"column",children:[Array.from({length:r},(M,C)=>{let v=r-1-C;return mn(ln,{wrap:"truncate",children:T(v).map((_,L)=>_.color===null?mn(ln,{children:" ".repeat(_.width)},L):_.glyph===null?mn(ln,{backgroundColor:_.color,children:" ".repeat(_.width)},L):mn(ln,{color:_.color,children:_.glyph.repeat(_.width)},L))},v)}),mn(ln,{wrap:"truncate",children:N<2?mn(ln,{color:f.faintForeground,children:He(S,k)}):Ql(Rh,{children:[mn(ln,{color:f.faintForeground,children:S}),mn(ln,{children:" ".repeat(W)}),E&&Ql(Rh,{children:[mn(ln,{color:f.mutedForeground,children:R}),mn(ln,{children:" ".repeat(N-yi(R)-W)})]}),mn(ln,{color:f.faintForeground,children:y})]})})]})}import{jsx as ct,jsxs as Ah}from"react/jsx-runtime";var yv={all:"\u5168\u90E8","30d":"30 \u5929","7d":"7 \u5929"},bv=1,ya=4,Ph=5,Sv=9;function xv(e){let t=-1,n=0;return e.forEach((o,r)=>{o>n&&(n=o,t=r)}),t<0?"\u2014":`${t} \u70B9`}function Eh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Zl("30d"),[i,s]=Zl("heatmap"),[a,c]=Zl(null),l=hv(null),u=Q([o,e.revision],async()=>{let m=l.current;if(m!==null&&m.revision===e.revision){let h=await Xl(o);return{summary:m.summary,stats:h,site:m.site}}let[p,d,b]=await Promise.all([xh(),Xl(o),Ge(e.ctx.site)]);return l.current={revision:e.revision,summary:p,site:b},{summary:p,stats:d,site:b}});return gv(()=>{u.phase==="ready"&&c(yd({tokens:u.data.stats.totals.tokens,scope:"user",range:o}))},[u,o]),G(m=>{m==="r"&&e.reload(),m==="t"&&s(p=>p==="heatmap"?"chart":"heatmap")}),ct(Y,{hints:["\u2191\u2193 \u6EDA\u52A8","\u2190\u2192 \u5207\u6362\u533A\u95F4","t \u5207\u6362\u56FE\u8868","/ \u8FC7\u6EE4","r \u5237\u65B0"],children:ct(Eo,{flexDirection:"column",children:ct(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u91CF",width:t,children:({summary:m,stats:p,site:d})=>{let b=[{label:"\u8D26\u6237\u4F59\u989D",value:Te(m.balance,d.quotaPerUsd)},{label:"\u4ECA\u65E5\u8BF7\u6C42",value:Le(m.today.requests)},{label:"\u4ECA\u65E5 Token",value:Le(m.today.tokens)},{label:"\u4ECA\u65E5\u6D88\u8017",value:Te(m.today.cost,d.quotaPerUsd)}],h=[{label:"\u8BF7\u6C42\u6570",value:Le(p.totals.requests)},{label:"Token \u603B\u91CF",value:qn(p.totals.tokens)},{label:"\u6D88\u8017",value:Te(p.totals.cost,d.quotaPerUsd)},{label:"\u6D3B\u8DC3\u5929\u6570",value:Le(p.activeDays)},{label:"\u5F53\u524D\u8FDE\u7EED",value:`${p.currentStreak} \u5929`},{label:"\u6700\u957F\u8FDE\u7EED",value:`${p.longestStreak} \u5929`},{label:"\u9AD8\u5CF0\u65F6\u6BB5",value:xv(p.hourly)},{label:"\u5E38\u7528\u6A21\u578B",value:p.models[0]?.displayName??"\u2014"}],g=t-ge,x=C=>Bt+C+Ut(b.length,g)+X+Bt+C+bv+C+Ut(h.length,g)+X+Bt+C,T=n-x(qe)>=ya?qe:0,k=n-x(T),S=X+Bt+T+Ph,y=i==="chart"&&p.chart.points.length>0&&k>=S+ya,R=i==="heatmap"&&cr(g)&&k-(X+To)>=ya,N=R?X+To:0,E=y?Math.min(Sv,Ph+Math.floor((k-S-ya)/2)):0,W=k-N-(y?X+Bt+T+E:0),M=C=>`${(p.totals.tokens>0?C/p.totals.tokens*100:0).toFixed(1)}%`;return Ah(Eo,{flexDirection:"column",children:[ct(pe,{title:"\u6982\u89C8",width:t,gap:T,children:ct(it,{width:g,tiles:b})}),ct(Eo,{marginTop:1,flexDirection:"column",children:Ah(pe,{title:"\u533A\u95F4\u7EDF\u8BA1",width:t,gap:T,children:[ct(Fs,{options:Th.map(C=>({value:C,label:yv[C]})),value:o,onChange:r}),ct(Eo,{marginTop:T,children:ct(it,{width:g,tiles:h})}),R&&ct(Eo,{marginTop:1,flexDirection:"column",children:ct(lr,{data:p.heatmap,value:C=>C.cost,caption:a,width:g})})]})}),y&&ct(Eo,{marginTop:1,flexDirection:"column",children:ct(pe,{title:"\u7528\u91CF\u8D8B\u52BF",note:"\u67F1\u8272\u7531\u4EAE\u81F3\u6697\u5BF9\u5E94\u7528\u91CF\u524D\u4E94\u7684\u6A21\u578B\uFF0C\u7070\u8272\u4E3A\u5176\u4ED6",width:t,gap:T,children:ct(_h,{data:p.chart,order:p.models.map(C=>C.model),width:g,rows:E})})}),ct(Eo,{marginTop:1,flexDirection:"column",children:ct(pe,{title:"\u6A21\u578B\u7528\u91CF",width:t,gap:T,children:p.models.length===0?ct(ye,{tone:"info",width:g,title:"\u6682\u65E0\u7528\u91CF\u6570\u636E",detail:"\u8C03\u7528 API \u540E\u8FD9\u91CC\u4F1A\u663E\u793A\u5404\u6A21\u578B\u7684\u6BCF\u65E5 Token \u7528\u91CF"}):ct(de,{retain:"list",items:p.models,width:g,height:W,columns:[{label:"\u6A21\u578B",shrink:!0},{label:"\u603B Token",align:"right"},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u5360\u6BD4",align:"right"}],row:C=>[C.displayName,qn(C.tokens),qn(C.inTokens),qn(C.outTokens),M(C.tokens)],searchOf:C=>C.displayName})})})]})}})})})}import{Box as yr,Text as tm}from"ink";import{useState as Nh}from"react";import{z as wv}from"zod";import{z as gt}from"zod";var Tv=gt.object({id:gt.number().int(),name:gt.string(),description:gt.string(),multiplier:gt.number()}),ba=()=>A(gt.array(Tv),"/groups"),em=gt.object({id:gt.number().int(),name:gt.string(),keyPrefix:gt.string(),keySuffix:gt.string(),groupId:gt.number().int().nullable(),groupName:gt.string().nullable(),usedQuota:gt.number(),quotaLimit:gt.number().nullable()}),Sa=()=>A(gt.array(em),"/tokens"),Mh=e=>A(em.extend({token:gt.string()}),"/tokens",{method:"POST",json:e}),xa=(e,t)=>A(em,`/tokens/${e}`,{method:"PATCH",json:t}),Ih=e=>A(se,`/tokens/${e}`,{method:"DELETE"});import{jsx as lt,jsxs as Ta}from"react/jsx-runtime";var Lh={model:"",requestId:"",token:"",group:"",status:"",range:"today",since:"",until:""},Oh=wv.iso.date();function kv(e){let t=Ec();return e.range==="today"?{since:t,until:t}:e.range==="7d"?{since:Gn(t,-6),until:t}:e.range==="30d"?{since:Gn(t,-29),until:t}:e.range==="custom"?{...e.since===""?{}:{since:e.since},...e.until===""?{}:{until:e.until}}:{}}function Dh(e){let t=kv(e);return{...e.model.trim()===""?{}:{model:e.model.trim()},...e.requestId.trim()===""?{}:{requestId:e.requestId.trim()},...e.token===""?{}:{token:e.token},...e.group===""?{}:{group:e.group},...e.status===""?{}:{status:e.status},...t.since===void 0?{}:{since:Mc(t.since).toISOString()},...t.until===void 0?{}:{until:Mc(Gn(t.until,1)).toISOString()}}}var vv=_t(Za,Ki,"\u5168\u90E8\u72B6\u6001"),Cv=[{value:"",label:"\u4E0D\u9650"},{value:"today",label:"\u4ECA\u5929"},{value:"7d",label:"\u8FD1 7 \u5929"},{value:"30d",label:"\u8FD1 30 \u5929"},{value:"custom",label:"\u81EA\u5B9A\u4E49\u8D77\u6B62"}];function Rv({log:e,quotaPerUsd:t,width:n}){let o=n-ge,r=Ki(e.status),i=ht(r),s=e.status!=="anomaly"?null:e.totalTokens>0?"\u672C\u6B21\u8C03\u7528\u672A\u8FD4\u56DE\u7528\u91CF\u6570\u636E\uFF0C\u8D39\u7528\u6309\u8BF7\u6C42\u4E0E\u54CD\u5E94\u7684\u6587\u672C\u91CF\u4F30\u7B97":"\u672C\u6B21\u8C03\u7528\u672A\u8FD4\u56DE\u7528\u91CF\u6570\u636E\u4E14\u65E0\u6CD5\u4F30\u7B97\uFF0C\u672A\u8BA1\u8D39",a=[];e.cachedTokens>0&&a.push(["\u7F13\u5B58\u8BFB",Le(e.cachedTokens)]),e.cacheWriteTokens>0&&a.push(["\u7F13\u5B58\u5199",Le(e.cacheWriteTokens)]),e.cacheWrite1hTokens>0&&a.push(["\u7F13\u5B58\u5199 1h",Le(e.cacheWrite1hTokens)]),e.webSearchRequests>0&&a.push(["\u7F51\u9875\u641C\u7D22",`${Le(e.webSearchRequests)} \u6B21`]),e.imageGenerationCalls>0&&a.push(["\u56FE\u50CF\u751F\u6210",`${Le(e.imageGenerationCalls)} \u6B21`]),e.firstByteMs!==null&&a.push(["\u9996\u5B57\u8282",`${ao(e.firstByteMs)} s`]),e.tierOver!==null&&a.push(["\u8F93\u5165\u957F\u5EA6",yc(e.tierOver)]),e.paramMultipliers.length>0&&a.push(["\u547D\u4E2D\u53C2\u6570",_e(e.paramMultipliers.map(l=>`${l.value} \xD7${l.multiplier}`))]);let c=[["\u8BF7\u6C42 ID",e.requestId],["\u4EE4\u724C",e.tokenName],["\u5206\u7EC4",e.groupName],["\u8BF7\u6C42 IP",e.ip],["\u534F\u8BAE",Td(e.protocol)],["\u8BA1\u8D39\u6765\u6E90",e.subscriptionPlanName!==null?`\u8BA2\u9605 \xB7 ${e.subscriptionPlanName}`:"\u4F59\u989D"],["HTTP \u72B6\u6001",String(e.httpStatus)],...e.stopReason===null?[]:[["\u7ED3\u675F\u539F\u56E0",e.stopReason]]];return Ta(pe,{title:e.modelDisplayName,note:K(e.createdAt),width:n,children:[Ta(tm,{wrap:"truncate",children:[lt(tm,{color:i===void 0?f.mutedForeground:et[i],children:r.label}),lt(tm,{color:f.faintForeground,children:` ${_e([e.stream?"\u6D41\u5F0F":"",e.model])}`})]}),lt(yr,{marginTop:1,children:lt(it,{width:o,tiles:[{label:"\u8F93\u5165 Token",value:Le(e.promptTokens)},{label:"\u8F93\u51FA Token",value:Le(e.completionTokens)},{label:"\u6D88\u8017",value:Xo(e.quotaCost,t)},{label:"\u603B\u8017\u65F6",value:`${ao(e.latencyMs)} s`},{label:"\u6863\u4F4D",value:Or(e.tierOver)},{label:"\u5206\u7EC4\u500D\u7387",value:`\xD7${e.multiplier}`},{label:"\u53C2\u6570\u500D\u7387",value:`\xD7${Iu(e.paramMultipliers)}`},{label:"\u603B\u500D\u7387",value:`\xD7${Nu(e.multiplier,e.paramMultipliers)}`}]})}),s!==null&&lt(yr,{marginTop:1,children:lt(ye,{tone:"warn",width:o,title:s})}),lt(yr,{marginTop:1,children:lt(Ve,{width:o,items:[...a,...c]})})]})}function $h(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Nh({name:"list"}),[i,s]=Nh(Lh),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[g,x,T]=await Promise.all([ba(),Sa(),Ge(e.ctx.site)]);return{groups:g,tokens:x,site:T}}),m=ze([e.revision,JSON.stringify(i)],g=>wh({page:g,...Dh(i)}),{retain:"page"}),p=Q([e.revision,JSON.stringify(i)],()=>kh(Dh(i))),d=o.name==="list";G((g,x)=>{d&&(g==="r"?e.reload():g==="f"?(l(),r({name:"filter"})):x.leftArrow?m.go(-1):x.rightArrow&&m.go(1))});let b=()=>{o.name==="list"?e.pop():(l(),r({name:"list"}))},h=JSON.stringify(i)!==JSON.stringify(Lh);return lt(Y,{hints:d?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:b,children:lt(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7B5B\u9009\u9009\u9879",width:t,children:({groups:g,tokens:x,site:T})=>{if(o.name==="filter")return lt(te,{title:"\u7B5B\u9009\u65E5\u5FD7",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"text",name:"model",label:"\u6A21\u578B",initial:i.model,placeholder:"\u641C\u7D22\u6A21\u578B ID \u6216\u540D\u79F0"},{kind:"text",name:"requestId",label:"\u8BF7\u6C42 ID",initial:i.requestId,placeholder:"\u641C\u7D22\u8BF7\u6C42 ID"},{kind:"select",name:"token",label:"\u4EE4\u724C",options:[{value:"",label:"\u5168\u90E8\u4EE4\u724C"},...[...new Set(x.map(S=>S.name))].map(S=>({value:S,label:S}))],initial:i.token},{kind:"select",name:"group",label:"\u5206\u7EC4",options:[{value:"",label:"\u5168\u90E8\u5206\u7EC4"},...g.map(S=>({value:S.name,label:S.name}))],initial:i.group},{kind:"select",name:"status",label:"\u72B6\u6001",options:vv,initial:i.status},{kind:"select",name:"range",label:"\u65F6\u95F4\u8303\u56F4",options:Cv,initial:i.range},{kind:"text",name:"since",label:"\u5F00\u59CB\u65E5\u671F",initial:i.since,placeholder:"YYYY-MM-DD",hint:"\u4EC5\u65F6\u95F4\u8303\u56F4\u9009\u300C\u81EA\u5B9A\u4E49\u8D77\u6B62\u300D\u65F6\u751F\u6548"},{kind:"text",name:"until",label:"\u7ED3\u675F\u65E5\u671F",initial:i.until,placeholder:"YYYY-MM-DD",hint:"\u4EC5\u65F6\u95F4\u8303\u56F4\u9009\u300C\u81EA\u5B9A\u4E49\u8D77\u6B62\u300D\u65F6\u751F\u6548"}],onCancel:b,onSubmit:S=>{let y=S.range??"",R=(S.since??"").trim(),N=(S.until??"").trim();if(y==="custom"&&(R!==""&&!Oh.safeParse(R).success||N!==""&&!Oh.safeParse(N).success)){c("\u65E5\u671F\u65E0\u6548");return}s({model:S.model??"",requestId:S.requestId??"",token:S.token??"",group:S.group??"",status:S.status??"",range:y,since:R,until:N}),m.reset(),r({name:"list"})}});if(o.name==="detail")return lt(Rv,{log:o.log,quotaPerUsd:T.quotaPerUsd,width:t});let k=Ut(4,t);return Ta(yr,{flexDirection:"column",children:[lt(yr,{height:k+1,flexDirection:"column",overflow:"hidden",children:lt(V,{state:p,loading:"\u6B63\u5728\u7EDF\u8BA1\u7B5B\u9009\u7ED3\u679C",width:t,children:S=>lt(it,{width:t,tiles:[{label:"\u6D88\u8017",value:Te(S.quotaCost,T.quotaPerUsd)},{label:"RPM",value:Le(S.rpm)},{label:"TPM",value:Le(S.tpm)},{label:"\u5E76\u53D1",value:Le(S.concurrency)}]})})}),lt(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u4F7F\u7528\u65E5\u5FD7",width:t,children:S=>Ta(yr,{flexDirection:"column",children:[lt(de,{retain:"list",items:S.items,width:t,height:Math.max(3,n-2-k),columns:[{label:"\u65F6\u95F4"},{label:"\u6A21\u578B",shrink:!0},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u6D88\u8017",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:y=>[K(y.createdAt),y.modelDisplayName,Le(y.promptTokens),Le(y.completionTokens),Xo(y.quotaCost,T.quotaPerUsd),yt(Ki(y.status))],onOpen:y=>r({name:"detail",log:y}),emptyLabel:h?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u8C03\u7528\u8BB0\u5F55",emptyDescription:h?void 0:"\u901A\u8FC7\u4EE4\u724C\u8C03\u7528 API \u540E\uFF0C\u660E\u7EC6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),lt(We,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})}})})}import{Box as Dn,Text as Mo}from"ink";import{useState as Iv}from"react";import{z as we}from"zod";var _v=hc.extend({id:we.number().int(),model:we.string(),displayName:we.string(),rules:_u}),Pv=we.object({quotaPerUsd:we.number(),minTopupCny:we.number(),models:we.array(_v)});function wa(e){return fn(Pv,`${e}/api/pricing`)}var Av=we.object({cnyPerUsd:we.number(),groups:we.array(we.object({id:we.number().int(),name:we.string(),description:we.string(),multiplier:we.number()})),stats:we.object({requests:we.number(),errors:we.number(),latencyP50Ms:we.number().nullable(),firstByteP50Ms:we.number().nullable()}),heartbeat:we.object({groups:we.array(we.object({id:we.number().int(),name:we.string(),minutes:we.array(we.object({requests:we.number(),errors:we.number()}))}))})});function Bh(e){return A(Av,`/pricing/${e}`)}var Ev=we.object({data:we.array(we.object({id:we.string()}))});async function Fh(e,t,n){return(await fn(Ev,`${e}/v1/models`,{headers:{authorization:`Bearer ${t}`},...n===void 0?{}:{timeoutMs:n}})).data.map(r=>r.id)}var Uh=()=>A(Ou,"/provider-status");import{Text as br}from"ink";import{jsx as ka,jsxs as jh}from"react/jsx-runtime";var Mv=` ${ae.bullet} `,Hh=1;function qh({providers:e}){return jh(br,{wrap:"truncate",children:[ka(br,{color:f.faintForeground,children:"\u5B98\u65B9\u72B6\u6001"}),e.map(t=>{let n=$u(t);return jh(br,{children:[ka(br,{color:f.faintForeground,children:Mv}),ka(br,{color:f.foreground,children:`${wd(t.provider)} `}),ka(br,{color:et[n.tone],children:n.label})]},t.provider)})]})}import{jsx as Pe,jsxs as bi}from"react/jsx-runtime";var Nv=4,Lv=1+qe,Ov=e=>e.requests===0?f.border:e.errors===0?f.success:e.errors/e.requests>=.5?f.danger:f.warning;function Dv({minutes:e,width:t}){let n=e.slice(Math.max(0,e.length-t)),o=[];for(let r of n){let i=Ov(r),s=o[o.length-1];s!==void 0&&s.color===i?s.count+=1:o.push({color:i,count:1})}return Pe(Mo,{wrap:"truncate",children:o.map((r,i)=>Pe(Mo,{color:r.color,children:ae.barFilled.repeat(r.count)},i))})}function $v({price:e,width:t,contentRows:n}){let o=O(),r=Q([e.id,o.revision],()=>Bh(e.id)),i=Eu(e,e.rules),s=i.length>1,a=e.rules.filter(Pu),c=t-ge,l=1+i.length,u=1+a.length;return Pe(V,{state:r,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u8BE6\u60C5",width:t,children:m=>{let p=m.stats,d=[{label:"\u53EF\u7528\u7387",value:p.requests>0?`${((p.requests-p.errors)/p.requests*100).toFixed(1)}%`:"\u2014"},{label:"\u8C03\u7528\u6B21\u6570",value:Le(p.requests)},{label:"\u5EF6\u8FDF P50",value:p.latencyP50Ms!==null?`${ao(p.latencyP50Ms)} s`:"\u2014"},{label:"\u9996\u5B57\u8282 P50",value:p.firstByteP50Ms!==null?`${ao(p.firstByteP50Ms)} s`:"\u2014"}],b=a.length>0?X+Xe+u:0,h=Lv+Xe+Ut(d.length,c,2)+X+Xe+l+b+X+Xe,g=m.heartbeat.groups.length,x=n-h-Nv-X-Xe,T=Math.max(0,Math.floor(x/2));T<g&&(T=Math.max(0,Math.floor((x-1)/2))),T=Math.min(g,T);let k=T>0?X+Xe+T*2+(T<g?1:0):0,S=Math.max(1,n-h-k);return bi(Dn,{flexDirection:"column",children:[Pe(Dn,{marginBottom:qe,children:bi(Mo,{wrap:"truncate",children:[Pe(Mo,{bold:!0,color:f.foreground,children:e.displayName}),Pe(Mo,{color:f.faintForeground,children:` ${e.model}`})]})}),Pe(pe,{title:"\u8FD1 24 \u5C0F\u65F6",note:"\u5168\u90E8\u5206\u7EC4\u7684\u7EFC\u5408\u8C03\u7528\u7EDF\u8BA1",width:t,children:Pe(it,{width:c,tiles:d,maxPerRow:2})}),T>0&&Pe(Dn,{marginTop:1,flexDirection:"column",children:bi(pe,{title:"\u53EF\u7528\u6027",note:"\u6700\u8FD1\u4E00\u6BB5\u65F6\u95F4\u5404\u5206\u7EC4\u7684\u8C03\u7528\u5065\u5EB7\u72B6\u51B5",width:t,children:[m.heartbeat.groups.slice(0,T).map(y=>bi(Dn,{flexDirection:"column",children:[Pe(Mo,{wrap:"truncate",color:f.foreground,children:y.name}),Pe(Dv,{minutes:y.minutes,width:c})]},y.id)),T<g&&Pe(Mo,{color:f.faintForeground,children:`\u5176\u4F59 ${g-T} \u4E2A\u5206\u7EC4\u672A\u663E\u793A`})]})}),Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u6A21\u578B\u4EF7\u683C",note:"\u6BCF\u767E\u4E07 Token \u7684\u7F8E\u5143\u6807\u4EF7",width:t,children:Pe(de,{items:i,width:c,height:l,columns:[{label:"\u6863\u4F4D"},...s?[{label:"\u8F93\u5165\u957F\u5EA6"}]:[],{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u7F13\u5B58\u8BFB\u53D6",align:"right"},{label:"\u7F13\u5B58\u5199\u5165",align:"right"}],row:y=>[y.name,...y.range===null?[]:[y.range],pn(y.price.inputPricePerMillionTokens,"-"),pn(y.price.outputPricePerMillionTokens,"-"),pn(y.price.cachedInputPricePerMillionTokens,"-"),pn(y.price.cacheWritePricePerMillionTokens,"-")]})})}),a.length>0&&Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u8BF7\u6C42\u53C2\u6570\u500D\u7387",note:"\u547D\u4E2D\u65F6 Token \u8D39\u7528\u4E58\u4EE5\u500D\u7387\uFF0C\u591A\u6761\u547D\u4E2D\u4F9D\u6B21\u76F8\u4E58",width:t,children:Pe(de,{items:a,width:c,height:u,columns:[{label:"\u53C2\u6570\u540D",shrink:!0},{label:"\u53C2\u6570\u503C",shrink:!0},{label:"\u500D\u7387",align:"right"}],row:y=>[y.param,y.value,`\xD7${y.multiplier}`]})})}),Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u5206\u7EC4\u4EF7\u683C",note:"\u500D\u7387\u968F\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u800C\u5B9A\uFF0C\u5355\u4EF7\u4E3A 1 \u7F8E\u5143\u6807\u4EF7\u7528\u91CF\u7684\u4EBA\u6C11\u5E01\u4EF7\u683C",width:t,children:m.groups.length===0?Pe(ye,{tone:"info",width:c,title:"\u6682\u65E0\u53EF\u7528\u5206\u7EC4",detail:"\u5F53\u524D\u6CA1\u6709\u542F\u7528\u7684\u6E20\u9053\u63D0\u4F9B\u8BE5\u6A21\u578B"}):Pe(de,{items:m.groups,width:c,height:S,columns:[{label:"\u5206\u7EC4",shrink:!0},{label:"\u8BF4\u660E",shrink:!0},{label:"\u500D\u7387",align:"right"},{label:"\u5355\u4EF7",align:"right"}],row:y=>[y.name,y.description,`\xD7${y.multiplier}`,`\xA5${(m.cnyPerUsd*y.multiplier).toFixed(2)}`]})})})]})}})}function Gh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Iv({name:"list"}),i=Q([e.revision],async()=>(await wa(e.ctx.site)).models),s=Q([e.revision],Uh);G(c=>{c==="r"&&e.reload()});let a=()=>{o.name==="list"?e.pop():r({name:"list"})};return Pe(Y,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","/ \u8FC7\u6EE4","r \u5237\u65B0"]:["\u2191\u2193 \u6EDA\u52A8","r \u5237\u65B0","Esc \u8FD4\u56DE"],onEscape:a,children:Pe(V,{state:i,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u5B9A\u4EF7",width:t,children:c=>{if(c.length===0)return Pe(ye,{tone:"info",width:t,title:"\u6682\u65E0\u6A21\u578B"});if(o.name==="detail")return Pe($v,{price:o.price,width:t,contentRows:n});let l=s.phase==="ready"?Du(s.data.providers):[],u=l.length>0?Hh+X:0;return bi(Dn,{flexDirection:"column",children:[l.length>0&&Pe(Dn,{marginBottom:X,children:Pe(qh,{providers:l})}),Pe(de,{retain:"list",items:c,width:t,height:n-u,columns:[{label:"\u6A21\u578B",shrink:!0},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u7F13\u5B58\u8BFB\u53D6",align:"right"},{label:"\u7F13\u5B58\u5199\u5165",align:"right"}],row:m=>[m.displayName,pn(m.inputPricePerMillionTokens,"-"),pn(m.outputPricePerMillionTokens,"-"),pn(m.cachedInputPricePerMillionTokens,"-"),pn(m.cacheWritePricePerMillionTokens,"-")],searchOf:m=>`${m.displayName} ${m.model}`,onOpen:m=>r({name:"detail",price:m}),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})]})}})})}import{Box as Io,Text as fC}from"ink";import{useState as Ma}from"react";function zh(e,t){let n=e.line??t.apiLines[0];if(n===void 0)throw new U("\u7AD9\u70B9\u672A\u914D\u7F6E\u63A5\u5165\u7EBF\u8DEF",{hint:"\u8BF7\u8054\u7CFB\u7AD9\u70B9\u7BA1\u7406\u5458\u5728\u8BBE\u7F6E\u91CC\u6DFB\u52A0\u63A5\u5165\u7EBF\u8DEF"});return n}async function Wh(e,t){let n=await Ge(e.site);return Fh(zh(fo(),n).url,t)}async function Vh(e,t,n){let o=await Ge(e.site),r=zh(fo(),o).url;return{input:{siteName:o.siteName,baseUrl:t.relayUrl(r),apiKey:n},at:t.resolveDir()}}async function Kh(e,t,n){let{input:o,at:r}=await Vh(e,t,n);t.apply(o,r)}async function Yh(e,t,n,o,r){let{input:i,at:s}=await Vh(e,t,n);t.apply({...i,model:o,models:r},s)}import{homedir as ny}from"os";import{join as Ca,resolve as Hv}from"path";import Bv from"json5";import{applyEdits as Fv,modify as Uv,parse as jv}from"jsonc-parser";function Jh(e,t){if(typeof e!="object"||e===null||Array.isArray(e))throw new U(`${t} \u7684\u9876\u5C42\u4E0D\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`);return e}function Xh(e){let t=[],n=jv(e,t,{allowTrailingComma:!0});return t.length>0?null:n}function Qh(e,t){let n=Xh(e);if(n!==null)return{root:Jh(n,t),jsonc:!0};try{return{root:Jh(Bv.parse(e),t),jsonc:!1}}catch(o){throw new U(`${t} \u4E0D\u662F\u5408\u6CD5 JSON\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:o})}}function no(e,t){let n=e;for(let o of t){if(typeof n!="object"||n===null||Array.isArray(n))return;n=n[o]}return n}function Si(e){let t=Nt(e);return t===null?null:Qh(t,e).root}function $n(e,t){let n=Si(e),o=n===null?void 0:no(n,t);return typeof o=="string"?o:null}function va(e,t){let n=Si(e);return n!==null&&no(n,t)!==void 0}function Gt(e,t){let n=Nt(e)??"{}",o=n.includes(`\r
18
+ ${n}`}import{Box as kg,Text as nk}from"ink";import{useState as ea}from"react";import{jsx as tk}from"react/jsx-runtime";function ur({title:e,width:t,download:n,onCancel:o,onSaved:r}){let{busy:i,error:s,run:a}=ue();return tk(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 Yf(c.path??"",l.fileName,l.bytes)},{onSuccess:r})}})}var dr={maxCount:xu,maxBytes:Su},Zn=e=>({kind:"textarea",name:"attachments",label:"\u9644\u4EF6\u8DEF\u5F84",rows:2,placeholder:"\u6BCF\u884C\u4E00\u4E2A\u672C\u5730\u6587\u4EF6\u8DEF\u5F84\uFF0C\u53EF\u7559\u7A7A",hint:`\u6700\u591A ${e.maxCount} \u4E2A\uFF0C\u5355\u4E2A\u4E0D\u8D85\u8FC7 ${e.maxBytes/1024/1024}MB`,optional:!0});import{jsx as On,jsxs as ak}from"react/jsx-runtime";var ta=e=>e===null?void 0:`\u539F\u56E0\uFF1A${e}`,pr=(e,t)=>e===null?0:gl(Bc(e.until),ta(e.reason),t)+1;function ko({muted:e,width:t}){return e===null?null:On(kg,{marginBottom:1,children:On(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 vo({notices:e,status:t,reason:n,width:o}){return t==="published"?null:On(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,ok=["content","attachments"],rk=9,ik=3,sk=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),b=ok.some(g=>(u[g]??"").trim()!==""),h=Math.min(sk,Math.max(ik,o-rk-fi(a)));return Re(b),gn(()=>d(!1),{isActive:p,layer:Wn.panel}),G(g=>{g==="q"&&b&&d(!0)},!p&&s===null),p?On(Ae,{width:n,title:t===null?"\u653E\u5F03\u8BC4\u8BBA":"\u653E\u5F03\u56DE\u590D",detail:t===null?"\u8BC4\u8BBA\u5C1A\u672A\u53D1\u8868\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F":"\u56DE\u590D\u5C1A\u672A\u53D1\u8868\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F",confirmLabel:"\u653E\u5F03",onConfirm:i,onCancel:()=>d(!1)}):On(te,{title:t===null?"\u53D1\u8868\u8BC4\u8BBA":`\u56DE\u590D ${t.mention}`,width:n,submitLabel:t===null?"\u53D1\u8868\u8BC4\u8BBA":"\u53D1\u8868\u56DE\u590D",busy:s!==null,busyLabel:s??"\u6B63\u5728\u63D0\u4EA4",error:a,fields:[{kind:"textarea",name:"content",label:"\u5185\u5BB9",rows:h,maxLength: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"},{...Zn(Qs),initial:u.attachments}],onChange:m,onCancel:()=>b?d(!0):i(),onSubmit:g=>{let x=(g.content??"").trim(),T;try{T=Jn(g.attachments??"",Qs)}catch(k){c(Se(k));return}if(x===""&&T.length===0){c(t===null?"\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9":"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9");return}if(jt(x).length+T.length>Qs.maxCount){c("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");return}l("\u6B63\u5728\u63D0\u4EA4",()=>Mn(T,ai,k=>xf(e,{content:pi(x,k),...t===null?{}:{replyToId:t.id}})),{onSuccess:k=>r(k.id)})}})}function ra({target:e,width:t,onDone:n,onCancel:o}){let{busy:r,error:i,fail:s,run:a}=ue();return On(te,{title:e.kind==="post"?"\u4E3E\u62A5\u5E16\u5B50":"\u4E3E\u62A5\u8BC4\u8BBA",width:t,submitLabel:"\u63D0\u4EA4\u4E3E\u62A5",busy:r!==null,busyLabel:r??"\u6B63\u5728\u63D0\u4EA4",error:i,fields:[{kind:"select",name:"reason",label:"\u4E3E\u62A5\u539F\u56E0",options:[{value:"",label:"\u8BF7\u9009\u62E9\u4E3E\u62A5\u539F\u56E0"},...Ni.map(c=>({value:c,label:vd(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"?Cf(e.id,m):Rf(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?On(ur,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${st(r.name)}`,width:t,download:async()=>{let c=await Uf(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")}}):ak(kg,{flexDirection:"column",children:[On(le,{width:t,height:Math.max(3,n-(s===null?0:1)),items:[{heading:"\u9644\u4EF6"},...e.map(c=>({value:c,label:ql(c)}))],onSelect:c=>{a(null),i(c)}}),s!==null&&On(nk,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${st(s)}`})]})}import{Fragment as gk,jsx as me,jsxs as xn}from"react/jsx-runtime";var lk={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"},Cg="\u5BC6\u94A5 ",mk=10,uk={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"}},dk=3,pk=8;function fk({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 Rg(){let e=O(),{width:t,columns:n,rows:o}=j(),r=Z(),[i,s]=vg({name:"menu"}),[a,c]=vg(!1),{busy:l,error:u,reset:m,fail:p,run:d}=ue(),b=Q([e.revision],async()=>{let[S,y,R,N]=await Promise.all([En(),Lf(),Mf(),jf()]);return{user:S.user,security:y,sessions:R.sessions,avatarReview:N.review}}),h=Q([e.revision],async()=>{let[S,y]=await Promise.all([En(),ff()]);return{homepage:await Pl(S.user.username),todo:y}});G(S=>{i.name==="menu"&&l===null&&S==="r"&&e.reload()}),Re(i.name==="codes"||l!==null);let g=()=>{if(i.name!=="codes"){if(i.name==="menu"){e.pop();return}m(),i.name==="passkey-rename"||i.name==="passkey-delete"?s({name:"passkey",item:i.item}):i.name==="confirm-revoke"?s({name:"session",item:i.item}):s({name:"menu"})}},x=S=>{s({name:"menu"}),e.reload(),e.toast("ok",S)},T=(S,y)=>{c(!1),s({name:"codes",codes:S,message:y})},k=(S,y)=>{S==="rebind"?d("\u6B63\u5728\u751F\u6210\u65B0\u5BC6\u94A5",()=>Al({code:y}),{onSuccess:R=>s({name:"enroll",setup:R})}):S==="regenerate"?d("\u6B63\u5728\u751F\u6210\u6062\u590D\u7801",()=>$f({code:y}),{onSuccess:({recoveryCodes:R})=>T(R,"\u6062\u590D\u7801\u5DF2\u66F4\u65B0")}):d("\u6B63\u5728\u505C\u7528",()=>Df({code:y}),{onSuccess:()=>x("\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u505C\u7528")})};return me(Y,{hints:i.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","r \u5237\u65B0"]:i.name==="codes"?["\u2191\u2193 \u79FB\u52A8","Enter \u786E\u8BA4"]:["Esc \u8FD4\u56DE"],locked:i.name==="codes",onEscape:g,isActive:l===null,children:me(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u8D26\u6237\u4FE1\u606F",width:t,children:({user:S,security:y,sessions:R,avatarReview:N})=>{if(i.name==="avatar")return xn(at,{flexDirection:"column",children:[N!==null&&me(at,{marginBottom:1,children:me(vo,{notices:Dc,status:N.status,reason:N.reviewReason,width:t})}),me(te,{title:"\u4FEE\u6539\u5934\u50CF",width:t,submitLabel:"\u4E0A\u4F20",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4E0A\u4F20",error:u,fields:[{kind:"text",name:"path",label:"\u56FE\u7247\u8DEF\u5F84",placeholder:"\u672C\u5730\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84"}],onCancel:g,onSubmit:w=>{let U=(w.path??"").trim();if(U===""){p("\u8BF7\u8F93\u5165\u56FE\u7247\u8DEF\u5F84");return}let re;try{re=Kf(U,$r)}catch(D){p(Se(D));return}d("\u6B63\u5728\u4E0A\u4F20",()=>Hf(re),{onSuccess:()=>x("\u5DF2\u63D0\u4EA4\u5BA1\u6838")})}})]});if(i.name==="avatar-delete")return me(Ae,{width:t,title:"\u786E\u8BA4\u5220\u9664\u5934\u50CF\uFF1F",detail:"\u5220\u9664\u540E\u663E\u793A\u9ED8\u8BA4\u5934\u50CF",confirmLabel:"\u5220\u9664",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>qf(),{onSuccess:()=>x("\u5934\u50CF\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="rename")return me(te,{title:"\u4FEE\u6539\u7528\u6237\u540D",width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"username",label:"\u7528\u6237\u540D",initial:S.username,placeholder:"\u8BF7\u8F93\u5165\u65B0\u7528\u6237\u540D"}],onCancel:g,onSubmit:w=>{let 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",()=>_f({username:U}),{onSuccess:()=>x("\u5DF2\u4FDD\u5B58")})}});if(i.name==="email")return me(te,{title:"\u4FEE\u6539\u90AE\u7BB1",width:t,submitLabel:"\u786E\u8BA4\u4FEE\u6539",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"email",label:"\u65B0\u90AE\u7BB1",placeholder:"\u7528\u4E8E\u767B\u5F55\u4E0E\u63A5\u6536\u901A\u77E5\u7684\u65B0\u90AE\u7BB1"},{kind:"code",name:"code",label:"\u9A8C\u8BC1\u7801",emailField:"email",send:w=>Af({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",()=>Ef({email:U,code:re,password:D}),{onSuccess:()=>x("\u90AE\u7BB1\u5DF2\u4FEE\u6539")})}});if(i.name==="password")return me(te,{title:"\u4FEE\u6539\u5BC6\u7801",width:t,submitLabel:"\u4FDD\u5B58",busy:l!==null,busyLabel:l??"\u6B63\u5728\u4FDD\u5B58",error:u,fields:[{kind:"text",name:"old",label:"\u5F53\u524D\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5F53\u524D\u5BC6\u7801"},{kind:"text",name:"next",label:"\u65B0\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u65B0\u5BC6\u7801",hint:`\u81F3\u5C11 ${Ot} \u4F4D\uFF0C\u4FDD\u5B58\u540E\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55`}],onCancel:g,onSubmit:w=>{let 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",()=>Pf({oldPassword:U,newPassword:re}),{onSuccess:()=>x("\u5BC6\u7801\u5DF2\u4FEE\u6539")})}});if(i.name==="confirm-logout-all")return me(Ae,{width:t,title:"\u786E\u8BA4\u9000\u51FA\u6240\u6709\u8BBE\u5907\u7684\u767B\u5F55\uFF1F",detail:"\u5F53\u524D\u8BBE\u5907\u4E5F\u4F1A\u4E00\u5E76\u9000\u51FA",confirmLabel:"\u9000\u51FA",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u9000\u51FA",()=>Nf(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u6240\u6709\u8BBE\u5907"),e.home()}}),onCancel:g});if(i.name==="code"){let w=uk[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}k(i.intent,re)}})}if(i.name==="enroll"){let w=(re,D)=>xn(gk,{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:Cg}),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:z=>{let ee=(z.code??"").trim();if(ee===""){p("\u8BF7\u8F93\u5165\u9A8C\u8BC1\u5668\u4E0A\u7684 6 \u4F4D\u6570\u5B57");return}d("\u6B63\u5728\u7ED1\u5B9A",()=>Of({code:ee}),{onSuccess:({recoveryCodes:he})=>T(he,"\u4E24\u6B65\u9A8C\u8BC1\u5DF2\u7ED1\u5B9A")})}})})]}),U=Ws(i.setup.otpauthUri,{width:t,rows:r},{columns:ck(Cg)+i.setup.secret.length,rows:mk},{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(fk,{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",()=>Bf(i.item.id,{name:U}),{onSuccess:()=>x("\u5DF2\u4FDD\u5B58")})}});if(i.name==="passkey-delete")return me(Ae,{width:t,title:`\u786E\u8BA4\u5220\u9664 Passkey\u300C${i.item.name}\u300D\uFF1F`,detail:"\u5220\u9664\u540E\u65E0\u6CD5\u518D\u7528\u5B83\u767B\u5F55",confirmLabel:"\u5220\u9664",busy:l,error:u,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>Ff(i.item.id),{onSuccess:()=>x("\u5DF2\u5220\u9664")}),onCancel:g});if(i.name==="passkey"){let w=i.item;return me(at,{flexDirection:"column",children:xn(pe,{title:`Passkey ${w.name}`,width:t,children:[me(Ve,{width:t-ge,items:[["\u540D\u79F0",w.name],["\u6DFB\u52A0\u65F6\u95F4",K(w.createdAt)],["\u6700\u8FD1\u4F7F\u7528",w.lastUsedAt===null?"\u2014":K(w.lastUsedAt)]]}),me(at,{marginTop:1,children:me(le,{width:t-ge,items:[{value:"rename",label:"\u91CD\u547D\u540D"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect: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(Ae,{width:t,title:"\u786E\u8BA4\u9000\u51FA\u8BE5\u8BBE\u5907\u7684\u767B\u5F55\uFF1F",confirmLabel:"\u9000\u51FA",busy:l,error:u,onConfirm:()=>{if(w.current){d("\u6B63\u5728\u9000\u51FA",()=>as(),{onSuccess:()=>{e.toast("ok","\u5DF2\u9000\u51FA\u767B\u5F55"),e.home()}});return}d("\u6B63\u5728\u9000\u51FA\u8BE5\u8BBE\u5907",()=>If(w.id),{onSuccess:()=>x("\u5DF2\u9000\u51FA\u8BE5\u8BBE\u5907")})},onCancel:g})}if(i.name==="session"){let w=i.item;return xn(at,{flexDirection:"column",children:[me(pe,{title:Go(w.device),note:w.current?"\u5F53\u524D\u8BBE\u5907":void 0,width:t,children:me(Ve,{width:t-ge,items:[["\u8BBE\u5907\u7C7B\u578B",w.device?.type!=null?lk[w.device.type]??w.device.type:"\u684C\u9762\u8BBE\u5907"],["\u5BA2\u6237\u7AEF",w.device?.client!=null?`${w.device.client} ${w.device.clientVersion??""}`.trim():"\u2014"],["\u64CD\u4F5C\u7CFB\u7EDF",w.device?.os!=null?`${w.device.os} ${w.device.osVersion??""}`.trim():"\u2014"],["\u8BBE\u5907\u578B\u53F7",w.device?.model!=null?`${w.device.vendor??""} ${w.device.model}`.trim():"\u2014"],["IP \u5730\u5740",w.ip],["\u767B\u5F55\u65F6\u95F4",K(w.loginAt)],["\u6700\u540E\u6D3B\u8DC3",K(w.lastActiveAt)],["\u767B\u5F55\u6709\u6548\u671F\u81F3",K(w.expiresAt)],["\u5BA2\u6237\u7AEF\u6807\u8BC6",w.userAgent??"\u2014"]]})}),l===null&&me(at,{marginTop:1,children:me(le,{width:t,items:[{value:"revoke",label:"\u9000\u51FA\u8BE5\u8BBE\u5907",labelTone:"danger"}],onSelect:()=>{m(),s({name:"confirm-revoke",item:w})}})})]})}let E=y.totp,W=h.phase==="ready"?h.data:null,M=W===null?null:W.todo,C=M===null?0:M.posts.filter(w=>w.status==="pending").length,v=M===null?0:M.posts.filter(w=>w.status==="rejected").length,_=_e([C>0&&`${C} \u7BC7\u5BA1\u6838\u4E2D`,v>0&&`${v} \u7BC7\u672A\u901A\u8FC7`]),L=[{heading:"\u793E\u533A"},{value:{kind:"my-posts"},label:"\u6211\u7684\u5E16\u5B50",hint:_===""?void 0:_},{value:{kind:"my-comments"},label:"\u6211\u7684\u8BC4\u8BBA"},{value:{kind:"bookmarks"},label:"\u6211\u7684\u6536\u85CF"},{value:{kind:"drafts"},label:"\u6211\u7684\u8349\u7A3F",hint:M!==null&&M.drafts>0?`${M.drafts} \u7BC7\u672A\u53D1\u5E03`:void 0},{heading:""},{heading:"\u8D26\u6237"},{value:{kind:"avatar"},label:"\u4FEE\u6539\u5934\u50CF",hint:N===null?"\u663E\u793A\u5728\u4E2A\u4EBA\u4E3B\u9875\u548C\u4F60\u7684\u53D1\u8A00\u4E2D":cd(N)},{value:{kind:"rename"},label:"\u4FEE\u6539\u7528\u6237\u540D",hint:"\u4FEE\u6539\u540E\u4E2A\u4EBA\u4E3B\u9875\u5730\u5740\u968F\u4E4B\u6539\u53D8"},{value:{kind:"email"},label:"\u4FEE\u6539\u90AE\u7BB1",hint:"\u9700\u8981\u90AE\u7BB1\u9A8C\u8BC1\u7801\u4E0E\u5F53\u524D\u5BC6\u7801"},{value:{kind:"password"},label:"\u4FEE\u6539\u5BC6\u7801",hint:"\u4FEE\u6539\u540E\u5176\u4ED6\u8BBE\u5907\u5C06\u9000\u51FA\u767B\u5F55"},...S.avatarUrl===null?[]:[{value:{kind:"avatar-delete"},label:"\u5220\u9664\u5934\u50CF",labelTone:"danger"}],{heading:""},{heading:"\u4E24\u6B65\u9A8C\u8BC1"},...E.enabled?[{value:{kind:"code",intent:"rebind"},label:"\u91CD\u65B0\u7ED1\u5B9A",hint:"\u751F\u6210\u65B0\u5BC6\u94A5\u5E76\u66F4\u6362\u6062\u590D\u7801"},{value:{kind:"code",intent:"regenerate"},label:"\u91CD\u65B0\u751F\u6210\u6062\u590D\u7801",hint:"\u539F\u6709\u6062\u590D\u7801\u5168\u90E8\u4F5C\u5E9F"},{value:{kind:"code",intent:"disable"},label:"\u505C\u7528",labelTone:"danger"}]:[{value:{kind:"enable"},label:"\u542F\u7528\u4E24\u6B65\u9A8C\u8BC1",hint:"\u767B\u5F55\u65F6\u8981\u6C42\u989D\u5916\u8F93\u5165\u9A8C\u8BC1\u5668\u52A8\u6001\u7801"}],{heading:""},{heading:"Passkey"},...y.passkeys.length===0?[{value:{kind:"none"},label:"\u6682\u65E0 Passkey",hint:"\u6DFB\u52A0\u540E\u53EF\u4F7F\u7528\u6307\u7EB9\u3001\u9762\u5BB9\u6216\u786C\u4EF6\u5BC6\u94A5\u4E00\u6B65\u767B\u5F55",disabled:!0}]:[],...y.passkeys.map(w=>({value:{kind:"passkey",item:w},label:w.name,hint:`\u6700\u8FD1\u4F7F\u7528 ${w.lastUsedAt===null?"\u2014":K(w.lastUsedAt)}`})),{value:{kind:"add-passkey"},label:"\u6DFB\u52A0 Passkey",hint:"\u9700\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"},{heading:""},{heading:"\u767B\u5F55\u8BBE\u5907"},...R.map(w=>({value:{kind:"session",item:w},label:w.current?`${Go(w.device)}\uFF08\u5F53\u524D\u8BBE\u5907\uFF09`:Go(w.device),...w.current?{labelTone:"accent"}:{},hint:`${w.ip} \xB7 \u6700\u540E\u6D3B\u8DC3 ${K(w.lastActiveAt)}`})),{value:{kind:"logout-all"},label:"\u9000\u51FA\u6240\u6709\u8BBE\u5907",labelTone:"danger",hint:"\u5F53\u524D\u8BBE\u5907\u4E5F\u4F1A\u4E00\u5E76\u9000\u51FA"}],P=W===null?null:W.homepage,B=[["\u7528\u6237\u540D",st(S.username)],["\u90AE\u7BB1",S.email],...E.enabled?[["\u4E24\u6B65\u9A8C\u8BC1",`\u542F\u7528\u4E8E ${E.enabledAt===null?"\u2014":K(E.enabledAt)}`],["\u6062\u590D\u7801",E.recoveryCodesRemaining===0?"\u5DF2\u5168\u90E8\u7528\u5B8C\uFF0C\u8BF7\u91CD\u65B0\u751F\u6210":`\u5269\u4F59 ${E.recoveryCodesRemaining} \u679A\uFF0C\u9A8C\u8BC1\u5668\u4E0D\u53EF\u7528\u65F6\u53EF\u4EE3\u66FF\u52A8\u6001\u7801\u767B\u5F55`]]:[],...P===null?[]:[["\u7B49\u7EA7",Ki(P.identity.points)],["\u79EF\u5206",`${P.identity.points} \xB7 ${Yi(P.identity.points)}`],["\u52A0\u5165\u65F6\u95F4",jr(P.joinedAt)]]],J=h.phase==="error"?h:null,oe=P!==null?Ut(dk,t)+X:J!==null?(J.hint===void 0?1:2)+X:0,fe=Js(B.length,t)+X+oe,$=X+Xe+To,ne=P!==null&&cr(t)&&r-fe-$>=pk;return xn(at,{flexDirection:"column",children:[me(Ve,{width:t,items:B}),P!==null&&me(at,{marginTop:X,children:me(it,{width:t,tiles:[{label:"\u5E16\u5B50",value:String(P.stats.posts)},{label:"\u8BC4\u8BBA",value:String(P.stats.comments)},{label:"\u83B7\u8D5E",value:String(P.stats.likesReceived)}]})}),J!==null&&me(at,{marginTop:X,children:me(Ft,{message:`\u793E\u533A\u6570\u636E\u8BFB\u53D6\u5931\u8D25\uFF1A${J.message}`,hint:J.hint,width:t})}),ne&&xn(at,{marginTop:X,flexDirection:"column",children:[me(Rn,{title:"\u793E\u533A\u8DB3\u8FF9",width:t}),me(at,{marginTop:Ge,flexDirection:"column",children:me(lr,{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:S.username}):w.kind==="my-comments"?e.push("my-comments",{username:S.username}):w.kind==="bookmarks"?e.push("bookmarks"):w.kind==="drafts"?e.push("drafts"):w.kind==="avatar"?s({name:"avatar"}):w.kind==="avatar-delete"?s({name:"avatar-delete"}):w.kind==="rename"?s({name:"rename"}):w.kind==="email"?s({name:"email"}):w.kind==="password"?s({name:"password"}):w.kind==="logout-all"?s({name:"confirm-logout-all"}):w.kind==="enable"?d("\u6B63\u5728\u751F\u6210\u5BC6\u94A5",()=>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 xk}from"ink";import{useRef as Lg,useState as fr}from"react";import Tk from"string-width";var _g=12e4,Pg=e=>A(mt($i),Ue("/tickets",{...e})),Ag=e=>A(bu,"/tickets",{method:"POST",json:e}),Gl=e=>A(ku,`/tickets/${e}`),Eg=(e,t,n)=>A(se,`/tickets/${e}/messages`,{method:"POST",json:{content:t,attachmentIds:n}}),hk=e=>A(wu,Ue("/tickets/attachments",{filename:e.fileName,contentType:e.contentType}),{method:"POST",body:e.bytes,headers:{"content-type":"application/octet-stream"},timeoutMs:_g}),yk=e=>A(se,`/tickets/attachments/${e}`,{method:"DELETE"}),sa={upload:hk,discard:yk},Mg=(e,t)=>cs(`/tickets/${e}/attachments/${t}`,{timeoutMs:_g}),Ig=e=>A(se,`/tickets/${e}/close`,{method:"POST"}),Ng=e=>A(se,`/tickets/${e}/reopen`,{method:"POST"});import{useEffect as bk,useRef as Sk}from"react";function aa(e,t,n=!0){let o=Sk(t);o.current=t,bk(()=>{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 wk=5e3,kk=11,vk=3,Og=1;function Ck(e,t){let n=[],o=r=>{let i=r.spans.reduce((a,c)=>a+Tk(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:Vn(r.content),color:f.foreground}],Math.max(8,t-4)),l=r.attachments.map(u=>({spans:[{text:"[\u9644\u4EF6] ",color:f.faintForeground},{text:u.fileName,color:f.foreground},{text:` (${Ko(u.fileSize)})`,color:f.mutedForeground}]}));s?n.push(o(a),...c.map(o),...l.map(o)):n.push(a,...c,...l)}),n}function Dg({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=fr("main"),[s,a]=fr(!1),[c,l]=fr(null),[u,m]=fr(null),[p,d]=fr(0),{busy:b,error:h,reset:g,fail:x,run:T}=ue();Re(b!==null);let k=Q([e.id,t.revision],async()=>{let[L,P]=await Promise.all([Gl(e.id),Be(t.ctx.site)]);return{detail:L,site:P}}),[S,y]=fr(null),R=Lg(0),N=Lg(t.revision);N.current!==t.revision&&(N.current=t.revision,R.current+=1,S!==null&&y(null));let E=k.phase==="ready"?k.data:null,W=S??E?.detail??null;aa(wk,async()=>{if(W===null||b!==null)return;let L=R.current,P=await Gl(e.id);L===R.current&&(P.ticket.updatedAt!==W.ticket.updatedAt||P.messages.length!==W.messages.length)&&y(P)},r==="main"&&E!==null);let M=W?.messages.some(L=>L.attachments.length>0)??!1;G(L=>{r!=="main"||s||b!==null||(L==="r"?t.reload():L==="x"&&W!==null&&W.ticket.status!=="closed"?(g(),i("confirm-close")):L==="a"&&M&&(g(),l(null),m(null),i("attachments")))}),xk((L,P)=>{P.tab&&r==="main"&&!s&&W?.ticket.status!=="closed"&&a(!0)},{isActive:r==="main"&&!s&&b===null});let C=()=>{if(r!=="main"){g(),i("main");return}if(s){a(!1);return}t.pop()},v=(L,P)=>{T("\u6B63\u5728\u53D1\u9001",()=>Mn(P,sa,B=>Eg(e.id,L,B.map(J=>J.id))),{onSuccess:()=>{a(!1),d(B=>B+1),t.reload(),t.toast("ok","\u5DF2\u53D1\u9001")}})},_=r==="main"&&!s?["\u2191\u2193 \u6EDA\u52A8",...W?.ticket.status==="closed"?[]:["Tab \u56DE\u590D"],...M?["a \u9644\u4EF6"]:[],...W?.ticket.status==="closed"?[]:["x \u5173\u95ED\u5DE5\u5355"],"r \u5237\u65B0"]:[];return Ht(Y,{trail:["\u5DE5\u5355\u652F\u6301",W?.ticket.title??"\u5DE5\u5355\u8BE6\u60C5"],hints:_,onEscape:C,isActive:b===null,children:Ht(V,{state:k,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:n,children:({site:L,detail:P})=>{let B=S??P,J=B.ticket,oe=J.status==="closed";if(r==="confirm-close")return Ht(Ae,{width:n,title:"\u5173\u95ED\u5DE5\u5355",detail:`\u786E\u5B9A\u5173\u95ED\u5DE5\u5355\u300C${J.title}\u300D\u5417\uFF1F\u5173\u95ED\u540E\u53EF\u91CD\u65B0\u6253\u5F00`,confirmLabel:"\u5173\u95ED\u5DE5\u5355",busy:b,error:h,onConfirm:()=>T("\u6B63\u5728\u5173\u95ED",()=>Ig(e.id),{onSuccess:()=>{i("main"),t.reload(),t.toast("ok","\u5DF2\u5173\u95ED")}}),onCancel:C});if(r==="attachments")return u!==null?Ht(ur,{title:`\u4FDD\u5B58\u9644\u4EF6 \u2014 ${u.fileName}`,width:n,download:async()=>({fileName:u.fileName,bytes:await Mg(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:b===null,items:[{heading:"\u9644\u4EF6"},...B.messages.flatMap(w=>w.attachments.map(U=>({value:U,label:U.fileName,hint:`${Rt(w.author)} \xB7 ${Ko(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?Og:0,$=oe?vk:s?kk:Og,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:Ck(B.messages,n),height:ne,isActive:!s&&b===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:b===null,items:[{value:"reopen",label:"\u91CD\u65B0\u6253\u5F00"}],onSelect:()=>T("\u6B63\u5728\u91CD\u65B0\u6253\u5F00",()=>Ng(e.id),{failToast:!0,onSuccess:()=>{t.reload(),t.toast("ok","\u5DF2\u91CD\u65B0\u6253\u5F00")}})})]}):s?Ht(te,{title:"\u56DE\u590D\u5DE5\u5355",width:n,submitLabel:"\u53D1\u9001\u56DE\u590D",busy:b!==null,busyLabel:b??"\u6B63\u5728\u53D1\u9001",error:h,fields:[{kind:"textarea",name:"content",label:"\u56DE\u590D\u5185\u5BB9",rows:3,maxLength:5e3,placeholder:"\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9",optional:!0},Zn(dr)],onCancel:()=>a(!1),onSubmit:w=>{let U=(w.content??"").trim(),re;try{re=Jn(w.attachments??"",dr)}catch(D){x(Se(D));return}if(U===""&&re.length===0){x("\u8BF7\u8F93\u5165\u56DE\u590D\u5185\u5BB9\u6216\u9644\u4EF6\u8DEF\u5F84");return}v(U,re)}},p):Ht(la,{color:f.faintForeground,children:"\u6309 Tab \u64B0\u5199\u56DE\u590D"})})]})}})})}import{Box as Rk}from"ink";import{useState as _k}from"react";import{jsx as Co,jsxs as Ek}from"react/jsx-runtime";var Pk=Pt(rc,Wc,"\u5168\u90E8\u72B6\u6001"),Ak={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"},Wl={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:Ak};function $g(){let e=O(),{width:t}=j(),n=Z(),[o,r]=_k({name:"list"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=ue(),p=ze([e.revision,i],h=>Pg({page:h,...i===""?{}:{status:i}}),{retain:"page"}),d=o.name==="list";G((h,g)=>{d&&(h==="r"?e.reload():h==="f"?r({name:"filter"}):h==="n"?r({name:"create-category"}):g.leftArrow?p.go(-1):g.rightArrow&&p.go(1))});let b=()=>{o.name==="list"?e.pop():o.name==="create"?r({name:"create-category"}):(l(),r({name:"list"}))};return Co(Y,{hints:d?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","n \u65B0\u5EFA","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:b,children:o.name==="filter"?Co(te,{title:"\u7B5B\u9009\u5DE5\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:Pk,initial:i}],onCancel:b,onSubmit:h=>{s(h.status??""),p.reset(),r({name:"list"})}}):o.name==="create-category"?Co(le,{width:t,height:n,items:[{heading:"\u5206\u7C7B"},...ic.map(h=>({value:h,label:ts(h),hint:Wl[h].title}))],onSelect:h=>r({name:"create",category:h})}):o.name==="create"?Co(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(h=>({value:h,label:Vc(h).label})),initial:"normal"},{kind:"text",name:"title",label:"\u6807\u9898",placeholder:Wl[o.category].title},{kind:"textarea",name:"content",label:"\u95EE\u9898\u63CF\u8FF0",rows:5,maxLength:5e3,placeholder:Wl[o.category].content},Zn(dr)],onCancel:b,onSubmit:h=>{let g=(h.title??"").trim(),x=(h.content??"").trim();if(g===""){u("\u8BF7\u586B\u5199\u6807\u9898");return}if(x===""){u("\u8BF7\u586B\u5199\u95EE\u9898\u63CF\u8FF0");return}let T;try{T=Jn(h.attachments??"",dr)}catch(k){u(Se(k));return}m("\u6B63\u5728\u63D0\u4EA4\u5DE5\u5355",()=>Mn(T,sa,k=>Ag({title:g,category:o.category,priority:h.priority??"normal",content:x,attachmentIds:k.map(S=>S.id)})),{onSuccess:k=>{r({name:"list"}),p.reset(),e.reload(),e.push("ticket",{id:k.id}),e.toast("ok","\u5DE5\u5355\u5DF2\u63D0\u4EA4")}})}}):Co(V,{state:p.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5DE5\u5355",width:t,children:h=>Ek(Rk,{flexDirection:"column",children:[Co(de,{retain:"list",items:h.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},{label:"\u4F18\u5148\u7EA7"},{label:"\u5206\u7C7B"},{label:"\u6700\u540E\u66F4\u65B0"},{label:"\u72B6\u6001",align:"right"}],row:g=>[g.title,bt(Vc(g.priority)),ts(g.category),K(g.updatedAt),bt(Wc(g.status))],onOpen:g=>e.push("ticket",{id:g.id}),emptyLabel:i===""?"\u6682\u65E0\u5DE5\u5355":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u9047\u5230\u95EE\u9898\u65F6\u53EF\u65B0\u5EFA\u5DE5\u5355\uFF0C\u7BA1\u7406\u5458\u4F1A\u5C3D\u5FEB\u56DE\u590D":void 0}),Co(We,{page:p.page,pages:p.pages,total:p.total,width:t})]})})})}import{Box as Mk}from"ink";import{jsx as hi}from"react/jsx-runtime";function Bg({params:e}){let t=O(),{width:n}=j(),o=Z(),r=Q([e.type,t.revision],()=>Bd(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(Mk,{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 Fg=(e,t)=>fn(se,`${e}/api/auth/send-code`,{json:t});async function Ug(e,t){let n=await Jt(`${e}/api/auth/register`,{json:t});sn(n);let o=zo.parse(n.data);return Vr(e,Wr({refresh:null,device:null},n.headers),o)}var jg=(e,t)=>fn(se,`${e}/api/auth/forgot-password`,{json:t}),Hg=(e,t)=>fn(se,`${e}/api/auth/reset-password`,{json:t});import{jsx as qg}from"react/jsx-runtime";function Gg(){let e=O(),{width:t}=j(),{busy:n,error:o,fail:r,run:i}=ue();return Re(n!==null),qg(Y,{trail:["\u627E\u56DE\u5BC6\u7801"],isActive:n===null,children:qg(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=>jg(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",()=>Hg(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 Kl,Text as Nk}from"ink";import{useState as Wg}from"react";import{Box as zg}from"ink";import{jsx as Vl,jsxs as Ik}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 Ik(zg,{flexDirection:"column",children:[Vl(ye,{tone:"info",width:t,title:`\u7EE7\u7EED\u524D\u8BF7\u9605\u8BFB\u5E76\u540C\u610F${r.join("\u4E0E")}`}),Vl(zg,{marginTop:1,children:Vl(le,{items:i,width:t,onSelect:s=>{s==="agree"?n():s==="terms"?o.push("agreement",{type:"terms"}):s==="privacy"?o.push("agreement",{type:"privacy"}):o.pop()}})})]})}import{jsx as eo,jsxs as Vg}from"react/jsx-runtime";function Kg(){let e=O(),{width:t}=j(),[n,o]=Wg({name:"credentials"}),[r,i]=Wg(!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,x)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>Dd(e.ctx.site,g,x),{onSuccess:T=>{if(T.status==="totp_required"){o({name:"factor",ticket:T.ticket,jar:T.jar});return}p(T.session.username)}})},b=(g,x)=>{u("\u6B63\u5728\u9A8C\u8BC1",()=>$d(e.ctx.site,g.jar,g.ticket,x,g.kind),{onSuccess:T=>p(T.username)})},h=()=>{n.name==="credentials"?e.pop():(c(),o({name:"credentials"}))};return Vg(Y,{trail:n.name==="credentials"?["\u767B\u5F55\u8D26\u53F7"]:["\u767B\u5F55\u8D26\u53F7","\u4E24\u6B65\u9A8C\u8BC1"],onEscape:h,isActive:s===null,children:[n.name==="credentials"&&eo(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:g=>ma(g.legal)&&!r?eo(ua,{legal:g.legal,width:t,onAgree:()=>i(!0)}):Vg(Kl,{flexDirection:"column",children:[eo(te,{title:"\u767B\u5F55",width:t,submitLabel:"\u767B\u5F55",error:a,busy:s!==null,busyLabel:s??"\u6B63\u5728\u9A8C\u8BC1",fields:[{kind:"text",name:"account",label:"\u8D26\u53F7",placeholder:"\u8BF7\u8F93\u5165\u7528\u6237\u540D\u6216\u90AE\u7BB1"},{kind:"text",name:"password",label:"\u5BC6\u7801",mask:!0,placeholder:"\u8BF7\u8F93\u5165\u5BC6\u7801"}],onCancel:h,onSubmit:x=>{let T=(x.account??"").trim(),k=x.password??"";if(T===""||k===""){l("\u8BF7\u586B\u5199\u8D26\u53F7\u4E0E\u5BC6\u7801");return}d(T,k)}}),eo(Kl,{marginTop:1,children:eo(Nk,{color:f.faintForeground,children:"Passkey \u767B\u5F55\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210"})})]})}),n.name==="factor"&&eo(le,{width:t,items:[{value:"totp",label:"\u52A8\u6001\u9A8C\u8BC1\u7801",hint:"\u8F93\u5165\u9A8C\u8BC1\u5668 App \u4E2D\u663E\u793A\u7684\u52A8\u6001\u9A8C\u8BC1\u7801"},{value:"recovery-code",label:"\u6062\u590D\u7801",hint:"\u8F93\u5165\u672A\u4F7F\u7528\u8FC7\u7684\u4E00\u6B21\u6027\u6062\u590D\u7801"}],onSelect:g=>o({name:"code",ticket:n.ticket,jar:n.jar,kind:g})}),n.name==="code"&&eo(Kl,{flexDirection:"column",children:eo(te,{title:"\u4E24\u6B65\u9A8C\u8BC1",width:t,submitLabel:"\u9A8C\u8BC1\u5E76\u767B\u5F55",error:a,busy:s!==null,busyLabel:s??"\u6B63\u5728\u9A8C\u8BC1",fields:[{kind:"text",name:"code",label:n.kind==="totp"?"\u52A8\u6001\u9A8C\u8BC1\u7801":"\u6062\u590D\u7801",placeholder:n.kind==="totp"?"6 \u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801":"\u8BF7\u8F93\u5165\u6062\u590D\u7801",hint:n.kind==="totp"?"\u8F93\u5165\u9A8C\u8BC1\u5668 App \u4E2D\u663E\u793A\u7684\u52A8\u6001\u9A8C\u8BC1\u7801":"\u8F93\u5165\u672A\u4F7F\u7528\u8FC7\u7684\u4E00\u6B21\u6027\u6062\u590D\u7801"}],onCancel:h,onSubmit:g=>{let x=(g.code??"").trim();if(x===""){l("\u8BF7\u586B\u5199\u9A8C\u8BC1\u7801");return}b(n,x)}})})]})}import{useState as Lk}from"react";import{jsx as da}from"react/jsx-runtime";function Yg(){let e=O(),{width:t}=j(),[n,o]=Lk(!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=>Fg(e.ctx.site,{email:u})},{kind:"text",name:"password",label:"\u5BC6\u7801",mask:!0,placeholder:`\u81F3\u5C11 ${Ot} \u4F4D`},{kind:"text",name:"invite",label:"\u9080\u8BF7\u7801",placeholder:"\u8BF7\u8F93\u5165\u9080\u8BF7\u7801",optional:!0}],onCancel:()=>e.pop(),onSubmit:u=>{let m=(u.username??"").trim(),p=(u.email??"").trim(),d=(u.code??"").trim(),b=u.password??"",h=(u.invite??"").trim();if(m===""||m.length>Kt){s(`\u8BF7\u8F93\u5165 1 \u5230 ${Kt} \u4E2A\u5B57\u7B26\u7684\u7528\u6237\u540D`);return}if(p===""||d===""){s("\u8BF7\u586B\u5199\u90AE\u7BB1\u4E0E\u9A8C\u8BC1\u7801");return}if(b.length<Ot){s(`\u5BC6\u7801\u81F3\u5C11 ${Ot} \u4F4D`);return}a("\u6B63\u5728\u6CE8\u518C",()=>Ug(e.ctx.site,{username:m,email:p,password:b,code:d,...h===""?{}:{inviteCode:h}}),{onSuccess:g=>{e.gate.announcementsChecked=!1,e.gate.announcementsShown=!1,e.toast("ok",`\u6CE8\u518C\u6210\u529F\uFF1A${g.username}`),e.home()}})}})})})}import{Box as yi}from"ink";import{useState as Ok}from"react";import{jsx as Nt,jsxs as Xg}from"react/jsx-runtime";var Dk=["category","title","content","attachments"],$k=11,Bk=2,Fk=3,Uk=16,Jg={new:"\u53D1\u5E03\u5E16\u5B50",draft:"\u7F16\u8F91\u8349\u7A3F",edit:"\u7F16\u8F91\u5E16\u5B50"};function jk(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 Hk(e,t){return e.find(n=>String(n.id)===t)?.description}function Qg({mode:e}){let t=O(),{width:n}=j(),o=Z(),r=jk(e),[i,s]=Me("values",()=>r),[a,c]=Ok(!1),{busy:l,error:u,fail:m,reset:p,run:d}=ue(),b=Q([],Us),h=Dk.some(E=>(i[E]??"")!==(r[E]??""));Re(h||l!==null);let g=E=>{let W=E.category??"";return{categoryId:W===""?null:Number(W),title:(E.title??"").trim(),content:(E.content??"").trim()}},x=(E,W)=>{let M;try{M=Jn(E.attachments??"",Xs)}catch(C){return m(Se(C)),null}return jt(W).length+M.length>Xs.maxCount?(m("\u9644\u4EF6\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650"),null):M},T=async E=>{switch(e.kind){case"new":return(await gf(E)).id;case"draft":return await Sf(e.draft.id,E),e.draft.id;case"edit":return await hf(e.post.id,E),e.post.id}},k=E=>{if(e.kind==="edit"&&!h){m("\u5185\u5BB9\u672A\u4FEE\u6539");return}let{categoryId:W,title:M,content:C}=g(E);if(W===null){m("\u8BF7\u9009\u62E9\u677F\u5757");return}if(M===""){m("\u8BF7\u586B\u5199\u6807\u9898");return}if(M.length>mo){m(`\u6807\u9898\u6700\u591A ${mo} \u4E2A\u5B57\u7B26`);return}let v=x(E,C);if(v!==null){if(C===""&&v.length===0){m("\u8BF7\u586B\u5199\u6B63\u6587");return}d("\u6B63\u5728\u63D0\u4EA4",()=>Mn(v,ai,_=>T({categoryId:W,title:M,content:pi(C,_)})),{onSuccess:_=>{t.toast("ok","\u5DF2\u63D0\u4EA4\u5BA1\u6838"),t.pop(),e.kind!=="edit"&&t.push("post",{id:_})}})}},S=(E,W)=>{let{categoryId:M,title:C,content:v}=g(E);if(C.length>mo){m(`\u6807\u9898\u6700\u591A ${mo} \u4E2A\u5B57\u7B26`);return}let _=x(E,v);_!==null&&d("\u6B63\u5728\u4FDD\u5B58\u8349\u7A3F",()=>Mn(_,ai,async L=>{let P={categoryId:M,title:C,content:pi(v,L)};W===null?await yf(P):await bf(W,P)}),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5B58\u8349\u7A3F")}})},y=e.kind==="draft"?e.draft.id:null,R=()=>{if(!h){t.pop();return}p(),c(!0)},N=()=>{if(!a){t.pop();return}p(),c(!1)};return G(E=>{E==="q"&&h&&R()},!a&&l===null),Nt(Y,{trail:["\u793E\u533A\u8BBA\u575B",Jg[e.kind]],onEscape:N,isActive:l===null,children:Nt(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u677F\u5757",width:n,children:E=>{if(a&&e.kind==="edit")return Nt(Ae,{width:n,title:"\u653E\u5F03\u4FEE\u6539",detail:"\u4FEE\u6539\u5C1A\u672A\u63D0\u4EA4\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F",confirmLabel:"\u653E\u5F03\u4FEE\u6539",onConfirm:t.pop,onCancel:N});if(a)return Xg(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"?S(i,y):L==="stay"?N():t.pop()}})})]});let W=e.kind==="edit"?0:1,M=e.kind==="edit"&&e.post.status==="published",C=M?Bk:0,v=Math.min(Uk,Math.max(Fk,o-$k-W-C-fi(u))),_=i.category??"";return Xg(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:Jg[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=>Hk(E,L)},{kind:"text",name:"title",label:"\u6807\u9898",initial:i.title,placeholder:"\u8BF7\u8F93\u5165\u5E16\u5B50\u6807\u9898"},{kind:"textarea",name:"content",label:"\u6B63\u6587",rows:v,maxLength:ji,initial:i.content,placeholder:"\u8BF7\u8F93\u5165\u6B63\u6587\uFF0C\u652F\u6301 Markdown"},{...Zn(Xs),initial:i.attachments}],secondary:e.kind==="edit"?void 0:{label:"\u5B58\u8349\u7A3F",onSubmit:L=>S(L,y)},onChange:s,onCancel:R,onSubmit:k})]})}})})}function Zg({params:e}){return Nt(Qg,{mode:e.draft===null?{kind:"new"}:{kind:"draft",draft:e.draft}})}function eh({params:e}){return Nt(Qg,{mode:{kind:"edit",post:e.post}})}import{Box as to,Text as Yl}from"ink";import{useEffect as Jl,useMemo as th,useState as pa}from"react";import{useRef as qk}from"react";function qt(e){let t=qk(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 Xl}from"react/jsx-runtime";var fa={kind:"floor"},Gk=2,nh=3,zk=4,ih=2,oh=3,rh="PgUp PgDn \u6EDA\u52A8\u6B63\u6587",ga=(e,t)=>{let n=na(Jo,e.status,e.reviewReason,t);return n===0?0:n+1};function Wk(e,t,n,o,r){let i=Math.max(ih+oh,o-Gk-ga(e,r)-3),s=Math.max(oh,Math.min(zk,i-nh)),a=Math.min(nh,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 Vk(e,t,n,o,r){let i=o-Xe-1-ga(e,r)-2-n;return Math.min(t.length,Math.max(ih,i))}function Kk(e,t,n,o){let r=e.status==="published"&&t.status==="published"&&n.status==="published",i=Ln(n.author,o);return[...r&&!i?[{value:"like",label:n.liked?"\u53D6\u6D88\u70B9\u8D5E":"\u70B9\u8D5E"}]:[],...r?[{value:"reply",label:"\u56DE\u590D"}]:[],...r&&!i?[{value:"report",label:"\u4E3E\u62A5"}]:[],...jt(n.content).length>0?[{value:"attachments",label:"\u9644\u4EF6"}]:[],{value:"author",label:"\u7528\u6237\u4E3B\u9875",hint:Rt(n.author)},...i?[{value:"delete",label:"\u5220\u9664",labelTone:"danger"}]:[]]}function sh({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),af(e.postId,e.floorId),En(),sr()]);return{post:w,floor:U,me:re.user,muted:D.muted}})),d=ze([e.floorId,t.revision],w=>cf(e.floorId,w),{retain:"replies-page"}),b=qt(d.state),h=p.phase==="ready"?p.data:null,g=b.phase==="ready"?b.data:null,[x,T]=pa(void 0);Jl(()=>T(void 0),[h]);let[k,S]=pa(new Map);Jl(()=>S(new Map),[g]);let y=h===null?null:{...h,floor:{...h.floor,...x}},R=g===null?[]:g.items.map(w=>({...w,...k.get(w.id)})),N=Tg(ld(R)),E=r.name==="actions"?R.find(w=>w.id===r.id)??null:null,W=s!==null&&R.some(w=>w.id===s);Jl(()=>{W&&a(null)},[W]);let M=y===null?null:y.floor.content,C=th(()=>M===null?[]:di(M,n),[M,n]),v=E===null?null:E.content,_=th(()=>v===null?[]:di(v,n-ge),[v,n]),L=y===null?null:Wk(y.floor,C,R.length,o-pr(y.muted,n),n),P=y===null||E===null?null:Kk(y.post,y.floor,E,y.me.username),B=E===null||P===null?null:Vk(E,_,P.length,o,n-ge),J=w=>y===null?null:w.kind==="floor"?y.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",()=>kf(w.id,!w.liked),{failToast:!0,onSuccess:({likeCount:re})=>U({liked:!w.liked,likeCount:re})})};G((w,U)=>{if(y===null||r.name!=="main"||c!==null)return;let{post:re,floor:D,me:z}=y,ee=re.status==="published"&&D.status==="published",he=Ln(D.author,z.username);w==="r"?t.reload():U.leftArrow?d.go(-1):U.rightArrow?d.go(1):w==="c"&&ee?i({name:"reply",target:fa}):w==="l"&&ee&&!he?oe(D,T):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=>S(z=>new Map(z).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(y===null)return[];if(r.name==="actions")return B===null?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C",..._.length>B?[rh]:[]];if(r.name!=="main"||L===null)return[];let{post:w,floor:U,me:re}=y,D=w.status==="published"&&U.status==="published",z=Ln(U.author,re.username);return[...R.length>0?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C"]:[],...C.length>L.bodyRows?[rh]:[],...D?["c \u56DE\u590D"]:[],...D&&!z?[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",...z?["d \u5220\u9664"]:[],"r \u5237\u65B0"]})(),onEscape:fe,isActive:r.name==="main"||c===null,children:Ee(V,{state:p,loading:"\u6B63\u5728\u8BFB\u53D6\u697C\u5C42",width:n,children:({post:w,floor:U,me:re,muted:D})=>{let z={...U,...x},ee=ie=>`${Ln(ie.author,re.username)?"\u83B7\u8D5E":ie.liked?"\u5DF2\u8D5E":"\u70B9\u8D5E"} ${ie.likeCount}`;if(r.name==="actions"){if(E===null||P===null||B===null)return Ee(ye,{tone:"info",width:n,title:"\u8BE5\u56DE\u590D\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"});let ie=n-ge;return Xl(pe,{title:Rt(E.author),note:K(E.createdAt),width:n,children:[Ee(Yl,{wrap:"truncate",color:f.mutedForeground,children:_e([E.replyTo!==null&&`\u56DE\u590D ${Zs(E.replyTo.author)}`,ee(E)])}),ga(E,ie)>0&&Ee(to,{marginTop:1,children:Ee(vo,{notices:Jo,status:E.status,reason:E.reviewReason,width:ie})}),Ee(to,{marginTop:1,children:Ee(pt,{lines:_,height:B,isActive:c===null,pageKeysOnly:!0})}),Ee(to,{marginTop:1,children:c!==null?Ee(Oe,{label:c}):Ee(le,{width:ie,items:P,onSelect:Qe=>$(E,Qe)})})]})}if(r.name!=="main"){let ie=J(r.target);if(ie===null)return Ee(ye,{tone:"info",width:n,title:"\u8BE5\u56DE\u590D\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u5220\u9664"});if(r.name==="reply")return Ee(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(Ae,{width:n,title:Qe?"\u5220\u9664\u8BC4\u8BBA":"\u5220\u9664\u56DE\u590D",detail:Qe?"\u5220\u9664\u540E\u8BE5\u697C\u5C42\u53CA\u5176\u5168\u90E8\u56DE\u590D\u5C06\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u5417\uFF1F":"\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u8FD9\u6761\u56DE\u590D\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:c,error:l,onConfirm:()=>m("\u6B63\u5728\u5220\u9664",()=>Tf(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 Xl(to,{flexDirection:"column",children:[Ee(ko,{muted:D,width:n}),Ee(Yl,{bold:!0,wrap:"truncate",color:f.foreground,children:w.title}),c!==null?Ee(Oe,{label:c}):Ee(Yl,{wrap:"truncate",color:f.mutedForeground,children:_e([z.floor!==null&&`#${z.floor}`,Rt(z.author),K(z.createdAt),`\u56DE\u590D ${z.replyCount}`,ee(z)])}),ga(z,n)>0&&Ee(to,{marginTop:1,children:Ee(vo,{notices:Jo,status:z.status,reason:z.reviewReason,width:n})}),Ee(to,{marginTop:1,children:Ee(pt,{lines:C,height:L.bodyRows,isActive:he,pageKeysOnly:!0})}),Ee(to,{marginTop:1,children:Ee(V,{state:b,loading:"\u6B63\u5728\u8BFB\u53D6\u56DE\u590D",width:n,children:()=>Xl(to,{flexDirection:"column",children:[Ee(de,{retain:"replies",items:N,width:n,height:L.listRows,isActive:he,columns:[Qn,{label:"\u56DE\u590D",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:({reply:ie,mention:Qe,prefix:Tt})=>[`${Tt}${Rt(ie.author)}`,Qe===null?wo(ie.content):`\u56DE\u590D ${Zs(Qe)}\uFF1A${wo(ie.content)}`,String(ie.likeCount),K(ie.createdAt),ie.status==="published"?"":bt(po(ie.status))],onOpen:({reply:ie})=>i({name:"actions",id:ie.id}),select:s===null?void 0:({reply:ie})=>ie.id===s,emptyLabel:"\u6682\u65E0\u56DE\u590D",emptyDescription:w.status==="published"&&z.status==="published"?"\u6309 c \u56DE\u590D\u672C\u697C":void 0}),Ee(We,{page:d.page,pages:d.pages,total:d.total,width:n})]})})})]})}})})}import{Box as Ro,Text as ba}from"ink";import{Box as ah}from"ink";import{jsx as gr,jsxs as ch}from"react/jsx-runtime";function ha({author:e,owner:t,width:n,height:o}){let r=O(),i=ze([e.kind,e.username,r.revision],a=>mf(e,a),{retain:"posts-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),gr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:a=>ch(ah,{flexDirection:"column",children:[gr(de,{retain:"posts",items:a.items,width:n,height:Math.max(3,o-1),columns:[{label:"\u6807\u9898",shrink:!0},...t?[{label:"\u8BF4\u660E",shrink:!0}]:[],mr,{label:"\u56DE\u590D",align:"right"},{label:"\u6D4F\u89C8",align:"right"},{label:"\u70B9\u8D5E",align:"right"},t?{label:"\u65F6\u95F4"}:{label:"\u65F6\u95F4",align:"right"},...t?[{label:"\u72B6\u6001",align:"right"}]:[]],row:c=>[c.title,...t?[$c(Hr,c)??""]:[],c.category.name,String(c.commentCount),String(c.viewCount),String(c.likeCount),K(c.publishedAt??c.createdAt),...t?[bt(po(c.status))]:[]],onOpen:c=>r.push("post",{id:c.id}),emptyLabel:"\u6682\u65E0\u5E16\u5B50"}),gr(We,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}function ya({author:e,owner:t,width:n,height:o}){let r=O(),i=ze([e.kind,e.username,r.revision],a=>uf(e,a),{retain:"comments-page"}),s=qt(i.state);return G((a,c)=>{c.leftArrow?i.go(-1):c.rightArrow&&i.go(1)}),gr(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u8BC4\u8BBA",width:n,children:a=>ch(ah,{flexDirection:"column",children:[gr(de,{retain:"comments",items:a.items,width:n,height:Math.max(3,o-1),columns:[{label:"\u8BC4\u8BBA",shrink:!0},...t?[{label:"\u8BF4\u660E",shrink:!0}]:[],{label:"\u5E16\u5B50",shrink:!0},{label:"\u70B9\u8D5E",align:"right"},{label:"\u65F6\u95F4"},...t?[{label:"\u72B6\u6001",align:"right"}]:[]],row:c=>[wo(c.content),...t?[$c(Jo,c)??""]:[],c.post.title??Xi,String(c.likeCount),K(c.createdAt),...t?[bt(po(c.status))]:[]],onOpen:c=>r.push("floor",{postId:c.post.id,floorId:c.floorId}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA"}),gr(We,{page:i.page,pages:i.pages,total:i.total,width:n})]})})}import{jsx as St,jsxs as Sa}from"react/jsx-runtime";var Yk=[{value:"posts",label:"\u5E16\u5B50"},{value:"comments",label:"\u8BC4\u8BBA"}],Jk=3,Xk=2,Qk=5;function Zk({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(Ro,{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 ${jr(e.joinedAt)}`])}),St(Ro,{marginTop:1,children:St(it,{width:n,tiles:[{label:"\u5E16\u5B50",value:String(i.posts)},{label:"\u8BC4\u8BBA",value:String(i.comments)},{label:"\u83B7\u8D5E",value:String(i.likesReceived)}]})}),o&&Sa(Ro,{marginTop:X,flexDirection:"column",children:[St(Rn,{title:"\u793E\u533A\u8DB3\u8FF9",width:n}),St(Ro,{marginTop:Ge,flexDirection:"column",children:St(lr,{data:e.activity,value:a=>a.count,caption:`\u8FD1\u4E00\u5E74\u5171 ${s} \u6B21`,width:n})})]})]})}function lh({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([lf(e.author),En()]),b=e.author.kind==="user"&&e.author.username===d.user.username;return{profile:p,owner:b}});G(p=>{p==="r"?t.reload():p==="t"&&i(d=>d==="posts"?"comments":"posts")});let a=Xk+1+Ut(Jk,n),c=o-a-2-1,l=X+Xe+To,u=cr(n)&&c-l>=Qk,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(Ro,{flexDirection:"column",children:[St(Zk,{profile:p,owner:d,width:n,heatmapOn:u}),St(Ro,{marginTop:1,children:St(Gs,{options:Yk,value:r,onChange:i,arrowKeys:!1})}),St(Ro,{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 mh}from"ink";import{useState as ev}from"react";import{jsx as _o,jsxs as dh}from"react/jsx-runtime";var tv={sort:"activity",categoryId:"",q:"",author:""},uh=e=>e.categoryId!==""||e.q!==""||e.author!=="",nv=(e,t)=>({page:t,sort:e.sort,...e.categoryId===""?{}:{categoryId:Number(e.categoryId)},...e.q===""?{}:{q:e.q},...e.author===""?{}:{author:e.author}});function ph(){let e=O(),{width:t}=j(),n=Z(),[o,r]=ev(!1),[i,s]=Me("filters",()=>tv),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[d,b]=await Promise.all([sr(),Us()]);return{muted:d.muted,categories:b}}),m=ze([e.revision,JSON.stringify(i)],d=>of(nv(i,d)),{retain:"page"});G((d,b)=>{o||(d==="r"?e.reload():d==="f"?r(!0):d==="n"?e.push("compose",{draft:null}):b.leftArrow?m.go(-1):b.rightArrow&&m.go(1))});let p=()=>{if(!o){e.pop();return}l(),r(!1)};return _o(Y,{hints:o?[]:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","n \u53D1\u5E03\u5E16\u5B50","f \u7B5B\u9009","r \u5237\u65B0"],onEscape:p,children:_o(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u793E\u533A",width:t,children:({muted:d,categories:b})=>o?_o(te,{title:"\u7B5B\u9009\u5E16\u5B50",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"select",name:"sort",label:"\u6392\u5E8F",options:ac.map(h=>({value:h,label:Cd(h)})),initial:i.sort},{kind:"select",name:"category",label:"\u677F\u5757",options:[{value:"",label:"\u5168\u90E8\u677F\u5757"},...b.map(h=>({value:String(h.id),label:h.name}))],initial:i.categoryId},{kind:"text",name:"q",label:"\u5173\u952E\u8BCD",initial:i.q,placeholder:"\u641C\u7D22\u6807\u9898\u6216\u6B63\u6587"},{kind:"text",name:"author",label:"\u4F5C\u8005",initial:i.author,placeholder:"\u8F93\u5165\u4F5C\u8005\u5B8C\u6574\u7528\u6237\u540D"}],onCancel:p,onSubmit:h=>{let g=(h.q??"").trim(),x=(h.author??"").trim();if(g.length>qi){c(`\u5173\u952E\u8BCD\u6700\u591A ${qi} \u4E2A\u5B57\u7B26`);return}if(x.length>Kt){c(`\u7528\u6237\u540D\u6700\u591A ${Kt} \u4E2A\u5B57\u7B26`);return}s({sort:h.sort,categoryId:h.category??"",q:g,author:x}),m.reset(),l(),r(!1)}}):dh(mh,{flexDirection:"column",children:[_o(ko,{muted:d,width:t}),_o(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:t,children:h=>dh(mh,{flexDirection:"column",children:[_o(de,{retain:"list",items:h.items,width:t,height:Math.max(3,n-1-pr(d,t)),columns:[{label:"\u4E3B\u9898",shrink:!0},Qn,mr,{label:"\u56DE\u590D",align:"right"},{label:"\u6D4F\u89C8",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:g=>[g.title,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:uh(i)?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u5E16\u5B50",emptyDescription:uh(i)?void 0:"\u6309 n \u53D1\u5E03\u7B2C\u4E00\u7BC7\u5E16\u5B50"}),_o(We,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})})})}import{Box as xa}from"ink";import{useState as ov}from"react";import{jsx as ft,jsxs as xh}from"react/jsx-runtime";var rv=X+Xe+2,iv=X+2+1+2;function gh(){let e=O();G(t=>{t==="r"&&e.reload()})}function hh({params:e}){let{width:t}=j(),n=Z();return gh(),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 yh({params:e}){let{width:t}=j(),n=Z();return gh(),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 bh(){let e=O(),{width:t}=j(),n=Z(),o=ze([e.revision],r=>df(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=>xh(xa,{flexDirection:"column",children:[ft(de,{retain:"list",items:r.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u6807\u9898",shrink:!0},Qn,{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u6700\u540E\u6D3B\u52A8",align:"right"}],row:i=>[i.title,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(We,{page:o.page,pages:o.pages,total:o.total,width:t})]})})})}var fh=e=>e.title===""?"\u672A\u547D\u540D\u8349\u7A3F":e.title;function Sh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=ov({name:"list"}),{busy:i,error:s,reset:a,run:c}=ue();Re(i!==null);let l=ze([e.revision],d=>pf(d),{retain:"page"}),u=o.name==="list";G((d,b)=>{u&&(d==="r"?e.reload():b.leftArrow?l.go(-1):b.rightArrow&&l.go(1))});let m=()=>{if(u){e.pop();return}a(),r({name:"list"})},p=o.name==="actions"?rv:o.name==="confirm-delete"?iv+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=>xh(xa,{flexDirection:"column",children:[ft(de,{retain:"list",items:d.items,width:t,height:Math.max(3,n-1-p),isActive:u,columns:[{label:"\u6807\u9898",shrink:!0},mr,{label:"\u521B\u5EFA\u65F6\u95F4",align:"right"}],row:b=>[fh(b),b.category===null?"\u2014":b.category.name,K(b.createdAt)],onOpen:b=>r({name:"actions",draft:b}),emptyLabel:"\u6682\u65E0\u8349\u7A3F",emptyDescription:"\u53D1\u5E03\u5E16\u5B50\u65F6\u53EF\u9009\u62E9\u5B58\u4E3A\u8349\u7A3F"}),ft(We,{page:l.page,pages:l.pages,total:l.total,width:t}),o.name==="actions"&&ft(xa,{marginTop:X,children:ft(pe,{title:fh(o.draft),width:t,children:ft(le,{width:t-ge,items:[{value:"edit",label:"\u7EE7\u7EED\u7F16\u8F91"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:b=>{if(b==="edit"){r({name:"list"}),e.push("compose",{draft:o.draft});return}a(),r({name:"confirm-delete",draft:o.draft})}})})}),o.name==="confirm-delete"&&ft(xa,{marginTop:X,children:ft(Ae,{width:t,title:"\u5220\u9664\u8349\u7A3F",detail:"\u5220\u9664\u540E\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u8FD9\u7BC7\u8349\u7A3F\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:i,error:s,onConfirm:()=>c("\u6B63\u5728\u5220\u9664",()=>Hs(o.draft.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:m})})]})})})}import{Box as Po,Text as Ql}from"ink";import{useEffect as Ta,useMemo as sv,useRef as av,useState as Zl}from"react";import{jsx as Ke,jsxs as em}from"react/jsx-runtime";var Th=2,cv=2,lv=2;function mv({post:e,width:t,height:n,isActive:o,follow:r,onFollowed:i}){let s=O(),a=ze([e.id,s.revision],u=>sf(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=>em(Po,{flexDirection:"column",children:[Ke(de,{retain:"floors",items:u.items,width:t,height:Math.max(3,n-1),isActive:o,columns:[{label:"\u697C\u5C42"},Qn,{label:"\u5185\u5BB9",shrink:!0},{label:"\u56DE\u590D",align:"right"},{label:"\u70B9\u8D5E",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:m=>[m.floor===null?"\u2014":`#${m.floor}`,Rt(m.author),wo(m.content),String(m.replyCount),String(m.likeCount),m.status==="published"?"":bt(po(m.status))],onOpen:m=>s.push("floor",{postId:e.id,floorId:m.id}),emptyLabel:"\u6682\u65E0\u8BC4\u8BBA",emptyDescription:e.status==="published"?"\u6309 c \u53D1\u8868\u7B2C\u4E00\u6761\u8BC4\u8BBA":void 0,select:r===null?void 0:m=>m.id===r}),Ke(We,{page:a.page,pages:a.pages,total:a.total,width:t})]})})}function wh({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=Me("mode",()=>"body"),[s,a]=Zl({name:"main"}),[c,l]=Zl(null),{busy:u,error:m,reset:p,run:d}=ue();Re(s.name==="confirm-delete"&&u!==null);let b=av(null),h=qt(Q([e.id,t.revision],async()=>{let[M,C,v]=await Promise.all([js(e.id),En(),sr()]);return{post:M,me:C.user,muted:v.muted}})),g=h.phase==="ready"?h.data:null,[x,T]=Zl(null);Ta(()=>T(null),[g]);let k=g===null?null:{...g,post:{...g.post,...x}},S=k!==null&&k.post.status==="published";Ta(()=>{!S||b.current===e.id||(b.current=e.id,rf(e.id).catch(()=>t.toast("warn","\u6D4F\u89C8\u8BA1\u6570\u53D1\u9001\u5931\u8D25")))},[e.id,S]);let y=s.name==="main"&&u===null,R=k===null?null:k.post.content,N=sv(()=>R===null?[]:di(R,n),[R,n]);G(M=>{if(k===null||!y)return;let{post:C,me:v}=k;if(M==="r"){t.reload();return}if(M==="v"){i(r==="body"?"floors":"body");return}if(M==="c"&&S){a({name:"comment"});return}if(r!=="body")return;let _=Ln(C.author,v.username),L={liked:C.liked,likeCount:C.likeCount,bookmarked:C.bookmarked};M==="l"&&S&&!_?d(C.liked?"\u6B63\u5728\u53D6\u6D88\u70B9\u8D5E":"\u6B63\u5728\u70B9\u8D5E",()=>wf(C.id,!C.liked),{failToast:!0,onSuccess:({likeCount:P})=>T({...L,liked:!C.liked,likeCount:P})}):M==="b"&&S?d(C.bookmarked?"\u6B63\u5728\u53D6\u6D88\u6536\u85CF":"\u6B63\u5728\u6536\u85CF",()=>vf(C.id,!C.bookmarked),{failToast:!0,onSuccess:()=>{T({...L,bookmarked:!C.bookmarked}),t.toast("ok",C.bookmarked?"\u5DF2\u53D6\u6D88\u6536\u85CF":"\u5DF2\u6536\u85CF")}}):M==="p"&&S&&!_?a({name:"report"}):M==="a"&&jt(C.content).length>0?a({name:"attachments"}):M==="u"?t.push("homepage",{author:ui(C.author)}):M==="e"&&_&&C.status!=="removed"?t.push("post-edit",{post:C}):M==="d"&&_&&(p(),a({name:"confirm-delete"}))});let E=()=>{if(s.name!=="main"){p(),a({name:"main"});return}if(r==="floors"){i("body");return}t.pop()},W=()=>{if(k===null||s.name!=="main")return[];let{post:M,me:C}=k;if(r==="floors")return["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...S?["c \u8BC4\u8BBA"]:[],"v \u6B63\u6587","r \u5237\u65B0"];let v=Ln(M.author,C.username);return["\u2191\u2193 \u6EDA\u52A8","v \u697C\u5C42\u5217\u8868",...S?["c \u8BC4\u8BBA",...v?[]:[M.liked?"l \u53D6\u6D88\u70B9\u8D5E":"l \u70B9\u8D5E"],M.bookmarked?"b \u53D6\u6D88\u6536\u85CF":"b \u6536\u85CF",...v?[]:["p \u4E3E\u62A5"]]:[],...jt(M.content).length>0?["a \u9644\u4EF6"]:[],"u \u7528\u6237\u4E3B\u9875",...v&&M.status!=="removed"?["e \u7F16\u8F91\u5E16\u5B50"]:[],...v?["d \u5220\u9664"]:[],"r \u5237\u65B0"]};return Ke(Y,{trail:["\u793E\u533A\u8BBA\u575B",k===null?"\u5E16\u5B50\u8BE6\u60C5":k.post.category.name,...r==="floors"&&s.name==="main"?["\u697C\u5C42\u5217\u8868"]:[]],hints:W(),onEscape:E,isActive:s.name==="main"||u===null,children:Ke(V,{state:h,loading:"\u6B63\u5728\u8BFB\u53D6\u5E16\u5B50",width:n,children:({post:M,me:C,muted:v})=>{let _={...M,...x},L=Ln(_.author,C.username);if(s.name==="comment")return Ke(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(Ae,{width:n,title:"\u5220\u9664\u5E16\u5B50",detail:"\u5220\u9664\u540E\u5E16\u5B50\u53CA\u5176\u5168\u90E8\u8BC4\u8BBA\u5C06\u65E0\u6CD5\u6062\u590D\uFF0C\u786E\u5B9A\u5220\u9664\u5417\uFF1F",confirmLabel:"\u5220\u9664",busy:u,error:m,onConfirm:()=>d("\u6B63\u5728\u5220\u9664",()=>Hs(_.id),{onSuccess:()=>{t.pop(),t.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:E});let P=Ke(Ql,{bold:!0,wrap:"truncate",color:f.foreground,children:_.title}),B=pr(v,n);if(r==="floors")return em(Po,{flexDirection:"column",children:[Ke(ko,{muted:v,width:n}),P,Ke(Po,{marginTop:1,children:Ke(mv,{post:_,width:n,height:o-Th-B,isActive:y,follow:c,onFollowed:()=>l(null)})})]});let J=na(Hr,_.status,_.reviewReason,n),oe=Math.max(lv,o-B-Th-(J===0?0:J+1)-1-cv);return em(Po,{flexDirection:"column",children:[Ke(ko,{muted:v,width:n}),P,Ke(Ql,{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(Po,{marginTop:1,children:Ke(vo,{notices:Hr,status:_.status,reason:_.reviewReason,width:n})}),Ke(Po,{marginTop:1,children:Ke(pt,{lines:N,height:oe,isActive:y})}),Ke(Po,{marginTop:1,children:u!==null?Ke(Oe,{label:u}):Ke(Ql,{wrap:"truncate",color:f.mutedForeground,children:_e([`\u8BC4\u8BBA ${_.commentCount}`,`${L?"\u83B7\u8D5E":_.liked?"\u5DF2\u8D5E":"\u70B9\u8D5E"} ${_.likeCount}`,_.bookmarked&&"\u5DF2\u6536\u85CF"])})})]})}})})}import{Box as Eo}from"ink";import{useEffect as xv,useRef as Tv,useState as om}from"react";import{z as H}from"zod";var uv=H.object({balance:H.number(),today:H.object({requests:H.number(),tokens:H.number(),cost:H.number()})}),kh=()=>A(uv,"/dashboard/summary"),vh=["all","30d","7d"],dv=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()}),tm=e=>A(dv,Ue("/dashboard/stats",{range:e})),pv=H.object({id:H.number().int(),requestId:H.string(),tokenName:H.string(),protocol:Fm,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:Iu,status:Vm,httpStatus:H.number().int(),stopReason:H.string().nullable(),latencyMs:H.number(),firstByteMs:H.number().nullable(),stream:H.boolean(),ip:H.string(),createdAt:H.string()}),Ch=e=>A(mt(pv),Ue("/logs",{...e})),fv=H.object({quotaCost:H.number(),rpm:H.number(),tpm:H.number(),concurrency:H.number()}),Rh=e=>A(fv,Ue("/logs/stats",{...e})),gv=H.object({id:H.number().int(),type:Gm,amount:H.number(),balanceAfter:H.number(),refType:zm,refId:H.string().nullable(),createdAt:H.string()}),_h=e=>A(mt(gv),Ue("/quota-ledger",{...e}));import{Box as hv,Text as ln}from"ink";import bi from"string-width";import{Fragment as Ah,jsx as mn,jsxs as nm}from"react/jsx-runtime";var Ao=1,yv=4,bv=1,hr=8,Sv=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587"],Ph=e=>`${Number(e.slice(5,7))}\u6708${Number(e.slice(8,10))}\u65E5`;function Eh({data:e,order:t,width:n,rows:o}){let r=o-bv,i=[];for(let M=e.start;M<=e.end;M=Gn(M,1))i.push(M);let s=Math.min(yv,Math.floor((n+Ao)/i.length)-Ao);s<1&&(s=1,i=i.slice(-Math.floor((n+Ao)/(1+Ao))));let a=i[0],c=i[i.length-1];if(a===void 0||c===void 0)return null;let l=new Map(t.slice(0,ws.length).map((M,C)=>[M,C])),u=ws.length,m=M=>ws[M]??f.faintForeground,p=new Map(i.map((M,C)=>[M,C])),d=i.map(()=>Array.from({length:u+1},()=>0));for(let M of e.points){let C=p.get(M.day);if(C===void 0)continue;let v=d[C];if(v===void 0)continue;let _=l.get(M.model)??u;v[_]=(v[_]??0)+M.tokens}let b=d.map(M=>M.reduce((C,v)=>C+v,0)),h=Math.max(0,...b),g=r*hr,x=d.map((M,C)=>{let v=Array.from({length:r},()=>null),_=b[C]??0;if(_<=0)return v;let L=Math.max(1,Math.round(_/h*g)),P=[],B=0,J=0;M.forEach((oe,fe)=>{B+=oe;let $=Math.round(B/_*L);for(let ne=J;ne<$;ne+=1)P[ne]=m(fe);J=$});for(let oe=0;oe<r;oe+=1){let fe=Math.min(hr,L-oe*hr);if(fe<=0)break;let $=new Map;for(let U=oe*hr;U<oe*hr+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;v[oe]={color:ne,glyph:fe===hr?null:Sv[fe-1]??null}}return v}),T=M=>{let C=[],v=(_,L,P)=>{let B=C[C.length-1];B!==void 0&&B.color===_&&B.glyph===L?B.width+=P:C.push({color:_,glyph:L,width:P})};return x.forEach((_,L)=>{L>0&&v(null,null,Ao);let P=_[M]??null;P===null?v(null,null,s):v(P.color,P.glyph,s)}),C},k=i.length*(s+Ao)-Ao,S=Ph(a),y=Ph(c),R=h>0?`\u5355\u65E5\u5CF0\u503C ${qn(h)}`:"",N=k-bi(S)-bi(y),E=R!==""&&N>=bi(R)+4,W=E?Math.floor((N-bi(R))/2):N;return nm(hv,{flexDirection:"column",children:[Array.from({length:r},(M,C)=>{let v=r-1-C;return mn(ln,{wrap:"truncate",children:T(v).map((_,L)=>_.color===null?mn(ln,{children:" ".repeat(_.width)},L):_.glyph===null?mn(ln,{backgroundColor:_.color,children:" ".repeat(_.width)},L):mn(ln,{color:_.color,children:_.glyph.repeat(_.width)},L))},v)}),mn(ln,{wrap:"truncate",children:N<2?mn(ln,{color:f.faintForeground,children:qe(S,k)}):nm(Ah,{children:[mn(ln,{color:f.faintForeground,children:S}),mn(ln,{children:" ".repeat(W)}),E&&nm(Ah,{children:[mn(ln,{color:f.mutedForeground,children:R}),mn(ln,{children:" ".repeat(N-bi(R)-W)})]}),mn(ln,{color:f.faintForeground,children:y})]})})]})}import{jsx as ct,jsxs as Ih}from"react/jsx-runtime";var wv={all:"\u5168\u90E8","30d":"30 \u5929","7d":"7 \u5929"},kv=1,wa=4,Mh=5,vv=9;function Cv(e){let t=-1,n=0;return e.forEach((o,r)=>{o>n&&(n=o,t=r)}),t<0?"\u2014":`${t} \u70B9`}function Nh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=om("30d"),[i,s]=om("heatmap"),[a,c]=om(null),l=Tv(null),u=Q([o,e.revision],async()=>{let m=l.current;if(m!==null&&m.revision===e.revision){let h=await tm(o);return{summary:m.summary,stats:h,site:m.site}}let[p,d,b]=await Promise.all([kh(),tm(o),Be(e.ctx.site)]);return l.current={revision:e.revision,summary:p,site:b},{summary:p,stats:d,site:b}});return xv(()=>{u.phase==="ready"&&c(bd({tokens:u.data.stats.totals.tokens,scope:"user",range:o}))},[u,o]),G(m=>{m==="r"&&e.reload(),m==="t"&&s(p=>p==="heatmap"?"chart":"heatmap")}),ct(Y,{hints:["\u2191\u2193 \u6EDA\u52A8","\u2190\u2192 \u5207\u6362\u533A\u95F4","t \u5207\u6362\u56FE\u8868","/ \u8FC7\u6EE4","r \u5237\u65B0"],children:ct(Eo,{flexDirection:"column",children:ct(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7528\u91CF",width:t,children:({summary:m,stats:p,site:d})=>{let b=[{label:"\u8D26\u6237\u4F59\u989D",value:Te(m.balance,d.quotaPerUsd)},{label:"\u4ECA\u65E5\u8BF7\u6C42",value:Le(m.today.requests)},{label:"\u4ECA\u65E5 Token",value:Le(m.today.tokens)},{label:"\u4ECA\u65E5\u6D88\u8017",value:Te(m.today.cost,d.quotaPerUsd)}],h=[{label:"\u8BF7\u6C42\u6570",value:Le(p.totals.requests)},{label:"Token \u603B\u91CF",value:qn(p.totals.tokens)},{label:"\u6D88\u8017",value:Te(p.totals.cost,d.quotaPerUsd)},{label:"\u6D3B\u8DC3\u5929\u6570",value:Le(p.activeDays)},{label:"\u5F53\u524D\u8FDE\u7EED",value:`${p.currentStreak} \u5929`},{label:"\u6700\u957F\u8FDE\u7EED",value:`${p.longestStreak} \u5929`},{label:"\u9AD8\u5CF0\u65F6\u6BB5",value:Cv(p.hourly)},{label:"\u5E38\u7528\u6A21\u578B",value:p.models[0]?.displayName??"\u2014"}],g=t-ge,x=C=>Bt+C+Ut(b.length,g)+X+Bt+C+kv+C+Ut(h.length,g)+X+Bt+C,T=n-x(Ge)>=wa?Ge:0,k=n-x(T),S=X+Bt+T+Mh,y=i==="chart"&&p.chart.points.length>0&&k>=S+wa,R=i==="heatmap"&&cr(g)&&k-(X+To)>=wa,N=R?X+To:0,E=y?Math.min(vv,Mh+Math.floor((k-S-wa)/2)):0,W=k-N-(y?X+Bt+T+E:0),M=C=>`${(p.totals.tokens>0?C/p.totals.tokens*100:0).toFixed(1)}%`;return Ih(Eo,{flexDirection:"column",children:[ct(pe,{title:"\u6982\u89C8",width:t,gap:T,children:ct(it,{width:g,tiles:b})}),ct(Eo,{marginTop:1,flexDirection:"column",children:Ih(pe,{title:"\u533A\u95F4\u7EDF\u8BA1",width:t,gap:T,children:[ct(Gs,{options:vh.map(C=>({value:C,label:wv[C]})),value:o,onChange:r}),ct(Eo,{marginTop:T,children:ct(it,{width:g,tiles:h})}),R&&ct(Eo,{marginTop:1,flexDirection:"column",children:ct(lr,{data:p.heatmap,value:C=>C.cost,caption:a,width:g})})]})}),y&&ct(Eo,{marginTop:1,flexDirection:"column",children:ct(pe,{title:"\u7528\u91CF\u8D8B\u52BF",note:"\u67F1\u8272\u7531\u4EAE\u81F3\u6697\u5BF9\u5E94\u7528\u91CF\u524D\u4E94\u7684\u6A21\u578B\uFF0C\u7070\u8272\u4E3A\u5176\u4ED6",width:t,gap:T,children:ct(Eh,{data:p.chart,order:p.models.map(C=>C.model),width:g,rows:E})})}),ct(Eo,{marginTop:1,flexDirection:"column",children:ct(pe,{title:"\u6A21\u578B\u7528\u91CF",width:t,gap:T,children:p.models.length===0?ct(ye,{tone:"info",width:g,title:"\u6682\u65E0\u7528\u91CF\u6570\u636E",detail:"\u8C03\u7528 API \u540E\u8FD9\u91CC\u4F1A\u663E\u793A\u5404\u6A21\u578B\u7684\u6BCF\u65E5 Token \u7528\u91CF"}):ct(de,{retain:"list",items:p.models,width:g,height:W,columns:[{label:"\u6A21\u578B",shrink:!0},{label:"\u603B Token",align:"right"},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u5360\u6BD4",align:"right"}],row:C=>[C.displayName,qn(C.tokens),qn(C.inTokens),qn(C.outTokens),M(C.tokens)],searchOf:C=>C.displayName})})})]})}})})})}import{Box as yr,Text as im}from"ink";import{useState as Dh}from"react";import{z as _v}from"zod";import{z as gt}from"zod";var Rv=gt.object({id:gt.number().int(),name:gt.string(),description:gt.string(),multiplier:gt.number()}),ka=()=>A(gt.array(Rv),"/groups"),rm=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(rm),"/tokens"),Lh=e=>A(rm.extend({token:gt.string()}),"/tokens",{method:"POST",json:e}),Ca=(e,t)=>A(rm,`/tokens/${e}`,{method:"PATCH",json:t}),Oh=e=>A(se,`/tokens/${e}`,{method:"DELETE"});import{jsx as lt,jsxs as Ra}from"react/jsx-runtime";var $h={model:"",requestId:"",token:"",group:"",status:"",range:"today",since:"",until:""},Bh=_v.iso.date();function Pv(e){let t=Lc();return e.range==="today"?{since:t,until:t}:e.range==="7d"?{since:Gn(t,-6),until:t}:e.range==="30d"?{since:Gn(t,-29),until:t}:e.range==="custom"?{...e.since===""?{}:{since:e.since},...e.until===""?{}:{until:e.until}}:{}}function Fh(e){let t=Pv(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(Gn(t.until,1)).toISOString()}}}var Av=Pt(oc,Zi,"\u5168\u90E8\u72B6\u6001"),Ev=[{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 Mv({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\u65E0\u6CD5\u4F30\u7B97\uFF0C\u672A\u8BA1\u8D39",a=[];e.cachedTokens>0&&a.push(["\u7F13\u5B58\u8BFB",Le(e.cachedTokens)]),e.cacheWriteTokens>0&&a.push(["\u7F13\u5B58\u5199",Le(e.cacheWriteTokens)]),e.cacheWrite1hTokens>0&&a.push(["\u7F13\u5B58\u5199 1h",Le(e.cacheWrite1hTokens)]),e.webSearchRequests>0&&a.push(["\u7F51\u9875\u641C\u7D22",`${Le(e.webSearchRequests)} \u6B21`]),e.imageGenerationCalls>0&&a.push(["\u56FE\u50CF\u751F\u6210",`${Le(e.imageGenerationCalls)} \u6B21`]),e.firstByteMs!==null&&a.push(["\u9996\u5B57\u8282",`${ao(e.firstByteMs)} s`]),e.tierOver!==null&&a.push(["\u8F93\u5165\u957F\u5EA6",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",wd(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(pe,{title:e.modelDisplayName,note:K(e.createdAt),width:n,children:[Ra(im,{wrap:"truncate",children:[lt(im,{color:i===void 0?f.mutedForeground:et[i],children:r.label}),lt(im,{color:f.faintForeground,children:` ${_e([e.stream?"\u6D41\u5F0F":"",e.model])}`})]}),lt(yr,{marginTop:1,children:lt(it,{width:o,tiles:[{label:"\u8F93\u5165 Token",value:Le(e.promptTokens)},{label:"\u8F93\u51FA Token",value:Le(e.completionTokens)},{label:"\u6D88\u8017",value:Xo(e.quotaCost,t)},{label:"\u603B\u8017\u65F6",value:`${ao(e.latencyMs)} s`},{label:"\u6863\u4F4D",value:Dr(e.tierOver)},{label:"\u5206\u7EC4\u500D\u7387",value:`\xD7${e.multiplier}`},{label:"\u53C2\u6570\u500D\u7387",value:`\xD7${Nu(e.paramMultipliers)}`},{label:"\u603B\u500D\u7387",value:`\xD7${Lu(e.multiplier,e.paramMultipliers)}`}]})}),s!==null&&lt(yr,{marginTop:1,children:lt(ye,{tone:"warn",width:o,title:s})}),lt(yr,{marginTop:1,children:lt(Ve,{width:o,items:[...a,...c]})})]})}function Uh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Dh({name:"list"}),[i,s]=Dh($h),{error:a,fail:c,reset:l}=ue(),u=Q([e.revision],async()=>{let[g,x,T]=await Promise.all([ka(),va(),Be(e.ctx.site)]);return{groups:g,tokens:x,site:T}}),m=ze([e.revision,JSON.stringify(i)],g=>Ch({page:g,...Fh(i)}),{retain:"page"}),p=Q([e.revision,JSON.stringify(i)],()=>Rh(Fh(i))),d=o.name==="list";G((g,x)=>{d&&(g==="r"?e.reload():g==="f"?(l(),r({name:"filter"})):x.leftArrow?m.go(-1):x.rightArrow&&m.go(1))});let b=()=>{o.name==="list"?e.pop():(l(),r({name:"list"}))},h=JSON.stringify(i)!==JSON.stringify($h);return lt(Y,{hints:d?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:b,children:lt(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u7B5B\u9009\u9009\u9879",width:t,children:({groups:g,tokens:x,site:T})=>{if(o.name==="filter")return lt(te,{title:"\u7B5B\u9009\u65E5\u5FD7",width:t,submitLabel:"\u67E5\u8BE2",error:a,fields:[{kind:"text",name:"model",label:"\u6A21\u578B",initial:i.model,placeholder:"\u641C\u7D22\u6A21\u578B ID \u6216\u540D\u79F0"},{kind:"text",name:"requestId",label:"\u8BF7\u6C42 ID",initial:i.requestId,placeholder:"\u641C\u7D22\u8BF7\u6C42 ID"},{kind:"select",name:"token",label:"\u4EE4\u724C",options:[{value:"",label:"\u5168\u90E8\u4EE4\u724C"},...[...new Set(x.map(S=>S.name))].map(S=>({value:S,label:S}))],initial:i.token},{kind:"select",name:"group",label:"\u5206\u7EC4",options:[{value:"",label:"\u5168\u90E8\u5206\u7EC4"},...g.map(S=>({value:S.name,label:S.name}))],initial:i.group},{kind:"select",name:"status",label:"\u72B6\u6001",options:Av,initial:i.status},{kind:"select",name:"range",label:"\u65F6\u95F4\u8303\u56F4",options:Ev,initial:i.range},{kind:"text",name:"since",label:"\u5F00\u59CB\u65E5\u671F",initial:i.since,placeholder:"YYYY-MM-DD",hint:"\u4EC5\u65F6\u95F4\u8303\u56F4\u9009\u300C\u81EA\u5B9A\u4E49\u8D77\u6B62\u300D\u65F6\u751F\u6548"},{kind:"text",name:"until",label:"\u7ED3\u675F\u65E5\u671F",initial:i.until,placeholder:"YYYY-MM-DD",hint:"\u4EC5\u65F6\u95F4\u8303\u56F4\u9009\u300C\u81EA\u5B9A\u4E49\u8D77\u6B62\u300D\u65F6\u751F\u6548"}],onCancel:b,onSubmit:S=>{let y=S.range??"",R=(S.since??"").trim(),N=(S.until??"").trim();if(y==="custom"&&(R!==""&&!Bh.safeParse(R).success||N!==""&&!Bh.safeParse(N).success)){c("\u65E5\u671F\u65E0\u6548");return}s({model:S.model??"",requestId:S.requestId??"",token:S.token??"",group:S.group??"",status:S.status??"",range:y,since:R,until:N}),m.reset(),r({name:"list"})}});if(o.name==="detail")return lt(Mv,{log:o.log,quotaPerUsd:T.quotaPerUsd,width:t});let k=Ut(4,t);return Ra(yr,{flexDirection:"column",children:[lt(yr,{height:k+1,flexDirection:"column",overflow:"hidden",children:lt(V,{state:p,loading:"\u6B63\u5728\u7EDF\u8BA1\u7B5B\u9009\u7ED3\u679C",width:t,children:S=>lt(it,{width:t,tiles:[{label:"\u6D88\u8017",value:Te(S.quotaCost,T.quotaPerUsd)},{label:"RPM",value:Le(S.rpm)},{label:"TPM",value:Le(S.tpm)},{label:"\u5E76\u53D1",value:Le(S.concurrency)}]})})}),lt(V,{state:m.state,loading:"\u6B63\u5728\u8BFB\u53D6\u4F7F\u7528\u65E5\u5FD7",width:t,children:S=>Ra(yr,{flexDirection:"column",children:[lt(de,{retain:"list",items:S.items,width:t,height:Math.max(3,n-2-k),columns:[{label:"\u65F6\u95F4"},{label:"\u6A21\u578B",shrink:!0},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u6D88\u8017",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:y=>[K(y.createdAt),y.modelDisplayName,Le(y.promptTokens),Le(y.completionTokens),Xo(y.quotaCost,T.quotaPerUsd),bt(Zi(y.status))],onOpen:y=>r({name:"detail",log:y}),emptyLabel:h?"\u65E0\u5339\u914D\u7ED3\u679C":"\u6682\u65E0\u8C03\u7528\u8BB0\u5F55",emptyDescription:h?void 0:"\u901A\u8FC7\u4EE4\u724C\u8C03\u7528 API \u540E\uFF0C\u660E\u7EC6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),lt(We,{page:m.page,pages:m.pages,total:m.total,width:t})]})})]})}})})}import{Box as Dn,Text as Mo}from"ink";import{useState as $v}from"react";import{z as we}from"zod";var Iv=xc.extend({id:we.number().int(),model:we.string(),displayName:we.string(),rules:Pu}),Nv=we.object({quotaPerUsd:we.number(),minTopupCny:we.number(),models:we.array(Iv)});function _a(e){return fn(Nv,`${e}/api/pricing`)}var Lv=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 jh(e){return A(Lv,`/pricing/${e}`)}var Ov=we.object({data:we.array(we.object({id:we.string()}))});async function Hh(e,t,n){return(await fn(Ov,`${e}/v1/models`,{headers:{authorization:`Bearer ${t}`},...n===void 0?{}:{timeoutMs:n}})).data.map(r=>r.id)}var qh=()=>A(Du,"/provider-status");import{Text as br}from"ink";import{jsx as Pa,jsxs as Gh}from"react/jsx-runtime";var Dv=` ${ae.bullet} `,zh=1;function Wh({providers:e}){return Gh(br,{wrap:"truncate",children:[Pa(br,{color:f.faintForeground,children:"\u5B98\u65B9\u72B6\u6001"}),e.map(t=>{let n=Bu(t);return Gh(br,{children:[Pa(br,{color:f.faintForeground,children:Dv}),Pa(br,{color:f.foreground,children:`${kd(t.provider)} `}),Pa(br,{color:et[n.tone],children:n.label})]},t.provider)})]})}import{jsx as Pe,jsxs as Si}from"react/jsx-runtime";var Bv=4,Fv=1+Ge,Uv=e=>e.requests===0?f.border:e.errors===0?f.success:e.errors/e.requests>=.5?f.danger:f.warning;function jv({minutes:e,width:t}){let n=e.slice(Math.max(0,e.length-t)),o=[];for(let r of n){let i=Uv(r),s=o[o.length-1];s!==void 0&&s.color===i?s.count+=1:o.push({color:i,count:1})}return Pe(Mo,{wrap:"truncate",children:o.map((r,i)=>Pe(Mo,{color:r.color,children:ae.barFilled.repeat(r.count)},i))})}function Hv({price:e,width:t,contentRows:n}){let o=O(),r=Q([e.id,o.revision],()=>jh(e.id)),i=Mu(e,e.rules),s=i.length>1,a=e.rules.filter(Au),c=t-ge,l=1+i.length,u=1+a.length;return Pe(V,{state:r,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u8BE6\u60C5",width:t,children:m=>{let p=m.stats,d=[{label:"\u53EF\u7528\u7387",value:p.requests>0?`${((p.requests-p.errors)/p.requests*100).toFixed(1)}%`:"\u2014"},{label:"\u8C03\u7528\u6B21\u6570",value:Le(p.requests)},{label:"\u5EF6\u8FDF P50",value:p.latencyP50Ms!==null?`${ao(p.latencyP50Ms)} s`:"\u2014"},{label:"\u9996\u5B57\u8282 P50",value:p.firstByteP50Ms!==null?`${ao(p.firstByteP50Ms)} s`:"\u2014"}],b=a.length>0?X+Xe+u:0,h=Fv+Xe+Ut(d.length,c,2)+X+Xe+l+b+X+Xe,g=m.heartbeat.groups.length,x=n-h-Bv-X-Xe,T=Math.max(0,Math.floor(x/2));T<g&&(T=Math.max(0,Math.floor((x-1)/2))),T=Math.min(g,T);let k=T>0?X+Xe+T*2+(T<g?1:0):0,S=Math.max(1,n-h-k);return Si(Dn,{flexDirection:"column",children:[Pe(Dn,{marginBottom:Ge,children:Si(Mo,{wrap:"truncate",children:[Pe(Mo,{bold:!0,color:f.foreground,children:e.displayName}),Pe(Mo,{color:f.faintForeground,children:` ${e.model}`})]})}),Pe(pe,{title:"\u8FD1 24 \u5C0F\u65F6",note:"\u5168\u90E8\u5206\u7EC4\u7684\u7EFC\u5408\u8C03\u7528\u7EDF\u8BA1",width:t,children:Pe(it,{width:c,tiles:d,maxPerRow:2})}),T>0&&Pe(Dn,{marginTop:1,flexDirection:"column",children:Si(pe,{title:"\u53EF\u7528\u6027",note:"\u6700\u8FD1\u4E00\u6BB5\u65F6\u95F4\u5404\u5206\u7EC4\u7684\u8C03\u7528\u5065\u5EB7\u72B6\u51B5",width:t,children:[m.heartbeat.groups.slice(0,T).map(y=>Si(Dn,{flexDirection:"column",children:[Pe(Mo,{wrap:"truncate",color:f.foreground,children:y.name}),Pe(jv,{minutes:y.minutes,width:c})]},y.id)),T<g&&Pe(Mo,{color:f.faintForeground,children:`\u5176\u4F59 ${g-T} \u4E2A\u5206\u7EC4\u672A\u663E\u793A`})]})}),Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u6A21\u578B\u4EF7\u683C",note:"\u6BCF\u767E\u4E07 Token \u7684\u7F8E\u5143\u6807\u4EF7",width:t,children:Pe(de,{items:i,width:c,height:l,columns:[{label:"\u6863\u4F4D"},...s?[{label:"\u8F93\u5165\u957F\u5EA6"}]:[],{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u7F13\u5B58\u8BFB\u53D6",align:"right"},{label:"\u7F13\u5B58\u5199\u5165",align:"right"}],row:y=>[y.name,...y.range===null?[]:[y.range],pn(y.price.inputPricePerMillionTokens,"-"),pn(y.price.outputPricePerMillionTokens,"-"),pn(y.price.cachedInputPricePerMillionTokens,"-"),pn(y.price.cacheWritePricePerMillionTokens,"-")]})})}),a.length>0&&Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u8BF7\u6C42\u53C2\u6570\u500D\u7387",note:"\u547D\u4E2D\u65F6 Token \u8D39\u7528\u4E58\u4EE5\u500D\u7387\uFF0C\u591A\u6761\u547D\u4E2D\u4F9D\u6B21\u76F8\u4E58",width:t,children:Pe(de,{items:a,width:c,height:u,columns:[{label:"\u53C2\u6570\u540D",shrink:!0},{label:"\u53C2\u6570\u503C",shrink:!0},{label:"\u500D\u7387",align:"right"}],row:y=>[y.param,y.value,`\xD7${y.multiplier}`]})})}),Pe(Dn,{marginTop:1,flexDirection:"column",children:Pe(pe,{title:"\u5206\u7EC4\u4EF7\u683C",note:"\u500D\u7387\u968F\u4EE4\u724C\u6240\u5C5E\u5206\u7EC4\u800C\u5B9A\uFF0C\u5355\u4EF7\u4E3A 1 \u7F8E\u5143\u6807\u4EF7\u7528\u91CF\u7684\u4EBA\u6C11\u5E01\u4EF7\u683C",width:t,children:m.groups.length===0?Pe(ye,{tone:"info",width:c,title:"\u6682\u65E0\u53EF\u7528\u5206\u7EC4",detail:"\u5F53\u524D\u6CA1\u6709\u542F\u7528\u7684\u6E20\u9053\u63D0\u4F9B\u8BE5\u6A21\u578B"}):Pe(de,{items:m.groups,width:c,height:S,columns:[{label:"\u5206\u7EC4",shrink:!0},{label:"\u8BF4\u660E",shrink:!0},{label:"\u500D\u7387",align:"right"},{label:"\u5355\u4EF7",align:"right"}],row:y=>[y.name,y.description,`\xD7${y.multiplier}`,`\xA5${(m.cnyPerUsd*y.multiplier).toFixed(2)}`]})})})]})}})}function Vh(){let e=O(),{width:t}=j(),n=Z(),[o,r]=$v({name:"list"}),i=Q([e.revision],async()=>(await _a(e.ctx.site)).models),s=Q([e.revision],qh);G(c=>{c==="r"&&e.reload()});let a=()=>{o.name==="list"?e.pop():r({name:"list"})};return Pe(Y,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","/ \u8FC7\u6EE4","r \u5237\u65B0"]:["\u2191\u2193 \u6EDA\u52A8","r \u5237\u65B0","Esc \u8FD4\u56DE"],onEscape:a,children:Pe(V,{state:i,loading:"\u6B63\u5728\u8BFB\u53D6\u6A21\u578B\u5B9A\u4EF7",width:t,children:c=>{if(c.length===0)return Pe(ye,{tone:"info",width:t,title:"\u6682\u65E0\u6A21\u578B"});if(o.name==="detail")return Pe(Hv,{price:o.price,width:t,contentRows:n});let l=s.phase==="ready"?$u(s.data.providers):[],u=l.length>0?zh+X:0;return Si(Dn,{flexDirection:"column",children:[l.length>0&&Pe(Dn,{marginBottom:X,children:Pe(Wh,{providers:l})}),Pe(de,{retain:"list",items:c,width:t,height:n-u,columns:[{label:"\u6A21\u578B",shrink:!0},{label:"\u8F93\u5165",align:"right"},{label:"\u8F93\u51FA",align:"right"},{label:"\u7F13\u5B58\u8BFB\u53D6",align:"right"},{label:"\u7F13\u5B58\u5199\u5165",align:"right"}],row:m=>[m.displayName,pn(m.inputPricePerMillionTokens,"-"),pn(m.outputPricePerMillionTokens,"-"),pn(m.cachedInputPricePerMillionTokens,"-"),pn(m.cacheWritePricePerMillionTokens,"-")],searchOf:m=>`${m.displayName} ${m.model}`,onOpen:m=>r({name:"detail",price:m}),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})]})}})})}import{Box as Io,Text as SC}from"ink";import{useState as Da}from"react";function sm(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 Kh(e,t){let n=sm(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 Yh(e,t){let n=await Be(e.site);return Hh(Kh(fo(),n).url,t)}async function Jh(e,t,n){let o=await Be(e.site),r=Kh(fo(),o).url;return{input:{siteName:o.siteName,baseUrl:t.relayUrl(r),apiKey:n},at:t.resolveDir()}}async function Xh(e,t,n){let{input:o,at:r}=await Jh(e,t,n);t.apply(o,r)}async function Qh(e,t,n,o,r){let{input:i,at:s}=await Jh(e,t,n);t.apply({...i,model:o,models:r},s)}import{homedir as iy}from"os";import{join as Ea,resolve as Vv}from"path";import qv from"json5";import{applyEdits as Gv,modify as zv,parse as Wv}from"jsonc-parser";function Zh(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 ey(e){let t=[],n=Wv(e,t,{allowTrailingComma:!0});return t.length>0?null:n}function ty(e,t){let n=ey(e);if(n!==null)return{root:Zh(n,t),jsonc:!0};try{return{root:Zh(qv.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 no(e,t){let n=e;for(let o of t){if(typeof n!="object"||n===null||Array.isArray(n))return;n=n[o]}return n}function xi(e){let t=Lt(e);return t===null?null:ty(t,e).root}function $n(e,t){let n=xi(e),o=n===null?void 0:no(n,t);return typeof o=="string"?o:null}function Aa(e,t){let n=xi(e);return n!==null&&no(n,t)!==void 0}function Gt(e,t){let n=Lt(e)??"{}",o=n.includes(`\r
19
19
  `)?`\r
20
20
  `:`
21
- `,r=Qh(n,e);r.jsonc||(n=JSON.stringify(r.root,null,2).replaceAll(`
22
- `,o));let i={insertSpaces:!0,tabSize:2,eol:o};try{for(let[a,c]of t)n=Fv(n,Uv(n,a,c,{formattingOptions:i}))}catch(a){throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`,{cause:a})}let s=Xh(n);if(s===null)throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);for(let[a,c]of t)if(JSON.stringify(no(s,a))!==JSON.stringify(c))throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${e}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);kn(e,n.endsWith(o)?n:`${n}${o}`,384)}var Zh=["env","ANTHROPIC_BASE_URL"],qv=["env","ANTHROPIC_AUTH_TOKEN"],ey=["hasCompletedOnboarding"],nm=e=>Ca(e.dir,"settings.json"),ty=e=>e.custom?Ca(e.dir,".claude.json"):Ca(ny(),".claude.json"),oy={id:"claude-code",label:"Claude Code",requiresModel:!1,resolveDir(){let e=process.env.CLAUDE_CONFIG_DIR;return e?{dir:Hv(e),custom:!0}:{dir:Ca(ny(),".claude"),custom:!1}},relayUrl:e=>e,configPaths:e=>[nm(e),ty(e)],read(e){return{baseUrl:$n(nm(e),Zh),model:null}},apply(e,t){Gt(nm(t),[[Zh,e.baseUrl],[qv,e.apiKey]]);let n=ty(t);va(n,ey)||Gt(n,[[ey,!0]])}};import{homedir as Wv}from"os";import{join as sm,resolve as Vv}from"path";import{parse as Kv,patch as Yv}from"@decimalturn/toml-patch";import{parse as Jv}from"smol-toml";import{homedir as Gv}from"os";import{resolve as zv}from"path";var Tn=e=>e.toLowerCase(),Ra=e=>`${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}_API_KEY`;function _a(e){let t=e.indexOf("/");return t===-1?null:[e.slice(0,t),e.slice(t+1)]}function Sr(e){let t=process.env[e]?.trim();if(!t)return null;let n=t.replace(/^~(?=$|[\\/])/,()=>Gv());return zv(n)}var Xv=["OPENAI_API_KEY"],ry="model_provider",om="model",rm=e=>sm(e.dir,"config.toml"),iy=e=>sm(e.dir,"auth.json");function im(e,t){try{return Jv(e,{integersAsBigInt:"asNeeded"})}catch(n){throw new U(`${t} \u4E0D\u662F\u5408\u6CD5 TOML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function Qv(e,t){let n=rm(t),o=Nt(n)??"";o!==""&&im(o,n);let r=Tn(e.siteName),i=Kv(o),s=i.model_providers;i.model_providers={...typeof s=="object"&&s!==null&&!Array.isArray(s)?s:{},[r]:{name:e.siteName,base_url:e.baseUrl,wire_api:"responses",requires_openai_auth:!0}},i[ry]=r,i[om]=e.model;let a=Yv(o,i,{inlineTableStart:2}),c=im(a,n);if(c[ry]!==r||c[om]!==e.model||c.model_providers?.[r]?.base_url!==e.baseUrl)throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${n}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);kn(n,a,384)}var sy={id:"codex",label:"Codex",requiresModel:!0,resolveDir(){let e=process.env.CODEX_HOME;return e?{dir:Vv(e),custom:!0}:{dir:sm(Wv(),".codex"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[rm(e),iy(e)],read(e){let t=rm(e),n=Nt(t),o=n===null?null:im(n,t),r=s=>typeof s=="string"?s:null,i=r(o?.model_provider);return{baseUrl:i===null?null:r(o?.model_providers?.[i]?.base_url),model:r(o?.[om])}},apply(e,t){Qv(e,t),Gt(iy(t),[[Xv,e.apiKey]])}};import{homedir as ay}from"os";import{join as xi,resolve as Zv}from"path";import{isMap as eC,isScalar as tC,parse as nC,parseDocument as oC}from"yaml";function Pa(e,t,n){let o=Nt(e)??"",r=o.includes(`\r
21
+ `,r=ty(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=Gv(n,zv(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=ey(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(no(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`);kn(e,n.endsWith(o)?n:`${n}${o}`,384)}var ny=["env","ANTHROPIC_BASE_URL"],Kv=["env","ANTHROPIC_AUTH_TOKEN"],oy=["hasCompletedOnboarding"],am=e=>Ea(e.dir,"settings.json"),ry=e=>e.custom?Ea(e.dir,".claude.json"):Ea(iy(),".claude.json"),sy={id:"claude-code",label:"Claude Code",requiresModel:!1,resolveDir(){let e=process.env.CLAUDE_CONFIG_DIR;return e?{dir:Vv(e),custom:!0}:{dir:Ea(iy(),".claude"),custom:!1}},relayUrl:e=>e,configPaths:e=>[am(e),ry(e)],read(e){return{baseUrl:$n(am(e),ny),model:null}},apply(e,t){Gt(am(t),[[ny,e.baseUrl],[Kv,e.apiKey]]);let n=ry(t);Aa(n,oy)||Gt(n,[[oy,!0]])}};import{homedir as Xv}from"os";import{join as um,resolve as Qv}from"path";import{parse as Zv,patch as eC}from"@decimalturn/toml-patch";import{parse as tC}from"smol-toml";import{homedir as Yv}from"os";import{resolve as Jv}from"path";var Tn=e=>e.toLowerCase(),Ma=e=>`${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}_API_KEY`;function Ia(e){let t=e.indexOf("/");return t===-1?null:[e.slice(0,t),e.slice(t+1)]}function Sr(e){let t=process.env[e]?.trim();if(!t)return null;let n=t.replace(/^~(?=$|[\\/])/,()=>Yv());return Jv(n)}var nC=["OPENAI_API_KEY"],ay="model_provider",cm="model",lm=e=>um(e.dir,"config.toml"),cy=e=>um(e.dir,"auth.json");function mm(e,t){try{return tC(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 oC(e,t){let n=lm(t),o=Lt(n)??"";o!==""&&mm(o,n);let r=Tn(e.siteName),i=Zv(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[ay]=r,i[cm]=e.model;let a=eC(o,i,{inlineTableStart:2}),c=mm(a,n);if(c[ay]!==r||c[cm]!==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`);kn(n,a,384)}var ly={id:"codex",label:"Codex",requiresModel:!0,resolveDir(){let e=process.env.CODEX_HOME;return e?{dir:Qv(e),custom:!0}:{dir:um(Xv(),".codex"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[lm(e),cy(e)],read(e){let t=lm(e),n=Lt(t),o=n===null?null:mm(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?.[cm])}},apply(e,t){oC(e,t),Gt(cy(t),[[nC,e.apiKey]])}};import{homedir as my}from"os";import{join as Ti,resolve as rC}from"path";import{isMap as iC,isScalar as sC,parse as aC,parseDocument as cC}from"yaml";function Na(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,kn(e,`${i.join(r)}${r}`,384)}var am="custom:",cm=e=>xi(e.dir,"config.yaml"),cy=e=>xi(e.dir,".env"),Bn=e=>typeof e=="string"?e:null;function ly(e,t){try{return nC(e)}catch(n){throw new U(`${t} \u4E0D\u662F\u5408\u6CD5 YAML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:n})}}function rC(e,t,n,o){let r=cm(t),i=oC(Nt(r)??"",{compat:"yaml-1.1"});if(i.errors.length>0)throw new U(`${r} \u4E0D\u662F\u5408\u6CD5 YAML\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`,{cause:i.errors[0]});if(i.contents!==null&&!eC(i.contents))throw new U(`${r} \u7684\u9876\u5C42\u4E0D\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7\u5199\u5165\uFF0C\u8BF7\u5148\u4FEE\u590D\u8BE5\u6587\u4EF6`);let s=`${am}${n}`;try{i.setIn(["providers",n],{api:e.baseUrl,key_env:o,transport:"anthropic_messages",discover_models:!1,models:Object.fromEntries(e.models.map(l=>[l,{}]))}),tC(i.get("model",!0))?i.set("model",{provider:s,default:e.model}):(i.setIn(["model","provider"],s),i.setIn(["model","default"],e.model))}catch(l){throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${r}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`,{cause:l})}let a=i.toString({lineWidth:0}),c=ly(a,r);if(Bn(c?.providers?.[n]?.api)!==e.baseUrl||Bn(c?.model?.provider)!==s||Bn(c?.model?.default)!==e.model)throw new U(`\u65E0\u6CD5\u5B89\u5168\u6539\u5199 ${r}\uFF0C\u5176\u7ED3\u6784\u8D85\u51FA\u9884\u671F\uFF0C\u8BF7\u624B\u5DE5\u914D\u7F6E\u8BE5\u6587\u4EF6`);kn(r,a,384)}var my={id:"hermes-agent",label:"Hermes Agent",requiresModel:!0,resolveDir(){let e=process.env.HERMES_HOME?.trim();if(e)return{dir:Zv(e),custom:!0};if(process.platform==="win32"){let t=process.env.LOCALAPPDATA;return{dir:xi(t??xi(ay(),"AppData","Local"),"hermes"),custom:!1}}return{dir:xi(ay(),".hermes"),custom:!1}},relayUrl:e=>e,configPaths:e=>[cm(e),cy(e)],read(e){let t=cm(e),n=Nt(t),o=n===null?null:ly(n,t),r=Bn(o?.model?.provider),i=r!==null&&r.startsWith(am)?r.slice(am.length):null,s=i===null?void 0:o?.providers?.[i];return{baseUrl:Bn(s?.api)??Bn(s?.url)??Bn(s?.base_url),model:Bn(o?.model?.default)??Bn(o?.model?.model)}},apply(e,t){let n=Tn(e.siteName),o=Ra(n);rC(e,t,n,o),Pa(cy(t),o,e.apiKey)}};import{existsSync as iC}from"fs";import{homedir as py}from"os";import{join as xr,resolve as fy}from"path";var sC="https://opencode.ai/config.json",gy="opencode.jsonc",aC=[gy,"opencode.json","config.json"],uy=["model"],lm=e=>aC.map(t=>xr(e.dir,t)).find(t=>iC(t))??xr(e.dir,gy),dy=()=>{let e=process.env.XDG_DATA_HOME;return xr(e?fy(e):xr(py(),".local","share"),"opencode","auth.json")},hy={id:"opencode",label:"OpenCode",requiresModel:!0,resolveDir(){let e=process.env.XDG_CONFIG_HOME;return e?{dir:xr(fy(e),"opencode"),custom:!0}:{dir:xr(py(),".config","opencode"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[lm(e),dy()],read(e){let t=lm(e),n=$n(t,uy),o=n===null?null:_a(n);if(o===null)return{baseUrl:null,model:null};let[r,i]=o;return{baseUrl:$n(t,["provider",r,"options","baseURL"]),model:i}},apply(e,t){let n=lm(t),o=Tn(e.siteName),r=[[["provider",o],{npm:"@ai-sdk/anthropic",name:e.siteName,options:{baseURL:e.baseUrl},models:Object.fromEntries(e.models.map(i=>[i,{name:i}]))}],[uy,`${o}/${e.model}`]];va(n,["$schema"])||r.unshift([["$schema"],sC]),Gt(n,r),Gt(dy(),[[[o],{type:"api",key:e.apiKey}]])}};import{homedir as cC}from"os";import{join as um}from"path";var yy=["models","providers"],Aa=["agents","defaults","model"],by=["agents","defaults","models"],mm=e=>Sr("OPENCLAW_CONFIG_PATH")??um(e.dir,"openclaw.json"),Sy=e=>um(e.dir,".env"),xy=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function lC(e){let t=no(e,Aa),n=xy(t)?t.primary:t;return typeof n=="string"?n:null}var Ty={id:"openclaw",label:"OpenClaw",requiresModel:!0,resolveDir(){let e=Sr("OPENCLAW_STATE_DIR");if(e!==null)return{dir:e,custom:!0};let t=Sr("OPENCLAW_HOME");return{dir:um(t??cC(),".openclaw"),custom:t!==null}},relayUrl:e=>e,configPaths:e=>[mm(e),Sy(e)],read(e){let t=Si(mm(e)),n=t===null?null:lC(t),o=n===null?null:_a(n);if(t===null||o===null)return{baseUrl:null,model:null};let[r,i]=o,s=no(t,[...yy,r,"baseUrl"]);return{baseUrl:typeof s=="string"?s:null,model:i}},apply(e,t){let n=mm(t),o=Tn(e.siteName),r=Ra(o),i=Si(n)??{},s=`${o}/${e.model}`,a=[[[...yy,o],{baseUrl:e.baseUrl,apiKey:{source:"env",provider:"default",id:r},api:"anthropic-messages",models:e.models.map(c=>({id:c,name:c}))}],xy(no(i,Aa))?[[...Aa,"primary"],s]:[Aa,{primary:s}]];for(let c of e.models){let l=`${o}/${c}`;no(i,[...by,l])===void 0&&a.push([[...by,l],{}])}Gt(n,a),Pa(Sy(t),r,e.apiKey)}};import{homedir as mC}from"os";import{join as pm}from"path";var dm=e=>pm(e.dir,"models.json"),Ea=e=>pm(e.dir,"settings.json"),wy={id:"pi-coding-agent",label:"Pi Coding Agent",requiresModel:!0,resolveDir(){let e=Sr("PI_CODING_AGENT_DIR");return e!==null?{dir:e,custom:!0}:{dir:pm(mC(),".pi","agent"),custom:!1}},relayUrl:e=>e,configPaths:e=>[dm(e),Ea(e)],read(e){let t=$n(Ea(e),["defaultProvider"]);return{baseUrl:t===null?null:$n(dm(e),["providers",t,"baseUrl"]),model:$n(Ea(e),["defaultModel"])}},apply(e,t){let n=Tn(e.siteName);Gt(dm(t),[[["providers",n],{baseUrl:e.baseUrl,api:"anthropic-messages",apiKey:e.apiKey,models:e.models.map(o=>({id:o,name:o}))}]]),Gt(Ea(t),[[["defaultProvider"],n],[["defaultModel"],e.model]])}};var ky=[oy,sy,Ty,my,hy,wy];var uC=6e3,dC=2,vy=e=>Jt(`${e.url}/api/site-config`,{timeoutMs:uC});async function pC(e){try{await vy(e);let t=Number.POSITIVE_INFINITY;for(let n=0;n<dC;n+=1){let o=Date.now();await vy(e),t=Math.min(t,Date.now()-o)}return{line:e,latencyMs:t}}catch{return{line:e,latencyMs:null}}}async function Cy(e){let t=[];for(let n of e)t.push(await pC(n));return t}import{jsx as De,jsxs as Ia}from"react/jsx-runtime";var gC=10,hC=3,Ry=4,Ey=e=>1+Math.max(1,Math.min(e,Ry))+(e>Ry?1:0);function _y(e,t){let n=e.trim();if(n==="")return null;let o=Number(n),r=Math.round(o*t);return!Number.isFinite(o)||o<=0||r<1?"invalid":r}var Py=e=>e.map(t=>({value:String(t.id),label:`${t.name} \xD7${t.multiplier}`})),Ay=(e,t)=>{let n=e.find(o=>String(o.id)===t);return n===void 0?void 0:`${n.description}\uFF08\u8BA1\u8D39\u500D\u7387 \xD7${n.multiplier}\uFF09`};function yC({lines:e,measured:t,effective:n,width:o,isActive:r,onPick:i}){let s=a=>{if(t===null)return"\u6D4B\u91CF\u4E2D";let c=t.find(l=>l.line.url===a.url);return c===void 0||c.latencyMs===null?"\u4E0D\u53EF\u8FBE":`${c.latencyMs} ms`};return De(pe,{title:"API \u63A5\u5165\u5730\u5740",note:n===void 0?void 0:`\u5F53\u524D ${n.name}`,width:o,children:De(de,{retain:"lines",items:e,width:o-ge,height:Ey(e.length),isActive:r,columns:[{label:"\u7EBF\u8DEF"},{label:"\u5EF6\u8FDF",align:"right"},{label:"\u8BF4\u660E",shrink:!0},{label:"\u72B6\u6001"}],row:a=>[a.name,s(a),a.description,n?.url===a.url?"\u4F7F\u7528\u4E2D":""],searchOf:a=>`${a.name} ${a.url}`,onOpen:i,emptyLabel:"\u7AD9\u70B9\u672A\u914D\u7F6E\u63A5\u5165\u7EBF\u8DEF\uFF0C\u8BF7\u8054\u7CFB\u7AD9\u70B9\u7BA1\u7406\u5458\u6DFB\u52A0"})})}function My(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Ma({name:"list"}),[i,s]=Ma(!1),[a,c]=Ma(()=>fo().line),[l,u]=Ma(0),{busy:m,error:p,reset:d,fail:b,run:h}=ue();Re(m!==null||o.name==="created"||o.name==="apply-pick"||o.name==="apply-model");let g=Q([e.revision],async()=>{let[P,B,J]=await Promise.all([Sa(),ba(),Ge(e.ctx.site)]);return{tokens:P,groups:B,site:J}}),x=g.phase==="ready"?g.data.site.apiLines:[],T=Q([l,x.map(P=>P.url).join("|")],()=>Cy(x)),k=m!==null,S=o.name==="list"&&!k,y=P=>{r({name:"list"}),e.reload(),e.toast("ok",P)};G(P=>{if(P==="r"){u(B=>B+1),e.reload();return}i||(P==="n"?r({name:"create"}):P==="l"&&x.length>0&&s(!0))},S);let R=P=>{os(B=>{B.line={name:P.name,url:P.url}}),c({name:P.name,url:P.url}),s(!1),e.toast("ok",`\u5DF2\u9009\u7528\u7EBF\u8DEF ${P.name}\uFF0C\u65B0\u5EFA\u4EE4\u724C\u5E76\u5199\u5165\u914D\u7F6E\u540E\u751F\u6548`)},N=(P,B,J)=>{h("\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",()=>Mh({name:P,groupId:B,quotaLimit:J}),{onSuccess:oe=>{e.reload(),r({name:"created",token:oe,secret:oe.token})}})},E=P=>{h("\u6B63\u5728\u5220\u9664\u4EE4\u724C",()=>Ih(P.id),{onSuccess:()=>y("\u4EE4\u724C\u5DF2\u5220\u9664")})},W=(P,B)=>{h("\u6B63\u5728\u8BFB\u53D6\u5BA2\u6237\u7AEF\u914D\u7F6E",async()=>ky.map(J=>{let oe=J.resolveDir(),fe=J.read(oe);return{client:J,configured:fe.baseUrl!==null,paths:J.configPaths(oe),model:fe.model}}),{failToast:!0,onSuccess:J=>r({name:"apply-pick",token:P,secret:B,targets:J})})},M=(P,B,J)=>{h("\u6B63\u5728\u5199\u5165",J,{failToast:!0,onSuccess:()=>{r({name:"list"}),e.toast("ok",_e([`\u5DF2\u5199\u5165 ${P}`,B]))}})},C=(P,B)=>{let J=P.targets.find(fe=>fe.client.id===B);if(J===void 0)return;let{client:oe}=J;if(!oe.requiresModel){M(oe.label,void 0,()=>Kh(e.ctx,oe,P.secret));return}h("\u6B63\u5728\u8BFB\u53D6\u53EF\u8DEF\u7531\u7684\u6A21\u578B",async()=>{let fe=await Wh(e.ctx,P.secret);if(fe.length===0)throw new U("\u8BE5\u4EE4\u724C\u6240\u5728\u5206\u7EC4\u6CA1\u6709\u53EF\u8DEF\u7531\u7684\u6A21\u578B\uFF0C\u6362\u4E00\u4E2A\u5206\u7EC4\u540E\u91CD\u65B0\u521B\u5EFA");return fe},{failToast:!0,onSuccess:fe=>r({name:"apply-model",token:P.token,secret:P.secret,targets:P.targets,needs:{...J,client:oe},models:fe})})},v=(P,B)=>{d(),r(P==="rename"?{name:"rename",token:B}:P==="regroup"?{name:"regroup",token:B}:P==="relimit"?{name:"relimit",token:B}:{name:"confirm-delete",token:B})},_=()=>{if(o.name==="list"){i?s(!1):e.pop();return}if(d(),o.name==="apply-pick"){r({name:"created",token:o.token,secret:o.secret});return}if(o.name==="apply-model"){r({name:"apply-pick",token:o.token,secret:o.secret,targets:o.targets});return}r({name:"list"})},L=()=>o.name!=="list"?["Esc \u8FD4\u56DE"]:i?["\u2191\u2193 \u79FB\u52A8","Enter \u9009\u7528","/ \u8FC7\u6EE4","r \u5237\u65B0","Esc \u8FD4\u56DE"]:["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","n \u65B0\u5EFA","l \u63A5\u5165\u5730\u5740","/ \u8FC7\u6EE4","r \u5237\u65B0"];return o.name==="created"||o.name==="apply-pick"||o.name==="apply-model"?De(Y,{hints:L(),onEscape:_,isActive:m===null,children:Ia(Io,{flexDirection:"column",children:[m!==null&&De(Oe,{label:m}),o.name==="created"&&!k&&Ia(Io,{flexDirection:"column",children:[De(ye,{tone:"ok",width:t,title:"\u4EE4\u724C\u5DF2\u521B\u5EFA",detail:"\u8BF7\u7ACB\u5373\u590D\u5236\u5E76\u59A5\u5584\u4FDD\u5B58\u3002\u51FA\u4E8E\u5B89\u5168\u8003\u8651\uFF0C\u5B8C\u6574\u4EE4\u724C\u53EA\u663E\u793A\u8FD9\u4E00\u6B21\uFF0C\u5173\u95ED\u540E\u5C06\u65E0\u6CD5\u518D\u6B21\u67E5\u770B\u3002"}),De(Io,{marginTop:1,children:De(fC,{color:f.accent,children:o.secret})}),De(Io,{marginTop:1,children:De(le,{width:t,items:[{value:"apply",label:"\u5199\u5165\u914D\u7F6E"},{value:"back",label:"\u6211\u5DF2\u4FDD\u5B58"}],onSelect:P=>{P==="back"?r({name:"list"}):W(o.token,o.secret)}})})]}),o.name==="apply-pick"&&!k&&De(pe,{title:"\u5199\u5165\u914D\u7F6E",note:o.token.name,width:t,children:De(le,{width:t-ge,height:n-Xe,retain:"apply",items:o.targets.map(P=>({value:P.client.id,label:P.client.label,badge:P.configured?"\u5DF2\u914D\u7F6E":"\u672A\u914D\u7F6E",badgeTone:P.configured?"accent":void 0,hint:P.paths.join(" ")})),onSelect:P=>C(o,P)})}),o.name==="apply-model"&&!k&&De(te,{title:`${o.needs.client.label} \u9ED8\u8BA4\u6A21\u578B`,width:t,submitLabel:"\u5199\u5165",error:p,fields:[{kind:"select",name:"model",label:"\u6A21\u578B",options:o.models.map(P=>({value:P,label:P})),initial:o.needs.model!==null&&o.models.includes(o.needs.model)?o.needs.model:o.models[0],hint:`\u5199\u5165\u540E\u4F5C\u4E3A ${o.needs.client.label} \u7684\u9ED8\u8BA4\u6A21\u578B`}],onCancel:_,onSubmit:P=>{let B=P.model;if(B===void 0||B===""){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u6A21\u578B");return}M(o.needs.client.label,B,()=>Yh(e.ctx,o.needs.client,o.secret,B,o.models))}})]})}):De(Y,{hints:L(),onEscape:_,isActive:m===null,children:De(V,{state:g,loading:"\u6B63\u5728\u8BFB\u53D6\u4EE4\u724C",width:t,children:({tokens:P,groups:B,site:J})=>{let oe=X+Xe+Ey(J.apiLines.length),fe=Math.max(hC,n-(o.name==="list"?oe:gC));return Ia(Io,{flexDirection:"column",children:[De(Io,{flexDirection:"column",marginBottom:X,children:De(de,{retain:"list",items:P,width:t,height:fe,isActive:S&&!i,columns:[{label:"\u540D\u79F0",shrink:!0},{label:"\u5206\u7EC4"},{label:"\u5DF2\u6D88\u8D39",align:"right"},{label:"\u8D39\u7528\u9650\u5236",align:"right"},{label:"\u5BC6\u94A5"}],row:$=>{let ne=Te($.usedQuota,J.quotaPerUsd);return[$.name,$.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664",$.quotaLimit!==null&&$.usedQuota>=$.quotaLimit?{text:ne,tone:"danger"}:ne,$.quotaLimit===null?"\u4E0D\u9650":Te($.quotaLimit,J.quotaPerUsd),Li($.keyPrefix,$.keySuffix)]},searchOf:$=>`${$.name} ${$.groupName??""}`,onOpen:$=>r({name:"actions",token:$}),emptyLabel:"\u6682\u65E0\u4EE4\u724C",emptyDescription:"\u521B\u5EFA\u4E00\u4E2A\u4EE4\u724C\u5373\u53EF\u5F00\u59CB\u8C03\u7528\u4E2D\u8F6C API"})}),m!==null&&(o.name==="list"||o.name==="actions"||o.name==="confirm-delete")&&De(Oe,{label:m}),o.name==="list"&&De(yC,{lines:J.apiLines,measured:T.phase==="ready"?T.data:null,effective:a??J.apiLines[0],width:t,isActive:S&&i,onPick:R}),o.name==="actions"&&!k&&Ia(pe,{title:o.token.name,width:t,children:[De(Ve,{width:t-ge,items:[["\u5206\u7EC4",o.token.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664"],["\u5DF2\u6D88\u8D39",Te(o.token.usedQuota,J.quotaPerUsd)],["\u8D39\u7528\u9650\u5236",o.token.quotaLimit===null?"\u4E0D\u9650":Te(o.token.quotaLimit,J.quotaPerUsd)],["\u5BC6\u94A5",Li(o.token.keyPrefix,o.token.keySuffix)]]}),De(Io,{marginTop:1,children:De(le,{width:t-ge,items:[{value:"rename",label:"\u540D\u79F0",hint:o.token.name},{value:"regroup",label:"\u5206\u7EC4",hint:o.token.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664"},{value:"relimit",label:"\u8D39\u7528\u9650\u5236",hint:o.token.quotaLimit===null?"\u4E0D\u9650":Te(o.token.quotaLimit,J.quotaPerUsd)},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:$=>v($,o.token)})})]}),o.name==="create"&&De(te,{title:"\u521B\u5EFA\u4EE4\u724C",width:t,submitLabel:"\u521B\u5EFA",error:p,busy:k,busyLabel:"\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",fields:[{kind:"text",name:"name",label:"\u540D\u79F0",placeholder:"\u8BF7\u8F93\u5165\u4EE4\u724C\u540D\u79F0"},{kind:"select",name:"group",label:"\u5206\u7EC4",options:Py(B),initial:String(B[0]?.id??""),hint:$=>Ay(B,$)},{kind:"text",name:"limit",label:"\u8D39\u7528\u9650\u5236",placeholder:"\u7F8E\u5143\u91D1\u989D\uFF0C\u7559\u7A7A\u5219\u4E0D\u9650\u5236",hint:"\u7D2F\u8BA1\u6D88\u8D39\u8FBE\u5230\u8D39\u7528\u4E0A\u9650\u540E\uFF0C\u8BE5\u4EE4\u724C\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD",optional:!0}],onCancel:_,onSubmit:$=>{let ne=($.name??"").trim();if(ne===""){b("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}let w=B.find(re=>String(re.id)===$.group);if(w===void 0){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}let F=_y($.limit??"",J.quotaPerUsd);if(F==="invalid"){b("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}N(ne,w.id,F)}}),o.name==="rename"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"text",name:"name",label:"\u540D\u79F0",initial:o.token.name,placeholder:"\u8BF7\u8F93\u5165\u4EE4\u724C\u540D\u79F0"}],onCancel:_,onSubmit:$=>{let ne=($.name??"").trim();if(ne===""){b("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}h("\u6B63\u5728\u4FDD\u5B58",()=>xa(o.token.id,{name:ne}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="regroup"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"select",name:"group",label:"\u5206\u7EC4",options:Py(B),initial:String(o.token.groupId??B[0]?.id??""),hint:o.token.groupId===null?"\u6240\u5C5E\u5206\u7EC4\u5DF2\u88AB\u5220\u9664\uFF0C\u8BE5\u4EE4\u724C\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u5206\u7EC4":$=>Ay(B,$)}],onCancel:_,onSubmit:$=>{let ne=B.find(w=>String(w.id)===$.group);if(ne===void 0){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}h("\u6B63\u5728\u4FDD\u5B58",()=>xa(o.token.id,{groupId:ne.id}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="relimit"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"text",name:"limit",label:"\u8D39\u7528\u9650\u5236",initial:o.token.quotaLimit===null?"":String(Math.round(o.token.quotaLimit/J.quotaPerUsd*100)/100),placeholder:"\u7F8E\u5143\u91D1\u989D\uFF0C\u7559\u7A7A\u5219\u4E0D\u9650\u5236",hint:`\u8BE5\u4EE4\u724C\u5DF2\u7D2F\u8BA1\u6D88\u8D39 ${Te(o.token.usedQuota,J.quotaPerUsd)}\uFF0C\u8FBE\u5230\u8D39\u7528\u4E0A\u9650\u540E\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD`,optional:!0}],onCancel:_,onSubmit:$=>{let ne=_y($.limit??"",J.quotaPerUsd);if(ne==="invalid"){b("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}h("\u6B63\u5728\u4FDD\u5B58",()=>xa(o.token.id,{quotaLimit:ne}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="confirm-delete"&&!k&&De(Ae,{width:t,title:"\u5220\u9664\u4EE4\u724C",detail:`\u5220\u9664\u300C${o.token.name}\u300D\u540E\u8BE5\u4EE4\u724C\u7ACB\u5373\u5931\u6548\uFF0C\u4F7F\u7528\u5B83\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD`,confirmLabel:"\u5220\u9664",error:p,onConfirm:()=>E(o.token),onCancel:_})]})}})})}import{Box as Ly,Text as SC}from"ink";import{useEffect as xC,useState as $y}from"react";import TC from"string-width";import{z as bC}from"zod";var Na=()=>A(ku,"/docs/manifest"),Iy=e=>A(vu,`/docs/pages/${e}`),Ny=e=>A(bC.array(Cu),Fe("/docs/search",{q:e}));import{jsx as Fn,jsxs as Dy}from"react/jsx-runtime";var wC=250,Oy="/ ";function kC(e,t){let[n,o]=$y(e);return xC(()=>{let r=setTimeout(()=>o(e),t);return()=>clearTimeout(r)},[e,t]),n}var vC=e=>e.groups.flatMap((t,n)=>[...n===0?[]:[{heading:""}],{heading:t.title},...t.items.map(o=>({value:o,label:o.title}))]);function By(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Me("query",()=>""),[i,s]=$y(!1),a=kC(o.trim(),wC),c=a.length>fc,l=Q([e.revision],Na),u=qt(Q([a,e.revision],()=>a===""||c?Promise.resolve(null):Ny(a))),m=l.phase==="ready",p=o.trim()!=="",d=i||p;G(T=>{if(T==="r"){e.reload();return}m&&T.startsWith("/")&&(s(!0),T.length>1&&r(T.slice(1)))},!i);let b=()=>{if(!d){e.pop();return}s(!1),r("")},h=i?["Enter \u786E\u8BA4","Esc \u53D6\u6D88"]:m?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","/ \u641C\u7D22","r \u5237\u65B0",...p?["Esc \u8FD4\u56DE"]:[]]:["r \u5237\u65B0"],g=(T,k)=>e.push("doc",{slug:T,anchor:k}),x=Math.max(3,n-(d?1:0));return Fn(Y,{hints:h,onEscape:b,children:Fn(V,{state:l,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863\u76EE\u5F55",width:t,children:T=>Dy(Ly,{flexDirection:"column",children:[d&&Dy(Ly,{children:[Fn(SC,{color:f.accent,children:Oy}),Fn(er,{value:o,onChange:r,onSubmit:()=>s(!1),isActive:i,placeholder:"\u641C\u7D22\u6587\u6863",width:t-TC(Oy)})]}),p?c?Fn(Ft,{message:`\u5173\u952E\u8BCD\u6700\u591A ${fc} \u4E2A\u5B57\u7B26`,width:t}):Fn(V,{state:u,loading:"\u6B63\u5728\u641C\u7D22",width:t,children:k=>k===null?Fn(Oe,{label:"\u6B63\u5728\u641C\u7D22"}):Fn(de,{retain:"results",items:k,width:t,height:x,isActive:!i,columns:[{label:"\u6807\u9898"},{label:"\u6458\u8981",shrink:!0}],row:S=>[S.title,S.snippet],onOpen:S=>g(S.slug,S.anchor),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})}):Fn(le,{retain:"toc",items:vC(T),width:t,height:x,isActive:!i,onSelect:k=>g(k.slug,null)})]})})})}import{Box as EC,Text as MC}from"ink";import{useMemo as IC,useState as NC}from"react";import{spawn as CC}from"child_process";var RC={darwin:[{command:"pbcopy",args:[]}],win32:[{command:"clip",args:[]}],linux:[{command:"wl-copy",args:[]},{command:"xclip",args:["-selection","clipboard"]},{command:"xsel",args:["--clipboard","--input"]}]};function _C(e,t){return new Promise((n,o)=>{let r=CC(e.command,e.args,{stdio:["pipe","ignore","ignore"]});r.on("error",i=>{i.code==="ENOENT"?n(!1):o(new U(`\u6267\u884C ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))}),r.on("close",i=>{i===0?n(!0):o(new U(`${e.command} \u9000\u51FA\u7801 ${i??"null"}`))}),r.stdin.on("error",i=>o(new U(`\u5199\u5165 ${e.command} \u5931\u8D25\uFF1A${i.message}`,{cause:i}))),r.stdin.end(t)})}async function La(e){let t=RC[process.platform];if(t===void 0)throw new U(`\u5F53\u524D\u7CFB\u7EDF\u4E0D\u652F\u6301\u5199\u5165\u526A\u8D34\u677F\uFF08${process.platform}\uFF09`);for(let n of t)if(await _C(n,e))return;throw new U("\u672A\u627E\u5230\u53EF\u7528\u7684\u526A\u8D34\u677F\u547D\u4EE4")}import{Lexer as PC,walkTokens as AC}from"marked";function Fy(e,t){let n=[],o=[],r=new Set,i="";for(let s of PC.lex(e,{gfm:!0,breaks:!1}))s.type==="heading"&&(i=il(s.tokens,"docs")),AC([s],a=>{if(a.type==="code"){o.push({lang:a.lang??"",text:a.text,section:i});return}if(a.type!=="link"||r.has(a.href))return;r.add(a.href);let c=il(a.tokens,"docs"),l=a.href.startsWith("#")?{slug:t,anchor:gc(a.href.slice(1))}:Ni(a.href);n.push(l===null?{kind:"external",text:c,href:a.href}:{kind:"guide",text:c,...l})});return{links:n,codes:o}}var Uy=e=>Vn(e).split(`
26
- `).map(t=>t.trim()).filter(t=>t!=="").join(" ");import{jsx as No,jsxs as $C}from"react/jsx-runtime";var LC=1,OC=16;function jy({params:e}){let{depth:t}=O();return No(DC,{params:e},t)}function DC({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=NC("body"),s=qt(Q([e.slug,t.revision],async()=>{let[h,g]=await Promise.all([Iy(e.slug),Na()]),x=new Map(g.groups.flatMap(T=>T.items.map(k=>[k.slug,k.title])));return{page:h,titles:x,outline:Fy(h.markdown,e.slug)}})),a=s.phase==="ready"?s.data:null,c=a===null?null:a.page.markdown,l=IC(()=>c===null?[]:hn(c,n,"docs"),[c,n]);G(h=>{if(r!=="body")return;if(h==="r"){t.reload();return}if(a===null)return;let{outline:g}=a;h==="l"&&g.links.length>0?i("links"):h==="c"&&g.codes.length>0&&i("codes")});let u=()=>{r==="body"?t.pop():i("body")},m=h=>{i("body"),La(h).then(()=>t.toast("ok","\u5DF2\u590D\u5236"),()=>t.toast("fail","\u590D\u5236\u5931\u8D25\uFF0C\u53EF\u7528 Option / Alt \u62D6\u9009\u590D\u5236"))},p=()=>{if(a===null)return["r \u5237\u65B0"];if(r==="links")return["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00\u6216\u590D\u5236"];if(r==="codes")return["\u2191\u2193 \u79FB\u52A8","Enter \u590D\u5236"];let{outline:h}=a;return["\u2191\u2193 \u6EDA\u52A8",...h.links.length>0?["l \u94FE\u63A5"]:[],...h.codes.length>0?["c \u590D\u5236\u4EE3\u7801"]:[],"r \u5237\u65B0"]},d=a===null?"\u6587\u6863\u8BE6\u60C5":a.page.title;return No(Y,{trail:r==="links"?["\u4F7F\u7528\u6587\u6863",d,"\u94FE\u63A5"]:r==="codes"?["\u4F7F\u7528\u6587\u6863",d,"\u4EE3\u7801"]:["\u4F7F\u7528\u6587\u6863",d],hints:p(),onEscape:u,children:No(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863",width:n,children:({titles:h,outline:g})=>{if(r==="links")return No(de,{retain:"links",items:g.links,width:n,height:o,columns:[{label:"\u94FE\u63A5",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u76EE\u6807",shrink:!0}],row:T=>T.kind==="guide"?[T.text,"\u7AD9\u5185\u6587\u6863",h.get(T.slug)??""]:[T.text,"\u5916\u90E8\u94FE\u63A5",T.href],onOpen:T=>T.kind==="guide"?t.push("doc",{slug:T.slug,anchor:T.anchor}):m(T.href)});if(r==="codes")return No(de,{retain:"codes",items:g.codes,width:n,height:o,columns:[{label:"\u4EE3\u7801",shrink:!0},{label:"\u8BED\u8A00"},{label:"\u7AE0\u8282",cap:OC}],row:T=>[Uy(T.text),T.lang,T.section],onOpen:T=>m(T.text)});let x=e.anchor===null?-1:l.findIndex(T=>T.anchor===e.anchor);return $C(EC,{flexDirection:"column",children:[No(pt,{retain:"body",lines:l,height:Math.max(1,o-LC),start:Math.max(0,x)}),No(MC,{wrap:"truncate",color:f.faintForeground,children:`\u7F51\u9875\u7248 ${t.ctx.site}/docs/${e.slug}`})]})}})})}import{Box as fm}from"ink";import{jsx as un,jsxs as BC}from"react/jsx-runtime";var Hy=[["\u2191\u2193 / k j","\u79FB\u52A8\u5149\u6807\u3001\u6EDA\u52A8\u5185\u5BB9"],["\u2190\u2192","\u5207\u6362\u5206\u6BB5\u3001\u7FFB\u9875\u3001\u6539\u53D6\u503C"],["[ ]","\u5207\u6362\u9876\u680F\u4E0A\u7684\u529F\u80FD"],["Enter","\u6253\u5F00\u3001\u786E\u8BA4\u3001\u63D0\u4EA4"],["Tab","\u8868\u5355\u4E0B\u4E00\u9879\u3001\u8FDB\u5165\u56DE\u590D\u6846"],["Esc","\u9000\u56DE\u4E0A\u4E00\u5C42"],["r","\u5237\u65B0\u5F53\u524D\u6570\u636E"],["n","\u65B0\u5EFA"],["f","\u7B5B\u9009\u5217\u8868"],["/","\u8FC7\u6EE4\u5217\u8868"],["Space / a","\u591A\u9009\u52FE\u9009\u3001\u5168\u9009"],["?","\u8FD9\u5F20\u8868"],["q","\u8FD4\u56DE\u4E0A\u5C42\uFF0C\u529F\u80FD\u5C4F\u4E0A\u9000\u51FA"],["Ctrl+C","\u9000\u51FA"]],qy=[["\u70B9\u51FB / \u6EDA\u8F6E","\u9009\u4E2D\u6253\u5F00\u3001\u6EDA\u52A8"],["Option / Alt \u62D6\u9009","\u590D\u5236\u6587\u672C"]],Gy=[["\u2190\u2192 Home End","\u79FB\u52A8\u5149\u6807"],["Ctrl+A / Ctrl+E","\u884C\u9996\u3001\u884C\u5C3E"],["Ctrl+W","\u5220\u9664\u524D\u4E00\u4E2A\u8BCD"],["Ctrl+U / Ctrl+K","\u5220\u5230\u884C\u9996\u3001\u884C\u5C3E"]];function zy({width:e,height:t}){let n=e-ge,o=[["\u7248\u672C",`${Wt} v${Vt}`],["\u672C\u5730\u5B58\u50A8",vn()]],r=[Hy,qy,Gy,o],s=(a=>r.reduce((c,l)=>c+Bt+a+zs(l.length,n),X*(r.length-1)))(qe)<=t?qe:0;return BC(Vd,{height:t,children:[un(pe,{title:"\u901A\u7528",width:e,gap:s,children:un(Ve,{items:Hy,width:n})}),un(fm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u9F20\u6807",width:e,gap:s,children:un(Ve,{items:qy,width:n})})}),un(fm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u6587\u672C\u8F93\u5165",width:e,gap:s,children:un(Ve,{items:Gy,width:n})})}),un(fm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u5173\u4E8E",width:e,gap:s,children:un(Ve,{items:o,width:n})})})]})}import{jsx as gm}from"react/jsx-runtime";function Wy(){let e=O(),{width:t}=j(),n=Z();return gn(e.pop),gm(So,{header:gm(Es,{trail:["CodeFlow","\u952E\u4F4D\u5E2E\u52A9"],width:t,onBack:e.pop,isActive:!0}),hints:["Esc \u8FD4\u56DE"],children:gm(zy,{width:t,height:n})})}import{Box as Vy,Text as FC}from"ink";import{jsx as Ti,jsxs as UC}from"react/jsx-runtime";var Ky=[{value:"login",label:"\u767B\u5F55\u8D26\u53F7",hint:"\u4F7F\u7528\u7528\u6237\u540D\u6216\u90AE\u7BB1\u7EE7\u7EED"},{value:"register",label:"\u6CE8\u518C\u8D26\u53F7",hint:"\u521B\u5EFA\u8D26\u53F7\u5F00\u59CB\u4F7F\u7528"},{value:"forgot",label:"\u627E\u56DE\u5BC6\u7801",hint:"\u901A\u8FC7\u90AE\u7BB1\u9A8C\u8BC1\u7801\u8BBE\u7F6E\u65B0\u5BC6\u7801"}];function Yy(){let e=O(),{width:t}=j(),n=oi(0),o=X+1+X+Ky.length,r=_s(t)&&n-Rs>=o;return UC(So,{header:r?Ti(Ps,{width:t}):null,hints:["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","? \u5E2E\u52A9","q \u9000\u51FA"],children:[Ti(Vy,{marginTop:1,children:Ti(FC,{color:f.mutedForeground,wrap:"truncate",children:"\u767B\u5F55\u540E\u5373\u53EF\u521B\u5EFA\u4EE4\u724C\u3001\u5199\u5165\u914D\u7F6E\u5E76\u67E5\u770B\u7528\u91CF"})}),Ti(Vy,{marginTop:1,children:Ti(le,{items:Ky,width:t,retain:"menu",onSelect:i=>e.push(i)})})]})}import{Box as hm,Text as ym}from"ink";import{useState as jC}from"react";import{jsx as nn,jsxs as bm}from"react/jsx-runtime";function Jy(){let e=O(),t=Ms(),{width:n}=j(),o=Z(),{busy:r,run:i}=ue(),[s,a]=jC({name:"list"}),c=ze([e.revision],m=>Bp({page:m}),{retain:"page"}),l=m=>{switch(m.kind){case"post":e.push("post",{id:m.postId});return;case"floor":e.push("floor",{postId:m.postId,floorId:m.floorId});return;case"ticket":e.push("ticket",{id:m.ticketId});return;case"invoices":e.select("invoices");return;case"recharge":e.select("recharge");return;case"subscription":e.select("subscription");return;case"security":e.select("profile");return}},u=m=>{a({name:"detail",message:m}),!m.read&&i("\u6B63\u5728\u6807\u8BB0\u5DF2\u8BFB",()=>Up(m.id),{failToast:!0,onSuccess:e.reload})};if(G((m,p)=>{s.name!=="list"||r!==null||(m==="r"?e.reload():p.leftArrow?c.go(-1):p.rightArrow?c.go(1):m==="a"&&t.any&&i("\u6B63\u5728\u6807\u8BB0\u5DF2\u8BFB",()=>jp(),{failToast:!0,onSuccess:()=>{e.reload(),e.toast("ok","\u5DF2\u5168\u90E8\u6807\u4E3A\u5DF2\u8BFB")}}))}),s.name==="detail"){let m=$c(s.message),p=fd[m.target.kind],d=Pt([{text:st(m.body),color:f.foreground}],n),b=Math.max(3,o-4);return bm(Y,{hints:[...d.length>b?["\u2191\u2193 \u6EDA\u52A8"]:[],`Enter ${p}`,"Esc \u8FD4\u56DE"],onEscape:()=>a({name:"list"}),children:[bm(ym,{wrap:"truncate",children:[nn(ym,{bold:!0,color:f.foreground,children:st(m.title)}),nn(ym,{color:f.faintForeground,children:` ${K(s.message.createdAt)}`})]}),nn(hm,{marginTop:1,children:nn(pt,{lines:d,height:Math.min(d.length,b)})}),nn(hm,{marginTop:1,children:r!==null?nn(Oe,{label:r}):nn(le,{width:n,items:[{value:m.target,label:p}],onSelect:l})})]})}return nn(Y,{hints:["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","\u2190\u2192 \u7FFB\u9875",...t.any?["a \u5168\u90E8\u5DF2\u8BFB"]:[],"r \u5237\u65B0"],children:nn(V,{state:c.state,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u5185\u6D88\u606F",width:n,children:m=>bm(hm,{flexDirection:"column",children:[nn(de,{retain:"list",items:m.items,width:n,height:Math.max(3,o-1),isActive:r===null,columns:[{label:"\u6D88\u606F",shrink:!0},{label:"\u5185\u5BB9",shrink:!0},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:p=>{let d=$c(p),b=st(d.title);return[p.read?b:{text:b,tone:"accent"},st(d.body),K(p.createdAt),p.read?"":{text:"\u672A\u8BFB",tone:"accent"}]},onOpen:u,emptyLabel:"\u6682\u65E0\u6D88\u606F",emptyDescription:"\u6709\u65B0\u6D88\u606F\u65F6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),r!==null?nn(Oe,{label:r}):nn(We,{page:c.page,pages:c.pages,total:c.total,width:n})]})})})}import{Box as Oa,Text as Lo}from"ink";import{useState as Qy}from"react";import{z as St}from"zod";var HC=St.object({inviteCode:St.string(),invitedCount:St.number(),totalReward:St.number(),rewards:St.object({firstInviterPercent:St.number(),firstInviteePercent:St.number(),subsequentInviterPercent:St.number()}),items:St.array(St.object({id:St.number().int(),rewardType:zm,rewardQuota:St.number(),rewardQuotaReversed:St.number(),inviterUsername:St.string(),inviteeUsername:St.string(),createdAt:St.string()}))}),Xy=()=>A(HC,"/invite");import{jsx as Rt,jsxs as Da}from"react/jsx-runtime";var qC=_t(Qa,Yi,"\u5168\u90E8\u7C7B\u578B"),Zy=3;function GC(e){let t=[];return e.firstInviterPercent>0&&t.push(`\u597D\u53CB\u9996\u6B21\u5145\u503C\uFF0C\u4F60\u83B7\u5F97 ${e.firstInviterPercent}% \u989D\u5EA6\u5956\u52B1`),e.firstInviteePercent>0&&t.push(`\u597D\u53CB\u9996\u6B21\u5145\u503C\uFF0C\u597D\u53CB\u672C\u4EBA\u83B7\u5F97 ${e.firstInviteePercent}% \u989D\u5EA6\u5956\u52B1`),e.subsequentInviterPercent>0&&t.push(`\u597D\u53CB\u540E\u7EED\u6BCF\u6B21\u5145\u503C\uFF0C\u4F60\u83B7\u5F97 ${e.subsequentInviterPercent}% \u989D\u5EA6\u5956\u52B1`),t.length===0?["\u9080\u8BF7\u5956\u52B1\u6682\u672A\u5F00\u542F"]:(t.push("\u5956\u52B1\u6309\u597D\u53CB\u5B9E\u4ED8\u91D1\u989D\u5BF9\u5E94\u989D\u5EA6\u6298\u7B97"),t)}function eb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Qy("main"),[i,s]=Qy(""),a=Q([e.revision],async()=>{let[l,u]=await Promise.all([Xy(),Ge(e.ctx.site)]);return{invite:l,site:u}});G(l=>{o==="main"&&(l==="r"?e.reload():l==="f"&&r("filter"))});let c=()=>{o==="main"?e.pop():r("main")};return Rt(Y,{hints:o==="main"?["\u2191\u2193 \u6EDA\u52A8","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:c,children:Rt(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u9080\u8BF7\u4FE1\u606F",width:t,children:({invite:l,site:u})=>{if(o==="filter")return Rt(te,{title:"\u7B5B\u9009\u5956\u52B1\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:qC,initial:i}],onCancel:c,onSubmit:x=>{s(x.type??""),r("main")}});let m=t-ge,p=GC(l.rewards),d=i===""?l.items:l.items.filter(x=>x.rewardType===i),b=x=>Ut(2,t)+X+Bt+x+2+X+Bt+x+p.length+X+Bt+x,h=n-b(qe)>=Zy?qe:0,g=Math.max(Zy,n-b(h));return Da(Oa,{flexDirection:"column",children:[Rt(it,{width:t,tiles:[{label:"\u5DF2\u9080\u8BF7\u4EBA\u6570",value:Le(l.invitedCount)},{label:"\u7D2F\u8BA1\u5956\u52B1\u989D\u5EA6",value:Te(l.totalReward,u.quotaPerUsd)}]}),Rt(Oa,{marginTop:1,flexDirection:"column",children:Da(pe,{title:"\u6211\u7684\u9080\u8BF7",width:t,gap:h,children:[Da(Lo,{wrap:"truncate",children:[Rt(Lo,{color:f.mutedForeground,children:"\u6211\u7684\u9080\u8BF7\u7801 "}),Rt(Lo,{color:f.accent,children:l.inviteCode})]}),Da(Lo,{wrap:"truncate",children:[Rt(Lo,{color:f.mutedForeground,children:"\u9080\u8BF7\u94FE\u63A5 "}),Rt(Lo,{color:f.accent,children:`${e.ctx.site}/register?invite=${l.inviteCode}`})]})]})}),Rt(Oa,{marginTop:1,flexDirection:"column",children:Rt(pe,{title:"\u5956\u52B1\u89C4\u5219",width:t,gap:h,children:p.map((x,T)=>Rt(Lo,{wrap:"truncate",color:f.mutedForeground,children:x},T))})}),Rt(Oa,{marginTop:1,flexDirection:"column",children:Rt(pe,{title:"\u9080\u8BF7\u5956\u52B1\u8BB0\u5F55",note:i===""?void 0:Yi(i),width:t,gap:h,children:Rt(de,{retain:"list",items:d,width:m,height:g,columns:[{label:"\u65F6\u95F4"},{label:"\u597D\u53CB",shrink:!0},{label:"\u5956\u52B1\u7C7B\u578B"},{label:"\u5956\u52B1\u989D\u5EA6",align:"right"}],row:x=>{let T=x.rewardQuota-x.rewardQuotaReversed,k=x.rewardQuotaReversed>0?`\u9000\u6B3E\u51B2\u51CF -${Te(x.rewardQuotaReversed,u.quotaPerUsd)}`:"";return[K(x.createdAt),x.rewardType==="first_invitee"?x.inviterUsername:x.inviteeUsername,Yi(x.rewardType),_e([Te(T,u.quotaPerUsd),k])]},emptyLabel:i===""?"\u6682\u65E0\u5956\u52B1\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u597D\u53CB\u901A\u8FC7\u4F60\u7684\u9080\u8BF7\u7801\u6CE8\u518C\u5E76\u5B8C\u6210\u5145\u503C\u540E\uFF0C\u5956\u52B1\u4F1A\u663E\u793A\u5728\u8FD9\u91CC":void 0})})})]})}})})}import{useState as pb}from"react";import{z as Ie}from"zod";var zC=12e4,WC=Ie.object({id:Ie.number().int(),orderNo:Ie.string(),amountCny:Ie.number().int()}),tb=()=>A(Ie.array(WC),"/invoices/eligible-orders"),nb=Ie.object({id:Ie.number().int(),type:Ja,title:Ie.string(),taxId:Ie.string().nullable(),invoiceNo:Ie.string().nullable(),remark:Ie.string().nullable(),amountCny:Ie.number().int(),status:jm,rejectReason:Ie.string().nullable(),rejectedAt:Ie.string().nullable(),issuedAt:Ie.string().nullable(),createdAt:Ie.string()}),VC=nb.extend({hasFile:Ie.boolean(),orders:Ie.array(Ie.object({orderNo:Ie.string(),amountCny:Ie.number().int()}))}),ob=()=>A(Ie.array(nb),"/invoices"),rb=e=>A(VC,`/invoices/${e}`),ib=e=>A(se,"/invoices",{method:"POST",json:e}),sb=e=>rs(`/invoices/${e}/file`,{timeoutMs:zC}),KC=Ie.object({id:Ie.number().int(),type:Ja,title:Ie.string(),taxId:Ie.string().nullable()}),$a=()=>A(Ie.array(KC),"/invoices/profiles"),ab=e=>A(se,"/invoices/profiles",{method:"POST",json:e}),cb=(e,t)=>A(se,`/invoices/profiles/${e}`,{method:"PATCH",json:t}),lb=e=>A(se,`/invoices/profiles/${e}`,{method:"DELETE"});import{Box as YC,Text as Oo,useInput as JC}from"ink";import{useEffect as XC,useState as QC}from"react";import{jsx as wi,jsxs as Sm}from"react/jsx-runtime";var ZC="[x]",eR="[ ]",mb=4,Ba=2,ub=2;function db({items:e,columns:t,row:n,selected:o,onToggle:r,onToggleAll:i,onSubmit:s,width:a,height:c,emptyLabel:l}){let[u,m]=QC(0),p=Math.max(1,c-1),d=e.length>p?Math.max(1,p-1):p;XC(()=>{m(S=>Math.min(S,Math.max(0,e.length-1)))},[e.length]);let b=cl(u,d),h=S=>{e.length!==0&&m(y=>(y+S+e.length)%e.length)};JC((S,y)=>{if(y.upArrow){h(-1);return}if(y.downArrow){h(1);return}if(y.return){s();return}S===" "&&e.length>0&&r(u)}),G(S=>{if(S==="k"){h(-1);return}if(S==="j"){h(1);return}S==="a"&&i()});let g=S=>{let y=b+S-1;return y>=0&&y<e.length?y:null},x=rt({onWheel:h,onClick:({row:S})=>{let y=g(S);y!==null&&(m(y),r(y))},onHover:({row:S})=>{let y=g(S);y!==null&&m(y)}}),T=Tl(t,e.map(S=>n(S)),a-Ba-mb),k=e.slice(b,b+d);return Sm(YC,{ref:x,flexDirection:"column",children:[Sm(Oo,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(Ba+mb),t.map((S,y)=>S.align==="right"?Kn(S.label,T[y]??0):Je(S.label,T[y]??0)).join(" ".repeat(ub))]}),e.length===0?wi(Oo,{color:f.faintForeground,children:`${" ".repeat(Ba)}${l}`}):k.map((S,y)=>{let R=b+y,N=R===u,E=o.has(R),W=N?f.accent:f.foreground,M=n(S);return Sm(Oo,{wrap:"truncate",children:[wi(Oo,{color:f.accent,children:N?`${ae.cursor} `:" "}),wi(Oo,{color:E?f.accent:W,bold:N,children:`${E?ZC:eR} `}),t.map((C,v)=>{let _=C.align==="right"?Kn(M[v]??"",T[v]??0):Je(M[v]??"",T[v]??0);return wi(Oo,{color:W,bold:N,children:v>0?`${" ".repeat(ub)}${_}`:_},C.label)})]},R)}),(b>0||b+d<e.length)&&wi(Oo,{color:f.faintForeground,children:`${" ".repeat(Ba)}${b+1}-${Math.min(b+d,e.length)} / ${e.length}`})]})}import{jsx as Tr}from"react/jsx-runtime";function fb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=pb({name:"pick"}),[i,s]=pb(new Set),{busy:a,error:c,reset:l,run:u}=ue();Re(a!==null);let m=Q([e.revision],async()=>{let[b,h]=await Promise.all([tb(),$a()]);return{orders:b,profiles:h}});G(b=>{o.name==="pick"&&b==="r"&&e.reload()});let p=()=>{o.name==="pick"?e.pop():o.name==="preset"?r({name:"pick"}):(l(),r({name:"preset"}))},d=(b,h,g)=>{let x=(g.remark??"").trim(),T=b.filter(k=>i.has(k.id)).map(k=>k.id);u("\u6B63\u5728\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7",()=>ib({orderIds:T,type:h.type,title:h.title,taxId:h.taxId,remark:x===""?null:x}),{onSuccess:()=>{e.toast("ok","\u5DF2\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7"),e.pop()}})};return Tr(Y,{trail:["\u53D1\u7968\u7BA1\u7406","\u7533\u8BF7\u5F00\u7968"],hints:o.name==="pick"?["\u2191\u2193 \u79FB\u52A8","Space \u52FE\u9009","a \u5168\u9009","Enter \u4E0B\u4E00\u6B65","r \u5237\u65B0"]:[],onEscape:p,isActive:a===null,children:Tr(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u53EF\u5F00\u7968\u8BA2\u5355",width:t,children:({orders:b,profiles:h})=>{if(o.name==="pick")return b.length===0?Tr(ye,{tone:"info",width:t,title:"\u6682\u65E0\u53EF\u5F00\u7968\u8BA2\u5355",detail:"\u5B8C\u6210\u5145\u503C\u5E76\u652F\u4ED8\u540E\uFF0C\u8BA2\u5355\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}):Tr(db,{items:b,width:t,height:n,columns:[{label:"\u8BA2\u5355\u53F7",shrink:!0},{label:"\u91D1\u989D",align:"right"}],row:g=>[g.orderNo,Ce(g.amountCny)],selected:new Set(b.flatMap((g,x)=>i.has(g.id)?[x]:[])),onToggle:g=>{let x=b[g]?.id;x!==void 0&&s(T=>{let k=new Set(T);return k.has(x)?k.delete(x):k.add(x),k})},onToggleAll:()=>s(g=>b.every(x=>g.has(x.id))?new Set:new Set(b.map(x=>x.id))),onSubmit:()=>{if(!b.some(g=>i.has(g.id))){e.toast("warn","\u8BF7\u5148\u52FE\u9009\u8981\u5F00\u7968\u7684\u8BA2\u5355");return}if(h.length===0){e.toast("warn","\u6682\u65E0\u5E38\u7528\u5F00\u7968\u4FE1\u606F\uFF0C\u8FD4\u56DE\u540E\u6309 p \u65B0\u589E");return}r({name:"preset"})},emptyLabel:"\u6682\u65E0\u53EF\u5F00\u7968\u8BA2\u5355"});if(o.name==="preset"){let g=[{heading:"\u5E38\u7528\u4FE1\u606F"},...h.map(x=>({value:x,label:`${uo(x.type)} \xB7 ${x.title}`,hint:x.taxId??void 0}))];return Tr(le,{items:g,width:t,height:n,onSelect:x=>r({name:"remark",profile:x})})}return Tr(te,{title:"\u7533\u8BF7\u5F00\u7968 \u2014 \u5907\u6CE8",width:t,submitLabel:"\u63D0\u4EA4\u7533\u8BF7",busy:a!==null,busyLabel:a??"\u6B63\u5728\u63D0\u4EA4",error:c,fields:[{kind:"textarea",name:"remark",label:"\u5907\u6CE8",rows:2,maxLength:200,placeholder:"\u5C55\u793A\u5728\u53D1\u7968\u7968\u9762\u5907\u6CE8\u680F\u7684\u5185\u5BB9",optional:!0}],onCancel:p,onSubmit:g=>d(b,o.profile,g)})}})})}import{Box as xm}from"ink";import{useState as tR}from"react";function gb(e,t){let n=e.type??"general",o=(e.title??"").trim(),r=(e.taxId??"").trim();return o===""?(t("\u8BF7\u8F93\u5165\u62AC\u5934"),null):n==="special"&&r===""?(t("\u589E\u503C\u7A0E\u4E13\u7528\u53D1\u7968\u9700\u586B\u5199\u7A0E\u53F7"),null):{type:n,title:o,taxId:r===""?null:r}}var hb=e=>[{kind:"select",name:"type",label:"\u7C7B\u578B",options:[{value:"general",label:qr("general")},{value:"special",label:qr("special")}],initial:e?.type??"general"},{kind:"text",name:"title",label:"\u62AC\u5934",initial:e?.title??"",placeholder:"\u4E2A\u4EBA\u6216\u5355\u4F4D\u540D\u79F0"},{kind:"text",name:"taxId",label:"\u7A0E\u53F7",initial:e?.taxId??"",placeholder:"\u7EB3\u7A0E\u4EBA\u8BC6\u522B\u53F7",optional:t=>t.type!=="special"}];import{jsx as Un,jsxs as yb}from"react/jsx-runtime";var nR=8,oR=3;function bb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=tR({name:"list"}),{busy:i,error:s,reset:a,fail:c,run:l}=ue();Re(i!==null);let u=Q([e.revision],$a),m=i!==null,p=o.name==="list"&&!m;G(b=>{b==="r"?e.reload():b==="n"&&r({name:"create"})},p);let d=()=>{o.name==="list"?e.pop():(a(),r({name:"list"}))};return Un(Y,{trail:["\u53D1\u7968\u7BA1\u7406","\u5E38\u7528\u4FE1\u606F"],hints:p?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","n \u65B0\u5EFA","r \u5237\u65B0"]:[],onEscape:d,isActive:i===null,children:Un(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u5E38\u7528\u5F00\u7968\u4FE1\u606F",width:t,children:b=>{let h=o.name==="list"?n:Math.max(oR,n-nR);return yb(xm,{flexDirection:"column",children:[Un(xm,{marginBottom:o.name==="list"?0:1,children:Un(de,{retain:"list",items:b,width:t,height:h,isActive:p,columns:[{label:"\u7C7B\u578B"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7A0E\u53F7"}],row:g=>[uo(g.type),g.title,g.taxId??"\u2014"],onOpen:g=>r({name:"actions",profile:g}),emptyLabel:"\u6682\u65E0\u5E38\u7528\u5F00\u7968\u4FE1\u606F",emptyDescription:"\u6309 n \u4FDD\u5B58\u4E00\u6761\u5E38\u7528\u5F00\u7968\u4FE1\u606F"})}),o.name==="actions"&&!m&&yb(pe,{title:o.profile.title,width:t,children:[Un(Ve,{width:t-ge,items:[["\u7C7B\u578B",qr(o.profile.type)],["\u7A0E\u53F7",o.profile.taxId??"\u2014"]]}),Un(xm,{marginTop:1,children:Un(le,{width:t-ge,items:[{value:"edit",label:"\u7F16\u8F91"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:g=>{a(),r(g==="edit"?{name:"edit",profile:o.profile}:{name:"confirm-delete",profile:o.profile})}})})]}),(o.name==="create"||o.name==="edit")&&Un(te,{title:o.name==="create"?"\u65B0\u589E\u5E38\u7528\u4FE1\u606F":`\u7F16\u8F91\u5E38\u7528\u4FE1\u606F \u2014 ${o.profile.title}`,width:t,submitLabel:"\u4FDD\u5B58",busy:m,busyLabel:i??"\u6B63\u5728\u4FDD\u5B58",error:s,fields:hb(o.name==="edit"?o.profile:null),onCancel:d,onSubmit:g=>{let x=gb(g,c);if(x===null)return;let T=o.name==="edit"?()=>cb(o.profile.id,x):()=>ab(x);l("\u6B63\u5728\u4FDD\u5B58",T,{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u4FDD\u5B58")}})}}),o.name==="confirm-delete"&&Un(Ae,{width:t,title:"\u5220\u9664\u5E38\u7528\u5F00\u7968\u4FE1\u606F",detail:`\u786E\u8BA4\u5220\u9664\u300C${o.profile.title}\u300D\uFF1F`,confirmLabel:"\u5220\u9664",busy:i,error:s,onConfirm:()=>l("\u6B63\u5728\u5220\u9664",()=>lb(o.profile.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:d})]})}})})}import{Box as ki,Text as wr}from"ink";import{useState as Tm}from"react";import{jsx as nt,jsxs as Sb}from"react/jsx-runtime";var rR=_t(Ya,Vi,"\u5168\u90E8\u72B6\u6001");function iR({id:e,width:t}){let n=O(),o=Q([e,n.revision],()=>rb(e)),r=t-ge,[i,s]=Tm(null),[a,c]=Tm(null),l=o.phase==="ready"?o.data:null;return G(u=>{if(u!=="d"||l===null||a!==null)return;let m=l.invoiceNo;!l.hasFile||m===null||(s(null),c(m))}),nt(V,{state:o,loading:"\u6B63\u5728\u8BFB\u53D6\u53D1\u7968\u8BE6\u60C5",width:t,children:u=>{if(a!==null)return nt(ur,{title:"\u4FDD\u5B58\u53D1\u7968\u6587\u4EF6",width:t,download:async()=>({fileName:`\u53D1\u7968-${a}.pdf`,bytes:await sb(u.id)}),onCancel:()=>c(null),onSaved:b=>{c(null),s(b),n.toast("ok","\u53D1\u7968\u5DF2\u4FDD\u5B58")}});let m=Vi(u.status),p=ht(m),d=[["\u62AC\u5934",u.title],...u.taxId===null?[]:[["\u7A0E\u53F7",u.taxId]],...u.invoiceNo===null?[]:[["\u53D1\u7968\u53F7\u7801",u.invoiceNo]],...u.remark===null?[]:[["\u5907\u6CE8",u.remark]],["\u7533\u8BF7\u65F6\u95F4",K(u.createdAt)],...u.rejectReason===null?[]:[["\u9A73\u56DE\u539F\u56E0",u.rejectReason]],...u.rejectedAt===null?[]:[["\u9A73\u56DE\u65F6\u95F4",K(u.rejectedAt)]],...u.issuedAt===null?[]:[["\u5F00\u7968\u65F6\u95F4",K(u.issuedAt)]]];return Sb(pe,{title:u.title,note:K(u.createdAt),width:t,children:[Sb(wr,{wrap:"truncate",children:[nt(wr,{color:f.mutedForeground,children:uo(u.type)}),nt(wr,{color:p===void 0?f.mutedForeground:et[p],children:` ${m.label}`})]}),nt(ki,{marginTop:1,children:nt(it,{width:r,maxPerRow:2,tiles:[{label:"\u91D1\u989D",value:Ce(u.amountCny)},{label:"\u5173\u8054\u8BA2\u5355",value:`${u.orders.length} \u7B14`}]})}),nt(ki,{marginTop:1,children:nt(Ve,{width:r,items:d})}),nt(ki,{marginTop:1,flexDirection:"column",children:u.orders.map(b=>nt(wr,{wrap:"truncate",color:f.faintForeground,children:_e([b.orderNo,Ce(b.amountCny)])},b.orderNo))}),u.hasFile&&i===null&&nt(ki,{marginTop:1,children:nt(wr,{wrap:"truncate",color:f.faintForeground,children:"\u6309 d \u4E0B\u8F7D\u53D1\u7968\u6587\u4EF6"})}),i!==null&&nt(ki,{marginTop:1,children:nt(wr,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${i}`})})]})}})}function xb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Tm({name:"list"}),[i,s]=Me("status",()=>""),a=Q([e.revision],ob);G(l=>{o.name==="list"&&(l==="r"?e.reload():l==="f"?r({name:"filter"}):l==="n"?e.push("invoice-apply"):l==="p"&&e.push("invoice-profiles"))});let c=()=>{o.name==="list"?e.pop():r({name:"list"})};return nt(Y,{hints:o.name==="list"?["\u2191\u2193 \u79FB\u52A8","Enter \u8BE6\u60C5","n \u7533\u8BF7\u5F00\u7968","p \u5E38\u7528\u4FE1\u606F","f \u7B5B\u9009","/ \u8FC7\u6EE4","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:c,children:nt(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u5F00\u7968\u8BB0\u5F55",width:t,children:l=>{if(o.name==="filter")return nt(te,{title:"\u7B5B\u9009\u53D1\u7968",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:rR,initial:i}],onCancel:c,onSubmit:m=>{s(m.status??""),r({name:"list"})}});if(o.name==="detail")return nt(iR,{id:o.id,width:t});let u=i===""?l:l.filter(m=>m.status===i);return nt(de,{retain:"list",items:u,width:t,height:n,columns:[{label:"\u65F6\u95F4"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u91D1\u989D",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:m=>[K(m.createdAt),m.title,uo(m.type),Ce(m.amountCny),yt(Vi(m.status))],searchOf:m=>m.title,onOpen:m=>r({name:"detail",id:m.id}),emptyLabel:i===""?"\u6682\u65E0\u5F00\u7968\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u6309 n \u4E3A\u5DF2\u4ED8\u6B3E\u8BA2\u5355\u7533\u8BF7\u5F00\u7968":void 0})}})})}import{Box as sR}from"ink";import{useState as Tb}from"react";import{jsx as kr,jsxs as cR}from"react/jsx-runtime";var aR=_t(Xa,jc,"\u5168\u90E8\u7C7B\u578B");function wb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Tb("list"),[i,s]=Tb(""),a=Q([e.revision],()=>Ge(e.ctx.site)),c=ze([e.revision,i],m=>vh({page:m,...i===""?{}:{type:i}}),{retain:"page"}),l=o==="list";G((m,p)=>{l&&(m==="r"?e.reload():m==="f"?r("filter"):p.leftArrow?c.go(-1):p.rightArrow&&c.go(1))});let u=()=>{o==="list"?e.pop():r("list")};return kr(Y,{hints:l?["\u2191\u2193 \u6EDA\u52A8","\u2190\u2192 \u7FFB\u9875","f \u7B5B\u9009","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:u,children:kr(V,{state:a,loading:"\u6B63\u5728\u8BFB\u53D6\u7AD9\u70B9\u914D\u7F6E",width:t,children:m=>o==="filter"?kr(te,{title:"\u7B5B\u9009\u6D41\u6C34",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"type",label:"\u7C7B\u578B",options:aR,initial:i}],onCancel:u,onSubmit:p=>{s(p.type??""),c.reset(),r("list")}}):kr(V,{state:c.state,loading:"\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u6D41\u6C34",width:t,children:p=>cR(sR,{flexDirection:"column",children:[kr(de,{retain:"list",items:p.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u65F6\u95F4"},{label:"\u7C7B\u578B"},{label:"\u53D8\u52A8",align:"right"},{label:"\u4F59\u989D",align:"right"},{label:"\u6765\u6E90",align:"right"}],row:d=>{let b=Xo(d.amount,m.quotaPerUsd);return[K(d.createdAt),jc(d.type),{text:d.amount>=0?`+${b}`:b,tone:d.amount>=0?"success":"danger"},Te(d.balanceAfter,m.quotaPerUsd),_e([Sd(d.refType),d.refId??""])]},emptyLabel:i===""?"\u6682\u65E0\u989D\u5EA6\u6D41\u6C34":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u5145\u503C\u6216\u6D88\u8017\u540E\uFF0C\u6BCF\u7B14\u53D8\u52A8\u4F1A\u8BB0\u5F55\u5728\u8FD9\u91CC":void 0}),kr(We,{page:c.page,pages:c.pages,total:c.total,width:t})]})})})})}import{Box as Pb}from"ink";import{useState as mR}from"react";import{z as lR}from"zod";var vi={recharge:"/recharge",subscription:"/subscriptions"};async function Fa(e,t){let n=`${vi[e]}/orders/${t}`;return e==="recharge"?{kind:e,...await A(Mr,n)}:{kind:e,...await A(Ir,n)}}async function kb(e,t){let n=`${vi[e]}/orders/${t}/pay`;if(e==="recharge"){let{order:i,qrCode:s}=await A(Mi,n,{method:"POST"});return{order:{kind:e,...i},qrCode:s}}let{order:o,qrCode:r}=await A(Nr,n,{method:"POST"});return{order:{kind:e,...o},qrCode:r}}var vb=(e,t)=>A(lR.array(fu),`${vi[e]}/orders/${t}/refunds`),Cb=(e,t,n)=>A(se,`${vi[e]}/orders/${t}/refund-request`,{method:"POST",json:{reason:n}}),Rb=(e,t)=>A(se,`${vi[e]}/orders/${t}/refund-request/cancel`,{method:"POST"});import{Box as Ua,Text as wn}from"ink";import{jsx as on,jsxs as Ci}from"react/jsx-runtime";function _b({order:e,refunds:t,quotaPerUsd:n,width:o}){let r=o-ge,i=zn(e.status),s=ht(i),a=[["\u521B\u5EFA\u65F6\u95F4",K(e.createdAt)]];return e.succeededRefundCny>0&&a.push(["\u5DF2\u9000\u91D1\u989D",Ce(e.succeededRefundCny)]),e.kind==="recharge"&&e.refundedQuota>0&&a.push(["\u6263\u56DE\u989D\u5EA6",Te(e.refundedQuota,n)]),e.pendingRefundCny>0&&a.push(["\u5F85\u786E\u8BA4\u9000\u6B3E",Ce(e.pendingRefundCny)]),Ci(pe,{title:e.kind==="recharge"?"\u5145\u503C":e.planName,note:e.orderNo,width:o,children:[Ci(wn,{wrap:"truncate",children:[on(wn,{color:s===void 0?f.mutedForeground:et[s],children:i.label}),e.kind==="subscription"&&on(wn,{color:f.faintForeground,children:` ${e.renewal?"\u7EED\u8D39":"\u65B0\u8D2D"}`})]}),on(Ua,{marginTop:1,children:on(it,{width:r,maxPerRow:2,tiles:e.kind==="recharge"?[{label:"\u91D1\u989D",value:Ce(e.amountCny)},{label:"\u5230\u8D26\u989D\u5EA6",value:Te(e.quota,n)}]:[{label:"\u91D1\u989D",value:Ce(e.amountCny)},{label:"\u8BA2\u9605\u65F6\u957F",value:`${e.grantedDurationDays} \u5929`}]})}),on(Ua,{marginTop:1,children:on(Ve,{width:r,items:a})}),t!==null&&Ci(Ua,{marginTop:1,flexDirection:"column",children:[on(wn,{color:f.mutedForeground,children:"\u9000\u6B3E\u8BB0\u5F55"}),t.length===0?on(wn,{color:f.faintForeground,children:"\u6682\u65E0\u9000\u6B3E\u8BB0\u5F55"}):t.map(c=>{let l=xd(c.status),u=ht(l);return Ci(Ua,{flexDirection:"column",children:[Ci(wn,{wrap:"truncate",children:[on(wn,{color:f.foreground,children:Ce(c.amountCny)}),on(wn,{color:u===void 0?f.mutedForeground:et[u],children:` ${l.label}`}),on(wn,{color:f.faintForeground,children:` ${K(c.createdAt)}`})]}),(c.reason!==null||c.rejectReason!==null||c.refundTradeNo!==null)&&on(wn,{wrap:"truncate",color:f.faintForeground,children:` ${_e([c.reason??"",c.rejectReason===null?"":`\u9A73\u56DE\uFF1A${c.rejectReason}`,c.refundTradeNo??""])}`})]},c.id)})]})]})}import{jsx as Do,jsxs as dR}from"react/jsx-runtime";var uR=new Set(["pending","expired","failed"]);function ja(e){let t=zn(e.status);return e.pendingRefundCny>0?{badge:`${t.label}\uFF08\u5F85\u786E\u8BA4 ${Ce(e.pendingRefundCny)}\uFF09`,badgeTone:"warning"}:{badge:t.label,badgeTone:ht(t)}}function vr(e,t,n){return e.kind==="recharge"?{kind:"recharge",orderNo:e.orderNo,qrCode:t,amountCny:e.amountCny,summary:[`\u5230\u8D26\u989D\u5EA6 ${Te(e.quota,n)}`],paidMessage:"\u5145\u503C\u6210\u529F\uFF01",paidNote:"\u4F59\u989D\u5DF2\u5230\u8D26",expiredNote:"\u82E5\u5DF2\u5B8C\u6210\u4ED8\u6B3E\uFF0C\u4F59\u989D\u4F1A\u81EA\u52A8\u5230\u8D26\uFF0C\u8BF7\u52FF\u91CD\u590D\u5145\u503C\uFF1B\u53EF\u5728\u300C\u5145\u503C\u8BB0\u5F55\u300D\u4E2D\u67E5\u770B"}:{kind:"subscription",orderNo:e.orderNo,qrCode:t,amountCny:e.amountCny,summary:[`${e.planName} \xB7 ${e.grantedDurationDays} \u5929`],paidMessage:"\u8BA2\u9605\u5DF2\u751F\u6548\uFF01",paidNote:"\u8BA2\u9605\u5DF2\u751F\u6548",expiredNote:"\u82E5\u5DF2\u5B8C\u6210\u4ED8\u6B3E\uFF0C\u8BA2\u9605\u4F1A\u81EA\u52A8\u751F\u6548\uFF0C\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\uFF1B\u53EF\u5728\u300C\u8BA2\u9605\u8BA2\u5355\u300D\u4E2D\u67E5\u770B"}}function Ab({params:e}){let t=O(),{width:n}=j(),[o,r]=mR("main"),{busy:i,error:s,reset:a,fail:c,run:l}=ue();Re(i!==null);let u=Q([e.kind,e.orderNo,t.revision],async()=>{let[h,g]=await Promise.all([Fa(e.kind,e.orderNo),Ge(t.ctx.site)]),x=uR.has(h.status)?null:await vb(e.kind,e.orderNo);return{order:h,refunds:x,site:g}});G(h=>{o==="main"&&i===null&&h==="r"&&t.reload()});let m=()=>{o==="main"?t.pop():(a(),r("main"))},p=h=>{l("\u6B63\u5728\u62C9\u8D77\u652F\u4ED8",()=>kb(e.kind,e.orderNo),{failToast:!0,onSuccess:({order:g,qrCode:x})=>{t.push("pay",vr(g,x,h.quotaPerUsd))}})},d=h=>{l("\u6B63\u5728\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7",()=>Cb(e.kind,e.orderNo,h),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7")}})},b=()=>{l("\u6B63\u5728\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",()=>Rb(e.kind,e.orderNo),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u64A4\u9500\u9000\u6B3E\u7533\u8BF7")}})};return Do(Y,{trail:["\u8BA2\u5355\u8BE6\u60C5"],hints:o==="main"?["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C","r \u5237\u65B0"]:[],onEscape:m,isActive:i===null,children:Do(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u5355",width:n,children:({order:h,refunds:g,site:x})=>{if(o==="refund")return Do(te,{title:`\u7533\u8BF7\u9000\u6B3E \u2014 ${h.orderNo}`,width:n,submitLabel:"\u63D0\u4EA4\u7533\u8BF7",busy:i!==null,busyLabel:i??"\u6B63\u5728\u63D0\u4EA4",error:s,fields:[{kind:"select",name:"reason",label:"\u9000\u6B3E\u539F\u56E0",options:[...Wc[e.kind].map(k=>({value:k,label:k})),{value:"other",label:"\u5176\u4ED6"}],initial:Wc[e.kind][0],hint:_d[e.kind]},{kind:"textarea",name:"custom",label:"\u5177\u4F53\u8BF4\u660E",rows:3,maxLength:256,placeholder:"\u8BF4\u660E\u7533\u8BF7\u9000\u6B3E\u7684\u539F\u56E0",hint:"\u4EC5\u9000\u6B3E\u539F\u56E0\u9009\u300C\u5176\u4ED6\u300D\u65F6\u5FC5\u586B"}],onCancel:m,onSubmit:k=>{let S=k.reason??"",y=S==="other"?(k.custom??"").trim():S;if(y===""){c("\u8BF7\u586B\u5199\u5177\u4F53\u8BF4\u660E");return}d(y)}});if(o==="confirm-cancel")return Do(Ae,{width:n,title:"\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",detail:`\u786E\u8BA4\u64A4\u9500\u8BA2\u5355 ${h.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\uFF1F${h.kind==="recharge"?"\u6536\u56DE\u7684\u989D\u5EA6":"\u51BB\u7ED3\u7684\u8BA2\u9605\u65F6\u957F"}\u5C06\u7ACB\u5373\u6062\u590D`,confirmLabel:"\u64A4\u9500\u7533\u8BF7",busy:i,error:s,onConfirm:b,onCancel:m});let T=[];return h.status==="pending"&&T.push({value:"pay",label:"\u7EE7\u7EED\u652F\u4ED8",hint:"\u91CD\u65B0\u62C9\u8D77\u652F\u4ED8\u5B9D\u4E8C\u7EF4\u7801"}),h.status==="refund_requested"&&T.push({value:"cancel-refund",label:"\u64A4\u9500\u7533\u8BF7",hint:"\u9000\u6B3E\u5C1A\u672A\u5BA1\u6838\uFF0C\u53EF\u64A4\u56DE"}),gu(h)&&T.push({value:"refund",label:"\u7533\u8BF7\u9000\u6B3E",labelTone:"danger"}),dR(Pb,{flexDirection:"column",children:[Do(_b,{order:h,refunds:g,quotaPerUsd:x.quotaPerUsd,width:n}),T.length>0&&i===null&&Do(Pb,{marginTop:1,children:Do(le,{width:n,items:T,retain:"menu",onSelect:k=>{a(),k==="pay"?p(x):r(k==="refund"?"refund":"confirm-cancel")}})})]})}})})}import{useRef as fR,useState as Ob}from"react";import{Box as Eb,Text as $o}from"ink";import{Fragment as pR,jsx as zt,jsxs as Mb}from"react/jsx-runtime";var Ib={columns:20,rows:2};function Nb(e,t,n){return js(e,t,Ib,n)}function Lb({phase:e,qrCode:t,amountCny:n,summary:o,paidNote:r,expiredNote:i,pollError:s,width:a,layout:c}){let l=s===null?zt(Oe,{label:"\u7B49\u5F85\u652F\u4ED8\u5230\u8D26\u2026"}):zt($o,{wrap:"truncate",color:et.warning,children:`\u67E5\u8BE2\u5931\u8D25\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF1A${s}`});if(e==="paid")return zt(ye,{tone:"ok",width:a,title:"\u652F\u4ED8\u6210\u529F\uFF01",detail:r});if(e==="expired")return zt(ye,{tone:"warn",width:a,title:"\u8BA2\u5355\u5DF2\u8D85\u65F6",detail:i});if(!c.fits)return Mb(Eb,{flexDirection:"column",children:[zt(ye,{tone:"warn",width:a,title:"\u7EC8\u7AEF\u5C3A\u5BF8\u4E0D\u8DB3\uFF0C\u65E0\u6CD5\u7ED8\u5236\u4E8C\u7EF4\u7801",detail:`\u653E\u5927\u5230 ${c.target.columns} \xD7 ${c.target.rows} \u53EF\u663E\u793A\u4E8C\u7EF4\u7801\uFF0C\u6216\u6309 c \u590D\u5236\u4ED8\u6B3E\u94FE\u63A5`}),zt($o,{color:f.accent,children:t}),zt(Eb,{marginTop:1,children:zt($o,{bold:!0,color:f.foreground,children:Ce(n)})}),l]});let u=c.asideRows-Ib.rows,m=u>=1,p=u>=2,d=u>=2+o.length;return zt(Hs,{value:t,aside:Mb(pR,{children:[p&&zt($o,{bold:!0,color:f.foreground,children:"\u626B\u7801\u652F\u4ED8"}),zt($o,{bold:!0,color:f.foreground,children:Ce(n)}),m&&zt($o,{color:f.mutedForeground,children:"\u8BF7\u4F7F\u7528\u652F\u4ED8\u5B9D\u626B\u4E00\u626B\u5B8C\u6210\u652F\u4ED8"}),d&&o.map((b,h)=>zt($o,{wrap:"truncate",color:f.mutedForeground,children:b},h)),l]})})}import{jsx as Db}from"react/jsx-runtime";var gR=5,hR=2e3;function $b({params:e}){let t=O(),{width:n,columns:o,rows:r}=j(),i=oi(0),[s,a]=Ob("waiting"),[c,l]=Ob(null),u=fR(0);na(hR,async()=>{let d;try{d=await Fa(e.kind,e.orderNo)}catch(b){l(xe(b));return}if(l(null),d.status==="paid"||d.credited){a("paid"),t.toast("ok",e.paidMessage);return}if(d.status==="expired"||d.status==="failed"){u.current+=1,u.current>=gR&&a("expired");return}u.current=0},s==="waiting"),G(d=>{d!=="c"||s!=="waiting"||La(e.qrCode).then(()=>t.toast("ok","\u5DF2\u590D\u5236"),()=>t.toast("fail","\u590D\u5236\u5931\u8D25\uFF0C\u53EF\u7528 Option / Alt \u62D6\u9009\u590D\u5236"))});let m=Nb(e.qrCode,{width:n,rows:i},{columns:o-n,rows:r-i}),p=s==="waiting"&&m.fits;return Db(Y,{trail:["\u626B\u7801\u652F\u4ED8"],bleed:p,hints:s==="waiting"?["c \u590D\u5236\u94FE\u63A5"]:[],children:Db(Lb,{phase:s,qrCode:e.qrCode,amountCny:e.amountCny,summary:e.summary,paidNote:e.paidNote,expiredNote:e.expiredNote,pollError:c,width:n,layout:m})})}import{useState as bR}from"react";import{z as jn}from"zod";var yR=jn.object({id:jn.number().int(),name:jn.string(),originalCny:jn.number().int(),discountPercent:jn.number().int(),payCny:jn.number().int(),quota:jn.number()}),Bb=()=>A(jn.array(yR),"/recharge-packages"),Fb=e=>A(Mi,"/recharge/orders",{method:"POST",json:e}),Ub=()=>A(jn.array(Mr),"/recharge/orders");import{jsx as Cr}from"react/jsx-runtime";var SR=_t(_r,zn,"\u5168\u90E8\u72B6\u6001");function xR(e,t){let n=e.discountPercent<100?`\uFF08\u539F\u4EF7 ${Ce(e.originalCny)} \xB7 ${e.discountPercent/10} \u6298\uFF09`:"";return`${Ce(e.payCny)}${n} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(e.quota,t)}`}function jb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=bR({name:"menu"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=ue();Re(a!==null);let p=Q([e.revision],async()=>{let[h,g,x]=await Promise.all([Bb(),wa(e.ctx.site),Ub()]);return{packages:h,pricing:g,orders:x}});G(h=>{o.name==="menu"&&(h==="r"?e.reload():h==="f"&&r({name:"filter"}))});let d=()=>{o.name==="menu"?e.pop():(l(),r({name:"menu"}))},b=(h,g)=>{m("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>Fb(h),{onSuccess:({order:x,qrCode:T})=>{r({name:"menu"}),e.push("pay",vr({kind:"recharge",...x},T,g))}})};return Cr(Y,{hints:o.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","f \u7B5B\u9009\u8BB0\u5F55","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:d,isActive:a===null,children:Cr(V,{state:p,loading:"\u6B63\u5728\u8BFB\u53D6\u5145\u503C\u5957\u9910",width:t,children:({packages:h,pricing:g,orders:x})=>{if(o.name==="confirm")return Cr(Ae,{width:t,title:`\u786E\u8BA4\u5145\u503C ${Ce(o.pkg.payCny)}\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>b({packageId:o.pkg.id},g.quotaPerUsd),onCancel:d});if(o.name==="custom")return Cr(te,{title:"\u81EA\u5B9A\u4E49\u91D1\u989D\u5145\u503C",width:t,submitLabel:"\u53BB\u652F\u4ED8",busy:a!==null,busyLabel:a??"\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",error:c,fields:[{kind:"text",name:"yuan",label:"\u5145\u503C\u91D1\u989D\uFF08\u5143\uFF09",placeholder:"\u8BF7\u8F93\u5165\u91D1\u989D",hint:`\u6700\u4F4E ${g.minTopupCny} \u5143 \xB7 \u5230\u8D26\u989D\u5EA6\u6309\u5145\u503C\u6C47\u7387\u6298\u7B97`}],onCancel:d,onSubmit:S=>{let y=Number((S.yuan??"").trim()),R=Oc(y);if(!Number.isFinite(y)||R<Oc(g.minTopupCny)||R>ic){u(`\u8BF7\u8F93\u5165 ${g.minTopupCny} \u5230 ${ud(ic)} \u5143\u4E4B\u95F4\u7684\u91D1\u989D`);return}b({amountCny:R},g.quotaPerUsd)}});if(o.name==="filter")return Cr(te,{title:"\u7B5B\u9009\u5145\u503C\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:SR,initial:i}],onCancel:d,onSubmit:S=>{s(S.status??""),r({name:"menu"})}});let T=i===""?x:x.filter(S=>S.status===i),k=[{heading:"\u5145\u503C\u5957\u9910"},...h.map(S=>({value:{kind:"pkg",pkg:S},label:S.name,hint:xR(S,g.quotaPerUsd)})),{value:{kind:"custom"},label:"\u81EA\u5B9A\u4E49\u91D1\u989D",hint:"\u8F93\u5165\u4EFB\u610F\u91D1\u989D\u5145\u503C"},{heading:""},{heading:"\u5145\u503C\u8BB0\u5F55"},...T.length===0?[{value:{kind:"none"},label:i===""?"\u6682\u65E0\u5145\u503C\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",...i===""?{hint:"\u9009\u62E9\u4E0A\u65B9\u5957\u9910\u6216\u8F93\u5165\u81EA\u5B9A\u4E49\u91D1\u989D\u5373\u53EF\u5145\u503C"}:{},disabled:!0}]:T.map(S=>({value:{kind:"order",orderNo:S.orderNo},label:Ce(S.amountCny),...ja(S),hint:`${K(S.createdAt)} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(S.quota,g.quotaPerUsd)}`}))];return Cr(le,{items:k,width:t,height:n,retain:"menu",onSelect:S=>{l(),S.kind==="custom"?r({name:"custom"}):S.kind==="order"?e.push("order",{kind:"recharge",orderNo:S.orderNo}):S.kind==="pkg"&&r({name:"confirm",pkg:S.pkg})}})}})})}import{Box as Hn,Text as Ri}from"ink";import{useState as vR}from"react";import CR from"string-width";import{z as Se}from"zod";var TR=Se.object({windowId:Se.number().int(),durationMinutes:Se.number().int(),quota:Se.number(),used:Se.number(),resetAt:Se.string()}),Hb=Se.object({name:Se.string(),multiplier:Se.number()}),wR=Se.object({billingPreference:Va,subscriptions:Se.array(Se.object({id:Se.number().int(),planName:Se.string(),groups:Se.array(Hb),startsAt:Se.string(),expiresAt:Se.string(),revokedAt:Se.string().nullable(),renewable:Se.boolean(),windows:Se.array(TR)}))}),qb=()=>A(wR,"/subscriptions"),kR=Se.object({id:Se.number().int(),name:Se.string(),description:Se.string().nullable(),priceCny:Se.number().int(),durationDays:Se.number().int(),enabled:Se.boolean(),groups:Se.array(Hb),windows:Se.array(Se.object({durationMinutes:Se.number().int(),quota:Se.number()}))}),Gb=()=>A(Se.array(kR),"/subscription-plans"),zb=e=>A(Nr,"/subscriptions/orders",{method:"POST",json:e}),Wb=e=>A(Nr,`/subscriptions/${e}/renew`,{method:"POST"}),Vb=()=>A(Se.array(Ir),"/subscriptions/orders"),Kb=e=>A(Se.object({billingPreference:Va}),"/subscriptions/preference",{method:"PUT",json:e});import{jsx as Ue,jsxs as Bo}from"react/jsx-runtime";var RR=_t(_r,zn,"\u5168\u90E8\u72B6\u6001");function _R(e,t,n){if(e.name==="sub"||e.name==="confirm-renew"){let o=t.find(r=>r.id===e.id);return o===void 0?{kind:"missing-sub"}:{kind:"sub",sub:o,confirm:e.name==="confirm-renew"}}if(e.name==="plan"||e.name==="confirm-buy"){let o=n.find(r=>r.id===e.id);return o===void 0?{kind:"missing-plan"}:{kind:"plan",plan:o,confirm:e.name==="confirm-buy"}}return{kind:"none"}}var PR=3;function AR({win:e,quotaPerUsd:t,width:n}){let o=Gc(e),r=Cd(e.durationMinutes),i=`\u5DF2\u7528 ${o}% ${ae.bullet} ${Te(e.used,t)} / ${Te(e.quota,t)}`;return Bo(Hn,{flexDirection:"column",children:[Bo(Ri,{wrap:"truncate",children:[Ue(Ri,{color:f.foreground,children:r}),Ue(Ri,{color:o>=100?f.danger:f.mutedForeground,children:Kn(i,Math.max(0,n-CR(r)))})]}),Ue(hg,{used:e.used,total:e.quota,width:n}),Ue(Ri,{wrap:"truncate",color:f.faintForeground,children:`\u5C06\u4E8E ${K(e.resetAt)} \u91CD\u7F6E`})]})}function ER(e){if(e.revokedAt!==null)return`${K(e.revokedAt)} \u4F5C\u5E9F`;let t=`${K(e.expiresAt)} \u5230\u671F`;return`\u5DF2\u7528 ${Math.max(...e.windows.map(Gc))}% \xB7 ${t}`}function MR(e){let t=e.windows.length*4;return X+Xe+2+t+(e.renewable?X+1:0)}function IR(e){let t=e.description!==null&&e.description!==""?1+qe:0,n=Math.ceil((1+e.windows.length)/2);return X+Xe+t+n+X+1}function Yb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=vR({name:"menu"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,run:u}=ue();Re(a!==null);let m=Q([e.revision],async()=>{let[g,x,T,k]=await Promise.all([qb(),Gb(),Vb(),Ge(e.ctx.site)]);return{mine:g,plans:x,orders:T,site:k}});G(g=>{o.name!=="menu"||a!==null||(g==="r"?e.reload():g==="f"&&r({name:"filter"}))});let p=()=>{l(),o.name==="menu"?e.pop():o.name==="confirm-renew"?r({name:"sub",id:o.id}):o.name==="confirm-buy"?r({name:"plan",id:o.id}):r({name:"menu"})},d=g=>{u("\u6B63\u5728\u4FDD\u5B58\u504F\u597D",()=>Kb({billingPreference:g}),{onSuccess:()=>{r({name:"menu"}),e.reload(),e.toast("ok","\u504F\u597D\u5DF2\u4FDD\u5B58")}})},b=(g,x)=>{u("\u6B63\u5728\u521B\u5EFA\u7EED\u8D39\u8BA2\u5355",()=>Wb(g.id),{onSuccess:({order:T,qrCode:k})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...T},k,x.quotaPerUsd))}})},h=(g,x)=>{u("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>zb({planId:g.id}),{onSuccess:({order:T,qrCode:k})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...T},k,x.quotaPerUsd))}})};return Ue(Y,{hints:o.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","f \u7B5B\u9009\u8BA2\u5355","r \u5237\u65B0"]:o.name==="sub"||o.name==="plan"?["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C","Esc \u8FD4\u56DE"]:["Esc \u8FD4\u56DE"],onEscape:p,isActive:a===null,children:Ue(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u9605",width:t,children:({mine:g,plans:x,orders:T,site:k})=>{if(o.name==="preference")return Ue(te,{title:"\u6263\u8D39\u65B9\u5F0F",width:t,submitLabel:"\u4FDD\u5B58",busy:a!==null,busyLabel:a??"\u6B63\u5728\u4FDD\u5B58",error:c,fields:[{kind:"select",name:"billingPreference",label:"\u6263\u8D39\u65B9\u5F0F",options:bd,initial:g.billingPreference,hint:Uc}],onCancel:p,onSubmit:v=>{d(v.billingPreference??g.billingPreference)}});if(o.name==="filter")return Ue(te,{title:"\u7B5B\u9009\u8BA2\u9605\u8BA2\u5355",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:RR,initial:i}],onCancel:p,onSubmit:v=>{s(v.status??""),r({name:"menu"})}});let S=_R(o,g.subscriptions,x);if(S.kind==="missing-sub")return Ue(ye,{tone:"warn",width:t,title:"\u8BA2\u9605\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664",detail:"\u6309 Esc \u8FD4\u56DE"});if(S.kind==="missing-plan")return Ue(ye,{tone:"warn",width:t,title:"\u5957\u9910\u4E0D\u5B58\u5728\u6216\u5DF2\u4E0B\u67B6",detail:"\u6309 Esc \u8FD4\u56DE"});if(S.kind==="sub"&&S.confirm)return Ue(Ae,{width:t,title:`\u786E\u8BA4\u7EED\u8D39\u300C${S.sub.planName}\u300D\uFF1F`,detail:"\u5C06\u6309\u5957\u9910\u5F53\u524D\u4EF7\u683C\u4E0E\u65F6\u957F\u5728\u5230\u671F\u65F6\u95F4\u4E0A\u987A\u5EF6",confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>b(S.sub,k),onCancel:p});if(S.kind==="plan"&&S.confirm)return Ue(Ae,{width:t,title:`\u786E\u8BA4\u8BA2\u9605\u300C${S.plan.name}\u300D\uFF08${Ce(S.plan.priceCny)} / ${S.plan.durationDays} \u5929\uFF09\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>h(S.plan,k),onCancel:p});let y=S.kind==="plan"?S.plan.description:"",R=i===""?T:T.filter(v=>v.status===i),N=[{heading:"\u6211\u7684\u8BA2\u9605"},...g.subscriptions.length===0?[{value:{kind:"none"},label:"\u6682\u65E0\u8BA2\u9605",hint:"\u8BA2\u9605\u4E0B\u65B9\u5957\u9910\u540E\uFF0C\u8986\u76D6\u8303\u56F4\u5185\u7684\u8C03\u7528\u5C06\u6309\u6263\u8D39\u65B9\u5F0F\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6",disabled:!0}]:g.subscriptions.map(v=>{let _=zc(v);return{value:{kind:"sub",id:v.id},label:v.planName,badge:_.label,badgeTone:ht(_),hint:ER(v)}}),{heading:""},{value:{kind:"preference"},label:"\u6263\u8D39\u65B9\u5F0F",badge:Fc(g.billingPreference),badgeTone:"accent",hint:Uc(g.billingPreference)},{heading:""},{heading:"\u53EF\u9009\u5957\u9910"},...x.length===0?[{value:{kind:"none"},label:"\u6682\u65E0\u53EF\u9009\u5957\u9910",hint:"\u8BA2\u9605\u5957\u9910\u4E0A\u67B6\u540E\u5C06\u663E\u793A\u5728\u8FD9\u91CC",disabled:!0}]:x.map(v=>({value:{kind:"plan",id:v.id},label:v.name,...v.enabled?{}:{badge:"\u5DF2\u505C\u552E",badgeTone:"warning"},hint:`${Ce(v.priceCny)} / ${v.durationDays} \u5929 \xB7 ${v.groups.map(Zi).join("\u3001")}`})),{heading:""},{heading:"\u8BA2\u9605\u8BA2\u5355"},...R.length===0?[{value:{kind:"none"},label:i===""?"\u6682\u65E0\u8BA2\u9605\u8BA2\u5355":"\u65E0\u5339\u914D\u7ED3\u679C",...i===""?{hint:"\u8BA2\u9605\u4E0A\u65B9\u5957\u9910\u540E\uFF0C\u8BA2\u5355\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}:{},disabled:!0}]:R.map(v=>({value:{kind:"order",orderNo:v.orderNo},label:`${v.planName}${v.renewal?"\uFF08\u7EED\u8D39\uFF09":""}`,...ja(v),hint:`${K(v.createdAt)} \xB7 ${Ce(v.amountCny)}`}))],E=S.kind==="sub"?MR(S.sub):S.kind==="plan"?IR(S.plan):0,W=E===0?n:n-E>=PR?n-E:0,M=t-ge,C=o.name==="menu"&&a===null;return Bo(Hn,{flexDirection:"column",children:[W>0&&Ue(le,{items:N,width:t,height:W,isActive:C,retain:"menu",onSelect:v=>{l(),v.kind==="preference"?r({name:"preference"}):v.kind==="order"?e.push("order",{kind:"subscription",orderNo:v.orderNo}):v.kind==="sub"?r({name:"sub",id:v.id}):v.kind==="plan"&&r({name:"plan",id:v.id})}}),S.kind==="sub"&&Bo(Hn,{marginTop:W>0?X:0,flexDirection:"column",children:[Bo(pe,{title:S.sub.planName,note:S.sub.revokedAt!==null?`${K(S.sub.revokedAt)} \u4F5C\u5E9F`:`${K(S.sub.expiresAt)} \u5230\u671F`,width:t,children:[Ue(Ve,{width:M,items:[["\u72B6\u6001",zc(S.sub).label],["\u8986\u76D6\u5206\u7EC4",S.sub.groups.map(Zi).join("\u3001")],["\u751F\u6548\u65F6\u95F4",K(S.sub.startsAt)]]}),Ue(Hn,{marginTop:1,flexDirection:"column",children:S.sub.windows.map((v,_)=>Ue(Hn,{marginTop:_===0?0:1,flexDirection:"column",children:Ue(AR,{win:v,quotaPerUsd:k.quotaPerUsd,width:M})},v.windowId))})]}),S.sub.renewable&&a===null&&Ue(Hn,{marginTop:X,children:Ue(le,{width:t,items:[{value:"renew",label:"\u7EED\u8D39"}],onSelect:()=>r({name:"confirm-renew",id:S.sub.id})})})]}),S.kind==="plan"&&Bo(Hn,{marginTop:W>0?X:0,flexDirection:"column",children:[Bo(pe,{title:S.plan.name,note:`${Ce(S.plan.priceCny)} / ${S.plan.durationDays} \u5929`,width:t,children:[y!==""&&Ue(Ri,{wrap:"truncate",color:f.mutedForeground,children:y}),Ue(Hn,{marginTop:y===""?0:qe,children:Ue(Ve,{width:M,items:[["\u8986\u76D6\u5206\u7EC4",S.plan.groups.map(Zi).join("\u3001")],...Rd(S.plan,k.quotaPerUsd).map((v,_)=>[_===0?"\u7528\u91CF\u7A97\u53E3":"",v])]})})]}),a===null&&Ue(Hn,{marginTop:X,children:Ue(le,{width:t,items:[{value:"subscribe",label:S.plan.enabled?"\u8BA2\u9605":"\u5DF2\u505C\u552E",disabled:!S.plan.enabled}],onSelect:()=>r({name:"confirm-buy",id:S.plan.id})})})]})]})}})})}import{jsx as be}from"react/jsx-runtime";var Jb={home:{render:()=>be(Yy,{})},help:{render:()=>be(Wy,{})},login:{render:()=>be(zg,{})},register:{render:()=>be(Wg,{})},forgot:{render:()=>be(jg,{})},agreement:{render:e=>be(Og,{params:e})},tokens:{render:()=>be(My,{})},logs:{render:()=>be($h,{})},usage:{render:()=>be(Eh,{})},ledger:{render:()=>be(wb,{})},subscription:{render:()=>be(Yb,{})},models:{render:()=>be(Gh,{})},docs:{render:()=>be(By,{})},doc:{render:e=>be(jy,{params:e})},recharge:{render:()=>be(jb,{})},order:{render:e=>be(Ab,{params:e})},pay:{render:e=>be($b,{params:e})},invoices:{render:()=>be(xb,{})},"invoice-apply":{render:()=>be(fb,{})},"invoice-profiles":{render:()=>be(bb,{})},invite:{render:()=>be(eb,{})},tickets:{render:()=>be(Lg,{})},ticket:{render:e=>be(Ng,{params:e})},community:{render:()=>be(mh,{})},post:{render:e=>be(Sh,{params:e})},floor:{render:e=>be(oh,{params:e})},compose:{render:e=>be(Jg,{params:e})},"post-edit":{render:e=>be(Xg,{params:e})},homepage:{render:e=>be(sh,{params:e})},inbox:{render:()=>be(Jy,{})},announcements:{render:()=>be(Qp,{})},"announce-gate":{render:e=>be(Yp,{params:e}),lockNav:!0},profile:{render:()=>be(wg,{})},"my-posts":{render:e=>be(ph,{params:e})},"my-comments":{render:e=>be(fh,{params:e})},bookmarks:{render:()=>be(gh,{})},drafts:{render:()=>be(hh,{})}};function Xb(e){return Jb[e].lockNav===!0}function Qb(e){let t=Jb[e.id].render;return t(e.params)}import{jsx as oo,jsxs as zR}from"react/jsx-runtime";function $R(){let e=O(),{rows:t}=j(),n=us(),o=Xb(e.current.id)||n,r=e.depth===1&&fs(e.current.id)&&Lt().session===null;return wm(()=>{r&&e.home()}),OR((i,s)=>{s.ctrl&&i==="c"&&e.exit()}),G(i=>{if(i==="?"){e.current.id==="help"?e.pop():o||e.push("help");return}i==="q"&&!o&&(e.depth>1?e.pop():e.exit())}),oo(NR,{flexDirection:"column",height:Math.max(1,t),paddingX:1,paddingTop:1,overflow:"hidden",children:Qb(e.current)})}function BR(){let e=O(),t=Q([e.revision],async()=>{if(e.gate.announcementsChecked||Lt().session===null)return null;let n;try{n=await Gd()}catch{return null}return e.gate.announcementsChecked=!0,n});return wm(()=>{t.phase!=="ready"||t.data===null||e.gate.announcementsShown||(e.gate.announcementsShown=!0,e.push("announce-gate",{item:t.data}))}),null}function FR(){let e=O(),t=DR(!1);return wm(()=>{t.current||(t.current=!0,Hd().then(n=>{n!==null&&e.toast("ok",`\u5DF2\u66F4\u65B0\u5230 v${n}\uFF0C\u91CD\u542F\u540E\u751F\u6548`)}).catch(n=>e.toast("fail",`\u81EA\u52A8\u66F4\u65B0\u5931\u8D25\uFF1A${xe(n)}`)))}),null}function UR({ctx:e,mouse:t}){return oo(ap,{subscribe:t.subscribe,children:oo(Xd,{children:oo(dp,{ctx:e,children:zR(zp,{children:[oo(FR,{}),oo(BR,{}),oo($R,{})]})})})})}var jR="\x1B[2J\x1B[3J\x1B[H",HR="\x1B[H\x1B[J",qR="\x1B[3J";function GR(e){return new Proxy(e,{get(t,n){if(n!=="write"){let o=Reflect.get(t,n,t);return typeof o=="function"?o.bind(t):o}return(...o)=>{let[r,...i]=o;if(typeof r!="string")return t.write(r,...i);let s=r.split(jR).join(HR).split(qR).join("");return t.write(s,...i)}}})}async function Zb(e){let t=ip(process.stdin,process.stdout);try{await LR(oo(UR,{ctx:e,mouse:t}),{exitOnCtrlC:!0,alternateScreen:!0,stdin:t.stdin,stdout:GR(process.stdout)}).waitUntilExit()}finally{t.dispose()}}var YR=`${Wt} v${Vt} \u2014 CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF
25
+ `,i=o===""?[]:o.split(/\r?\n/);i.at(-1)===""&&i.pop();let s=new RegExp(`^\\s*(?:export\\s+)?${t}\\s*=`),a=i.findIndex(l=>s.test(l)),c=`${t}=${n}`;a===-1?i.push(c):i[a]=c,kn(e,`${i.join(r)}${r}`,384)}var dm="custom:",pm=e=>Ti(e.dir,"config.yaml"),uy=e=>Ti(e.dir,".env"),Bn=e=>typeof e=="string"?e:null;function dy(e,t){try{return aC(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 lC(e,t,n,o){let r=pm(t),i=cC(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&&!iC(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=`${dm}${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,{}]))}),sC(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=dy(a,r);if(Bn(c?.providers?.[n]?.api)!==e.baseUrl||Bn(c?.model?.provider)!==s||Bn(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`);kn(r,a,384)}var py={id:"hermes-agent",label:"Hermes Agent",requiresModel:!0,resolveDir(){let e=process.env.HERMES_HOME?.trim();if(e)return{dir:rC(e),custom:!0};if(process.platform==="win32"){let t=process.env.LOCALAPPDATA;return{dir:Ti(t??Ti(my(),"AppData","Local"),"hermes"),custom:!1}}return{dir:Ti(my(),".hermes"),custom:!1}},relayUrl:e=>e,configPaths:e=>[pm(e),uy(e)],read(e){let t=pm(e),n=Lt(t),o=n===null?null:dy(n,t),r=Bn(o?.model?.provider),i=r!==null&&r.startsWith(dm)?r.slice(dm.length):null,s=i===null?void 0:o?.providers?.[i];return{baseUrl:Bn(s?.api)??Bn(s?.url)??Bn(s?.base_url),model:Bn(o?.model?.default)??Bn(o?.model?.model)}},apply(e,t){let n=Tn(e.siteName),o=Ma(n);lC(e,t,n,o),Na(uy(t),o,e.apiKey)}};import{existsSync as mC}from"fs";import{homedir as hy}from"os";import{join as xr,resolve as yy}from"path";var uC="https://opencode.ai/config.json",by="opencode.jsonc",dC=[by,"opencode.json","config.json"],fy=["model"],fm=e=>dC.map(t=>xr(e.dir,t)).find(t=>mC(t))??xr(e.dir,by),gy=()=>{let e=process.env.XDG_DATA_HOME;return xr(e?yy(e):xr(hy(),".local","share"),"opencode","auth.json")},Sy={id:"opencode",label:"OpenCode",requiresModel:!0,resolveDir(){let e=process.env.XDG_CONFIG_HOME;return e?{dir:xr(yy(e),"opencode"),custom:!0}:{dir:xr(hy(),".config","opencode"),custom:!1}},relayUrl:e=>`${e}/v1`,configPaths:e=>[fm(e),gy()],read(e){let t=fm(e),n=$n(t,fy),o=n===null?null:Ia(n);if(o===null)return{baseUrl:null,model:null};let[r,i]=o;return{baseUrl:$n(t,["provider",r,"options","baseURL"]),model:i}},apply(e,t){let n=fm(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}]))}],[fy,`${o}/${e.model}`]];Aa(n,["$schema"])||r.unshift([["$schema"],uC]),Gt(n,r),Gt(gy(),[[[o],{type:"api",key:e.apiKey}]])}};import{homedir as pC}from"os";import{join as hm}from"path";var xy=["models","providers"],La=["agents","defaults","model"],Ty=["agents","defaults","models"],gm=e=>Sr("OPENCLAW_CONFIG_PATH")??hm(e.dir,"openclaw.json"),wy=e=>hm(e.dir,".env"),ky=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function fC(e){let t=no(e,La),n=ky(t)?t.primary:t;return typeof n=="string"?n:null}var vy={id:"openclaw",label:"OpenClaw",requiresModel:!0,resolveDir(){let e=Sr("OPENCLAW_STATE_DIR");if(e!==null)return{dir:e,custom:!0};let t=Sr("OPENCLAW_HOME");return{dir:hm(t??pC(),".openclaw"),custom:t!==null}},relayUrl:e=>e,configPaths:e=>[gm(e),wy(e)],read(e){let t=xi(gm(e)),n=t===null?null:fC(t),o=n===null?null:Ia(n);if(t===null||o===null)return{baseUrl:null,model:null};let[r,i]=o,s=no(t,[...xy,r,"baseUrl"]);return{baseUrl:typeof s=="string"?s:null,model:i}},apply(e,t){let n=gm(t),o=Tn(e.siteName),r=Ma(o),i=xi(n)??{},s=`${o}/${e.model}`,a=[[[...xy,o],{baseUrl:e.baseUrl,apiKey:{source:"env",provider:"default",id:r},api:"anthropic-messages",models:e.models.map(c=>({id:c,name:c}))}],ky(no(i,La))?[[...La,"primary"],s]:[La,{primary:s}]];for(let c of e.models){let l=`${o}/${c}`;no(i,[...Ty,l])===void 0&&a.push([[...Ty,l],{}])}Gt(n,a),Na(wy(t),r,e.apiKey)}};import{homedir as gC}from"os";import{join as bm}from"path";var ym=e=>bm(e.dir,"models.json"),Oa=e=>bm(e.dir,"settings.json"),Cy={id:"pi-coding-agent",label:"Pi Coding Agent",requiresModel:!0,resolveDir(){let e=Sr("PI_CODING_AGENT_DIR");return e!==null?{dir:e,custom:!0}:{dir:bm(gC(),".pi","agent"),custom:!1}},relayUrl:e=>e,configPaths:e=>[ym(e),Oa(e)],read(e){let t=$n(Oa(e),["defaultProvider"]);return{baseUrl:t===null?null:$n(ym(e),["providers",t,"baseUrl"]),model:$n(Oa(e),["defaultModel"])}},apply(e,t){let n=Tn(e.siteName);Gt(ym(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 Ry=[sy,ly,vy,py,Sy,Cy];var hC=6e3,yC=2,_y=e=>Jt(`${e.url}/api/site-config`,{timeoutMs:hC});async function bC(e){try{await _y(e);let t=Number.POSITIVE_INFINITY;for(let n=0;n<yC;n+=1){let o=Date.now();await _y(e),t=Math.min(t,Date.now()-o)}return{line:e,latencyMs:t}}catch{return{line:e,latencyMs:null}}}async function Py(e){let t=[];for(let n of e)t.push(await bC(n));return t}import{jsx as De,jsxs as $a}from"react/jsx-runtime";var xC=10,TC=3,Ay=4,Ny=e=>1+Math.max(1,Math.min(e,Ay))+(e>Ay?1:0);function Ey(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 My=e=>e.map(t=>({value:String(t.id),label:`${t.name} \xD7${t.multiplier}`})),Iy=(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 wC({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(pe,{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(de,{retain:"lines",items:e,width:o-ge,height:Ny(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 Ly(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Da({name:"list"}),[i,s]=Da(!1),[a,c]=Da(()=>fo().line),[l,u]=Da(0),{busy:m,error:p,reset:d,fail:b,run:h}=ue();Re(m!==null||o.name==="created"||o.name==="apply-pick"||o.name==="apply-model");let g=Q([e.revision],async()=>{let[P,B,J]=await Promise.all([va(),ka(),Be(e.ctx.site)]);return{tokens:P,groups:B,site:J}}),x=g.phase==="ready"?g.data.site.apiLines:[],T=Q([l,x.map(P=>P.url).join("|")],()=>Py(x)),k=m!==null,S=o.name==="list"&&!k,y=P=>{r({name:"list"}),e.reload(),e.toast("ok",P)};G(P=>{if(P==="r"){u(B=>B+1),e.reload();return}i||(P==="n"?r({name:"create"}):P==="l"&&x.length>0&&s(!0))},S);let R=P=>{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`)},N=(P,B,J)=>{h("\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",()=>Lh({name:P,groupId:B,quotaLimit:J}),{onSuccess:oe=>{e.reload(),r({name:"created",token:oe,secret:oe.token})}})},E=P=>{h("\u6B63\u5728\u5220\u9664\u4EE4\u724C",()=>Oh(P.id),{onSuccess:()=>y("\u4EE4\u724C\u5DF2\u5220\u9664")})},W=(P,B)=>{h("\u6B63\u5728\u8BFB\u53D6\u5BA2\u6237\u7AEF\u914D\u7F6E",async()=>Ry.map(J=>{let oe=J.resolveDir(),fe=J.read(oe);return{client:J,configured:fe.baseUrl!==null,paths:J.configPaths(oe),model:fe.model}}),{failToast:!0,onSuccess:J=>r({name:"apply-pick",token:P,secret:B,targets:J})})},M=(P,B,J)=>{h("\u6B63\u5728\u5199\u5165",J,{failToast:!0,onSuccess:()=>{r({name:"list"}),e.toast("ok",_e([`\u5DF2\u5199\u5165 ${P}`,B]))}})},C=(P,B)=>{let J=P.targets.find(fe=>fe.client.id===B);if(J===void 0)return;let{client:oe}=J;if(!oe.requiresModel){M(oe.label,void 0,()=>Xh(e.ctx,oe,P.secret));return}h("\u6B63\u5728\u8BFB\u53D6\u53EF\u8DEF\u7531\u7684\u6A21\u578B",async()=>{let fe=await Yh(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})})},v=(P,B)=>{d(),r(P==="rename"?{name:"rename",token:B}:P==="regroup"?{name:"regroup",token:B}:P==="relimit"?{name:"relimit",token:B}:{name:"confirm-delete",token:B})},_=()=>{if(o.name==="list"){i?s(!1):e.pop();return}if(d(),o.name==="apply-pick"){r({name:"created",token:o.token,secret:o.secret});return}if(o.name==="apply-model"){r({name:"apply-pick",token:o.token,secret:o.secret,targets:o.targets});return}r({name:"list"})},L=()=>o.name!=="list"?["Esc \u8FD4\u56DE"]:i?["\u2191\u2193 \u79FB\u52A8","Enter \u9009\u7528","/ \u8FC7\u6EE4","r \u5237\u65B0","Esc \u8FD4\u56DE"]:["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","n \u65B0\u5EFA","l \u63A5\u5165\u5730\u5740","/ \u8FC7\u6EE4","r \u5237\u65B0"];return o.name==="created"||o.name==="apply-pick"||o.name==="apply-model"?De(Y,{hints:L(),onEscape:_,isActive:m===null,children:$a(Io,{flexDirection:"column",children:[m!==null&&De(Oe,{label:m}),o.name==="created"&&!k&&$a(Io,{flexDirection:"column",children:[De(ye,{tone:"ok",width:t,title:"\u4EE4\u724C\u5DF2\u521B\u5EFA",detail:"\u8BF7\u7ACB\u5373\u590D\u5236\u5E76\u59A5\u5584\u4FDD\u5B58\u3002\u51FA\u4E8E\u5B89\u5168\u8003\u8651\uFF0C\u5B8C\u6574\u4EE4\u724C\u53EA\u663E\u793A\u8FD9\u4E00\u6B21\uFF0C\u5173\u95ED\u540E\u5C06\u65E0\u6CD5\u518D\u6B21\u67E5\u770B\u3002"}),De(Io,{marginTop:1,children:De(SC,{color:f.accent,children:o.secret})}),De(Io,{marginTop:1,children:De(le,{width:t,items:[{value:"apply",label:"\u5199\u5165\u914D\u7F6E"},{value:"back",label:"\u6211\u5DF2\u4FDD\u5B58"}],onSelect:P=>{P==="back"?r({name:"list"}):W(o.token,o.secret)}})})]}),o.name==="apply-pick"&&!k&&De(pe,{title:"\u5199\u5165\u914D\u7F6E",note:o.token.name,width:t,children:De(le,{width:t-ge,height:n-Xe,retain:"apply",items:o.targets.map(P=>({value:P.client.id,label:P.client.label,badge:P.configured?"\u5DF2\u914D\u7F6E":"\u672A\u914D\u7F6E",badgeTone:P.configured?"accent":void 0,hint:P.paths.join(" ")})),onSelect:P=>C(o,P)})}),o.name==="apply-model"&&!k&&De(te,{title:`${o.needs.client.label} \u9ED8\u8BA4\u6A21\u578B`,width:t,submitLabel:"\u5199\u5165",error:p,fields:[{kind:"select",name:"model",label:"\u6A21\u578B",options:o.models.map(P=>({value:P,label:P})),initial:o.needs.model!==null&&o.models.includes(o.needs.model)?o.needs.model:o.models[0],hint:`\u5199\u5165\u540E\u4F5C\u4E3A ${o.needs.client.label} \u7684\u9ED8\u8BA4\u6A21\u578B`}],onCancel:_,onSubmit:P=>{let B=P.model;if(B===void 0||B===""){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u6A21\u578B");return}M(o.needs.client.label,B,()=>Qh(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+Ny(J.apiLines.length),fe=Math.max(TC,n-(o.name==="list"?oe:xC));return $a(Io,{flexDirection:"column",children:[De(Io,{flexDirection:"column",marginBottom:X,children:De(de,{retain:"list",items:P,width:t,height:fe,isActive:S&&!i,columns:[{label:"\u540D\u79F0",shrink:!0},{label:"\u5206\u7EC4"},{label:"\u5DF2\u6D88\u8D39",align:"right"},{label:"\u8D39\u7528\u9650\u5236",align:"right"},{label:"\u5BC6\u94A5"}],row:$=>{let ne=Te($.usedQuota,J.quotaPerUsd);return[$.name,$.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664",$.quotaLimit!==null&&$.usedQuota>=$.quotaLimit?{text:ne,tone:"danger"}:ne,$.quotaLimit===null?"\u4E0D\u9650":Te($.quotaLimit,J.quotaPerUsd),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(wC,{lines:J.apiLines,measured:T.phase==="ready"?T.data:null,pick:sm(a,J.apiLines),width:t,isActive:S&&i,onPick:R}),o.name==="actions"&&!k&&$a(pe,{title:o.token.name,width:t,children:[De(Ve,{width:t-ge,items:[["\u5206\u7EC4",o.token.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664"],["\u5DF2\u6D88\u8D39",Te(o.token.usedQuota,J.quotaPerUsd)],["\u8D39\u7528\u9650\u5236",o.token.quotaLimit===null?"\u4E0D\u9650":Te(o.token.quotaLimit,J.quotaPerUsd)],["\u5BC6\u94A5",Fi(o.token.keyPrefix,o.token.keySuffix)]]}),De(Io,{marginTop:1,children:De(le,{width:t-ge,items:[{value:"rename",label:"\u540D\u79F0",hint:o.token.name},{value:"regroup",label:"\u5206\u7EC4",hint:o.token.groupName??"\u5206\u7EC4\u5DF2\u5220\u9664"},{value:"relimit",label:"\u8D39\u7528\u9650\u5236",hint:o.token.quotaLimit===null?"\u4E0D\u9650":Te(o.token.quotaLimit,J.quotaPerUsd)},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:$=>v($,o.token)})})]}),o.name==="create"&&De(te,{title:"\u521B\u5EFA\u4EE4\u724C",width:t,submitLabel:"\u521B\u5EFA",error:p,busy:k,busyLabel:"\u6B63\u5728\u521B\u5EFA\u4EE4\u724C",fields:[{kind:"text",name:"name",label:"\u540D\u79F0",placeholder:"\u8BF7\u8F93\u5165\u4EE4\u724C\u540D\u79F0"},{kind:"select",name:"group",label:"\u5206\u7EC4",options:My(B),initial:String(B[0]?.id??""),hint:$=>Iy(B,$)},{kind:"text",name:"limit",label:"\u8D39\u7528\u9650\u5236",placeholder:"\u7F8E\u5143\u91D1\u989D\uFF0C\u7559\u7A7A\u5219\u4E0D\u9650\u5236",hint:"\u7D2F\u8BA1\u6D88\u8D39\u8FBE\u5230\u8D39\u7528\u4E0A\u9650\u540E\uFF0C\u8BE5\u4EE4\u724C\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD",optional:!0}],onCancel:_,onSubmit:$=>{let ne=($.name??"").trim();if(ne===""){b("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}let w=B.find(re=>String(re.id)===$.group);if(w===void 0){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}let U=Ey($.limit??"",J.quotaPerUsd);if(U==="invalid"){b("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}N(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:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"text",name:"name",label:"\u540D\u79F0",initial:o.token.name,placeholder:"\u8BF7\u8F93\u5165\u4EE4\u724C\u540D\u79F0"}],onCancel:_,onSubmit:$=>{let ne=($.name??"").trim();if(ne===""){b("\u8BF7\u586B\u5199\u4EE4\u724C\u540D\u79F0");return}h("\u6B63\u5728\u4FDD\u5B58",()=>Ca(o.token.id,{name:ne}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="regroup"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"select",name:"group",label:"\u5206\u7EC4",options:My(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":$=>Iy(B,$)}],onCancel:_,onSubmit:$=>{let ne=B.find(w=>String(w.id)===$.group);if(ne===void 0){b("\u8BF7\u9009\u62E9\u4E00\u4E2A\u5206\u7EC4");return}h("\u6B63\u5728\u4FDD\u5B58",()=>Ca(o.token.id,{groupId:ne.id}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="relimit"&&De(te,{title:`\u7F16\u8F91\u4EE4\u724C \u2014 ${o.token.name}`,width:t,submitLabel:"\u4FDD\u5B58",error:p,busy:k,busyLabel:"\u6B63\u5728\u4FDD\u5B58",fields:[{kind:"text",name:"limit",label:"\u8D39\u7528\u9650\u5236",initial:o.token.quotaLimit===null?"":String(Math.round(o.token.quotaLimit/J.quotaPerUsd*100)/100),placeholder:"\u7F8E\u5143\u91D1\u989D\uFF0C\u7559\u7A7A\u5219\u4E0D\u9650\u5236",hint:`\u8BE5\u4EE4\u724C\u5DF2\u7D2F\u8BA1\u6D88\u8D39 ${Te(o.token.usedQuota,J.quotaPerUsd)}\uFF0C\u8FBE\u5230\u8D39\u7528\u4E0A\u9650\u540E\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD`,optional:!0}],onCancel:_,onSubmit:$=>{let ne=Ey($.limit??"",J.quotaPerUsd);if(ne==="invalid"){b("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u8D39\u7528\u9650\u5236");return}h("\u6B63\u5728\u4FDD\u5B58",()=>Ca(o.token.id,{quotaLimit:ne}),{onSuccess:()=>y("\u5DF2\u4FDD\u5B58")})}}),o.name==="confirm-delete"&&!k&&De(Ae,{width:t,title:"\u5220\u9664\u4EE4\u724C",detail:`\u5220\u9664\u300C${o.token.name}\u300D\u540E\u8BE5\u4EE4\u724C\u7ACB\u5373\u5931\u6548\uFF0C\u4F7F\u7528\u5B83\u7684\u8C03\u7528\u5C06\u88AB\u62D2\u7EDD`,confirmLabel:"\u5220\u9664",error:p,onConfirm:()=>E(o.token),onCancel:_})]})}})})}import{Box as $y,Text as vC}from"ink";import{useEffect as CC,useState as Uy}from"react";import RC from"string-width";import{z as kC}from"zod";var Ba=()=>A(vu,"/docs/manifest"),Oy=e=>A(Cu,`/docs/pages/${e}`),Dy=e=>A(kC.array(Ru),Ue("/docs/search",{q:e}));import{jsx as Fn,jsxs as Fy}from"react/jsx-runtime";var _C=250,By="/ ";function PC(e,t){let[n,o]=Uy(e);return CC(()=>{let r=setTimeout(()=>o(e),t);return()=>clearTimeout(r)},[e,t]),n}var AC=e=>e.groups.flatMap((t,n)=>[...n===0?[]:[{heading:""}],{heading:t.title},...t.items.map(o=>({value:o,label:o.title}))]);function jy(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Me("query",()=>""),[i,s]=Uy(!1),a=PC(o.trim(),_C),c=a.length>bc,l=Q([e.revision],Ba),u=qt(Q([a,e.revision],()=>a===""||c?Promise.resolve(null):Dy(a))),m=l.phase==="ready",p=o.trim()!=="",d=i||p;G(T=>{if(T==="r"){e.reload();return}m&&T.startsWith("/")&&(s(!0),T.length>1&&r(T.slice(1)))},!i);let b=()=>{if(!d){e.pop();return}s(!1),r("")},h=i?["Enter \u786E\u8BA4","Esc \u53D6\u6D88"]:m?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","/ \u641C\u7D22","r \u5237\u65B0",...p?["Esc \u8FD4\u56DE"]:[]]:["r \u5237\u65B0"],g=(T,k)=>e.push("doc",{slug:T,anchor:k}),x=Math.max(3,n-(d?1:0));return Fn(Y,{hints:h,onEscape:b,children:Fn(V,{state:l,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863\u76EE\u5F55",width:t,children:T=>Fy($y,{flexDirection:"column",children:[d&&Fy($y,{children:[Fn(vC,{color:f.accent,children:By}),Fn(er,{value:o,onChange:r,onSubmit:()=>s(!1),isActive:i,placeholder:"\u641C\u7D22\u6587\u6863",width:t-RC(By)})]}),p?c?Fn(Ft,{message:`\u5173\u952E\u8BCD\u6700\u591A ${bc} \u4E2A\u5B57\u7B26`,width:t}):Fn(V,{state:u,loading:"\u6B63\u5728\u641C\u7D22",width:t,children:k=>k===null?Fn(Oe,{label:"\u6B63\u5728\u641C\u7D22"}):Fn(de,{retain:"results",items:k,width:t,height:x,isActive:!i,columns:[{label:"\u6807\u9898"},{label:"\u6458\u8981",shrink:!0}],row:S=>[S.title,S.snippet],onOpen:S=>g(S.slug,S.anchor),emptyLabel:"\u65E0\u5339\u914D\u7ED3\u679C"})}):Fn(le,{retain:"toc",items:AC(T),width:t,height:x,isActive:!i,onSelect:k=>g(k.slug,null)})]})})})}import{Box as OC,Text as DC}from"ink";import{useMemo as $C,useState as BC}from"react";import{spawn as EC}from"child_process";var MC={darwin:[{command:"pbcopy",args:[]}],win32:[{command:"clip",args:[]}],linux:[{command:"wl-copy",args:[]},{command:"xclip",args:["-selection","clipboard"]},{command:"xsel",args:["--clipboard","--input"]}]};function IC(e,t){return new Promise((n,o)=>{let r=EC(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=MC[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 IC(n,e))return;throw new F("\u672A\u627E\u5230\u53EF\u7528\u7684\u526A\u8D34\u677F\u547D\u4EE4")}import{Lexer as NC,walkTokens as LC}from"marked";function Hy(e,t){let n=[],o=[],r=new Set,i="";for(let s of NC.lex(e,{gfm:!0,breaks:!1}))s.type==="heading"&&(i=ll(s.tokens,"docs")),LC([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 qy=e=>Vn(e).split(`
26
+ `).map(t=>t.trim()).filter(t=>t!=="").join(" ");import{jsx as No,jsxs as HC}from"react/jsx-runtime";var FC=1,UC=16;function Gy({params:e}){let{depth:t}=O();return No(jC,{params:e},t)}function jC({params:e}){let t=O(),{width:n}=j(),o=Z(),[r,i]=BC("body"),s=qt(Q([e.slug,t.revision],async()=>{let[h,g]=await Promise.all([Oy(e.slug),Ba()]),x=new Map(g.groups.flatMap(T=>T.items.map(k=>[k.slug,k.title])));return{page:h,titles:x,outline:Hy(h.markdown,e.slug)}})),a=s.phase==="ready"?s.data:null,c=a===null?null:a.page.markdown,l=$C(()=>c===null?[]:hn(c,n,"docs"),[c,n]);G(h=>{if(r!=="body")return;if(h==="r"){t.reload();return}if(a===null)return;let{outline:g}=a;h==="l"&&g.links.length>0?i("links"):h==="c"&&g.codes.length>0&&i("codes")});let u=()=>{r==="body"?t.pop():i("body")},m=h=>{i("body"),Fa(h).then(()=>t.toast("ok","\u5DF2\u590D\u5236"),()=>t.toast("fail","\u590D\u5236\u5931\u8D25\uFF0C\u53EF\u7528 Option / Alt \u62D6\u9009\u590D\u5236"))},p=()=>{if(a===null)return["r \u5237\u65B0"];if(r==="links")return["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00\u6216\u590D\u5236"];if(r==="codes")return["\u2191\u2193 \u79FB\u52A8","Enter \u590D\u5236"];let{outline:h}=a;return["\u2191\u2193 \u6EDA\u52A8",...h.links.length>0?["l \u94FE\u63A5"]:[],...h.codes.length>0?["c \u590D\u5236\u4EE3\u7801"]:[],"r \u5237\u65B0"]},d=a===null?"\u6587\u6863\u8BE6\u60C5":a.page.title;return No(Y,{trail:r==="links"?["\u4F7F\u7528\u6587\u6863",d,"\u94FE\u63A5"]:r==="codes"?["\u4F7F\u7528\u6587\u6863",d,"\u4EE3\u7801"]:["\u4F7F\u7528\u6587\u6863",d],hints:p(),onEscape:u,children:No(V,{state:s,loading:"\u6B63\u5728\u8BFB\u53D6\u6587\u6863",width:n,children:({titles:h,outline:g})=>{if(r==="links")return No(de,{retain:"links",items:g.links,width:n,height:o,columns:[{label:"\u94FE\u63A5",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u76EE\u6807",shrink:!0}],row:T=>T.kind==="guide"?[T.text,"\u7AD9\u5185\u6587\u6863",h.get(T.slug)??""]:[T.text,"\u5916\u90E8\u94FE\u63A5",T.href],onOpen:T=>T.kind==="guide"?t.push("doc",{slug:T.slug,anchor:T.anchor}):m(T.href)});if(r==="codes")return No(de,{retain:"codes",items:g.codes,width:n,height:o,columns:[{label:"\u4EE3\u7801",shrink:!0},{label:"\u8BED\u8A00"},{label:"\u7AE0\u8282",cap:UC}],row:T=>[qy(T.text),T.lang,T.section],onOpen:T=>m(T.text)});let x=e.anchor===null?-1:l.findIndex(T=>T.anchor===e.anchor);return HC(OC,{flexDirection:"column",children:[No(pt,{retain:"body",lines:l,height:Math.max(1,o-FC),start:Math.max(0,x)}),No(DC,{wrap:"truncate",color:f.faintForeground,children:`\u7F51\u9875\u7248 ${t.ctx.site}/docs/${e.slug}`})]})}})})}import{Box as Sm}from"ink";import{jsx as un,jsxs as qC}from"react/jsx-runtime";var zy=[["\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"]],Wy=[["\u70B9\u51FB / \u6EDA\u8F6E","\u9009\u4E2D\u6253\u5F00\u3001\u6EDA\u52A8"],["Option / Alt \u62D6\u9009","\u590D\u5236\u6587\u672C"]],Vy=[["\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 Ky({width:e,height:t}){let n=e-ge,o=[["\u7248\u672C",`${Wt} v${Vt}`],["\u672C\u5730\u5B58\u50A8",vn()]],r=[zy,Wy,Vy,o],s=(a=>r.reduce((c,l)=>c+Bt+a+Js(l.length,n),X*(r.length-1)))(Ge)<=t?Ge:0;return qC(Xd,{height:t,children:[un(pe,{title:"\u901A\u7528",width:e,gap:s,children:un(Ve,{items:zy,width:n})}),un(Sm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u9F20\u6807",width:e,gap:s,children:un(Ve,{items:Wy,width:n})})}),un(Sm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u6587\u672C\u8F93\u5165",width:e,gap:s,children:un(Ve,{items:Vy,width:n})})}),un(Sm,{marginTop:X,flexDirection:"column",children:un(pe,{title:"\u5173\u4E8E",width:e,gap:s,children:un(Ve,{items:o,width:n})})})]})}import{jsx as xm}from"react/jsx-runtime";function Yy(){let e=O(),{width:t}=j(),n=Z();return gn(e.pop),xm(So,{header:xm(Os,{trail:["CodeFlow","\u952E\u4F4D\u5E2E\u52A9"],width:t,onBack:e.pop,isActive:!0}),hints:["Esc \u8FD4\u56DE"],children:xm(Ky,{width:t,height:n})})}import{Box as Jy,Text as GC}from"ink";import{jsx as wi,jsxs as zC}from"react/jsx-runtime";var Xy=[{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 Qy(){let e=O(),{width:t}=j(),n=ri(0),o=X+1+X+Xy.length,r=Is(t)&&n-Ms>=o;return zC(So,{header:r?wi(Ns,{width:t}):null,hints:["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","? \u5E2E\u52A9","q \u9000\u51FA"],children:[wi(Jy,{marginTop:1,children:wi(GC,{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(Jy,{marginTop:1,children:wi(le,{items:Xy,width:t,retain:"menu",onSelect:i=>e.push(i)})})]})}import{Box as Tm,Text as wm}from"ink";import{useState as WC}from"react";import{jsx as nn,jsxs as km}from"react/jsx-runtime";function Zy(){let e=O(),t=Ds(),{width:n}=j(),o=Z(),{busy:r,run:i}=ue(),[s,a]=WC({name:"list"}),c=ze([e.revision],m=>Hp({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",()=>Gp(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",()=>zp(),{failToast:!0,onSuccess:()=>{e.reload(),e.toast("ok","\u5DF2\u5168\u90E8\u6807\u4E3A\u5DF2\u8BFB")}}))}),s.name==="detail"){let m=jc(s.message),p=gd[m.target.kind],d=At([{text:st(m.body),color:f.foreground}],n),b=Math.max(3,o-4);return km(Y,{hints:[...d.length>b?["\u2191\u2193 \u6EDA\u52A8"]:[],`Enter ${p}`,"Esc \u8FD4\u56DE"],onEscape:()=>a({name:"list"}),children:[km(wm,{wrap:"truncate",children:[nn(wm,{bold:!0,color:f.foreground,children:st(m.title)}),nn(wm,{color:f.faintForeground,children:` ${K(s.message.createdAt)}`})]}),nn(Tm,{marginTop:1,children:nn(pt,{lines:d,height:Math.min(d.length,b)})}),nn(Tm,{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=>km(Tm,{flexDirection:"column",children:[nn(de,{retain:"list",items:m.items,width:n,height:Math.max(3,o-1),isActive:r===null,columns:[{label:"\u6D88\u606F",shrink:!0},{label:"\u5185\u5BB9",shrink:!0},{label:"\u65F6\u95F4"},{label:"\u72B6\u6001",align:"right"}],row:p=>{let d=jc(p),b=st(d.title);return[p.read?b:{text:b,tone:"accent"},st(d.body),K(p.createdAt),p.read?"":{text:"\u672A\u8BFB",tone:"accent"}]},onOpen:u,emptyLabel:"\u6682\u65E0\u6D88\u606F",emptyDescription:"\u6709\u65B0\u6D88\u606F\u65F6\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}),r!==null?nn(Oe,{label:r}):nn(We,{page:c.page,pages:c.pages,total:c.total,width:n})]})})})}import{Box as Ua,Text as Lo}from"ink";import{useState as tb}from"react";import{z as xt}from"zod";var VC=xt.object({inviteCode:xt.string(),invitedCount:xt.number(),totalReward:xt.number(),rewards:xt.object({firstInviterPercent:xt.number(),firstInviteePercent:xt.number(),subsequentInviterPercent:xt.number()}),items:xt.array(xt.object({id:xt.number().int(),rewardType:Wm,rewardQuota:xt.number(),rewardQuotaReversed:xt.number(),inviterUsername:xt.string(),inviteeUsername:xt.string(),createdAt:xt.string()}))}),eb=()=>A(VC,"/invite");import{jsx as _t,jsxs as ja}from"react/jsx-runtime";var KC=Pt(nc,es,"\u5168\u90E8\u7C7B\u578B"),nb=3;function YC(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 ob(){let e=O(),{width:t}=j(),n=Z(),[o,r]=tb("main"),[i,s]=tb(""),a=Q([e.revision],async()=>{let[l,u]=await Promise.all([eb(),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:KC,initial:i}],onCancel:c,onSubmit:x=>{s(x.type??""),r("main")}});let m=t-ge,p=YC(l.rewards),d=i===""?l.items:l.items.filter(x=>x.rewardType===i),b=x=>Ut(2,t)+X+Bt+x+2+X+Bt+x+p.length+X+Bt+x,h=n-b(Ge)>=nb?Ge:0,g=Math.max(nb,n-b(h));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(pe,{title:"\u6211\u7684\u9080\u8BF7",width:t,gap:h,children:[ja(Lo,{wrap:"truncate",children:[_t(Lo,{color:f.mutedForeground,children:"\u6211\u7684\u9080\u8BF7\u7801 "}),_t(Lo,{color:f.accent,children:l.inviteCode})]}),ja(Lo,{wrap:"truncate",children:[_t(Lo,{color:f.mutedForeground,children:"\u9080\u8BF7\u94FE\u63A5 "}),_t(Lo,{color:f.accent,children:`${e.ctx.site}/register?invite=${l.inviteCode}`})]})]})}),_t(Ua,{marginTop:1,flexDirection:"column",children:_t(pe,{title:"\u5956\u52B1\u89C4\u5219",width:t,gap:h,children:p.map((x,T)=>_t(Lo,{wrap:"truncate",color:f.mutedForeground,children:x},T))})}),_t(Ua,{marginTop:1,flexDirection:"column",children:_t(pe,{title:"\u9080\u8BF7\u5956\u52B1\u8BB0\u5F55",note:i===""?void 0:es(i),width:t,gap:h,children:_t(de,{retain:"list",items:d,width:m,height:g,columns:[{label:"\u65F6\u95F4"},{label:"\u597D\u53CB",shrink:!0},{label:"\u5956\u52B1\u7C7B\u578B"},{label:"\u5956\u52B1\u989D\u5EA6",align:"right"}],row:x=>{let T=x.rewardQuota-x.rewardQuotaReversed,k=x.rewardQuotaReversed>0?`\u9000\u6B3E\u51B2\u51CF -${Te(x.rewardQuotaReversed,u.quotaPerUsd)}`:"";return[K(x.createdAt),x.rewardType==="first_invitee"?x.inviterUsername:x.inviteeUsername,es(x.rewardType),_e([Te(T,u.quotaPerUsd),k])]},emptyLabel:i===""?"\u6682\u65E0\u5956\u52B1\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u597D\u53CB\u901A\u8FC7\u4F60\u7684\u9080\u8BF7\u7801\u6CE8\u518C\u5E76\u5B8C\u6210\u5145\u503C\u540E\uFF0C\u5956\u52B1\u4F1A\u663E\u793A\u5728\u8FD9\u91CC":void 0})})})]})}})})}import{useState as hb}from"react";import{z as Ie}from"zod";var JC=12e4,XC=Ie.object({id:Ie.number().int(),orderNo:Ie.string(),amountCny:Ie.number().int()}),rb=()=>A(Ie.array(XC),"/invoices/eligible-orders"),ib=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:Hm,rejectReason:Ie.string().nullable(),rejectedAt:Ie.string().nullable(),issuedAt:Ie.string().nullable(),createdAt:Ie.string()}),QC=ib.extend({hasFile:Ie.boolean(),orders:Ie.array(Ie.object({orderNo:Ie.string(),amountCny:Ie.number().int()}))}),sb=()=>A(Ie.array(ib),"/invoices"),ab=e=>A(QC,`/invoices/${e}`),cb=e=>A(se,"/invoices",{method:"POST",json:e}),lb=e=>cs(`/invoices/${e}/file`,{timeoutMs:JC}),ZC=Ie.object({id:Ie.number().int(),type:ec,title:Ie.string(),taxId:Ie.string().nullable()}),Ha=()=>A(Ie.array(ZC),"/invoices/profiles"),mb=e=>A(se,"/invoices/profiles",{method:"POST",json:e}),ub=(e,t)=>A(se,`/invoices/profiles/${e}`,{method:"PATCH",json:t}),db=e=>A(se,`/invoices/profiles/${e}`,{method:"DELETE"});import{Box as eR,Text as Oo,useInput as tR}from"ink";import{useEffect as nR,useState as oR}from"react";import{jsx as ki,jsxs as vm}from"react/jsx-runtime";var rR="[x]",iR="[ ]",pb=4,qa=2,fb=2;function gb({items:e,columns:t,row:n,selected:o,onToggle:r,onToggleAll:i,onSubmit:s,width:a,height:c,emptyLabel:l}){let[u,m]=oR(0),p=Math.max(1,c-1),d=e.length>p?Math.max(1,p-1):p;nR(()=>{m(S=>Math.min(S,Math.max(0,e.length-1)))},[e.length]);let b=dl(u,d),h=S=>{e.length!==0&&m(y=>(y+S+e.length)%e.length)};tR((S,y)=>{if(y.upArrow){h(-1);return}if(y.downArrow){h(1);return}if(y.return){s();return}S===" "&&e.length>0&&r(u)}),G(S=>{if(S==="k"){h(-1);return}if(S==="j"){h(1);return}S==="a"&&i()});let g=S=>{let y=b+S-1;return y>=0&&y<e.length?y:null},x=rt({onWheel:h,onClick:({row:S})=>{let y=g(S);y!==null&&(m(y),r(y))},onHover:({row:S})=>{let y=g(S);y!==null&&m(y)}}),T=Cl(t,e.map(S=>n(S)),a-qa-pb),k=e.slice(b,b+d);return vm(eR,{ref:x,flexDirection:"column",children:[vm(Oo,{wrap:"truncate",color:f.faintForeground,children:[" ".repeat(qa+pb),t.map((S,y)=>S.align==="right"?Kn(S.label,T[y]??0):Je(S.label,T[y]??0)).join(" ".repeat(fb))]}),e.length===0?ki(Oo,{color:f.faintForeground,children:`${" ".repeat(qa)}${l}`}):k.map((S,y)=>{let R=b+y,N=R===u,E=o.has(R),W=N?f.accent:f.foreground,M=n(S);return vm(Oo,{wrap:"truncate",children:[ki(Oo,{color:f.accent,children:N?`${ae.cursor} `:" "}),ki(Oo,{color:E?f.accent:W,bold:N,children:`${E?rR:iR} `}),t.map((C,v)=>{let _=C.align==="right"?Kn(M[v]??"",T[v]??0):Je(M[v]??"",T[v]??0);return ki(Oo,{color:W,bold:N,children:v>0?`${" ".repeat(fb)}${_}`:_},C.label)})]},R)}),(b>0||b+d<e.length)&&ki(Oo,{color:f.faintForeground,children:`${" ".repeat(qa)}${b+1}-${Math.min(b+d,e.length)} / ${e.length}`})]})}import{jsx as Tr}from"react/jsx-runtime";function yb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=hb({name:"pick"}),[i,s]=hb(new Set),{busy:a,error:c,reset:l,run:u}=ue();Re(a!==null);let m=Q([e.revision],async()=>{let[b,h]=await Promise.all([rb(),Ha()]);return{orders:b,profiles:h}});G(b=>{o.name==="pick"&&b==="r"&&e.reload()});let p=()=>{o.name==="pick"?e.pop():o.name==="preset"?r({name:"pick"}):(l(),r({name:"preset"}))},d=(b,h,g)=>{let x=(g.remark??"").trim(),T=b.filter(k=>i.has(k.id)).map(k=>k.id);u("\u6B63\u5728\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7",()=>cb({orderIds:T,type:h.type,title:h.title,taxId:h.taxId,remark:x===""?null:x}),{onSuccess:()=>{e.toast("ok","\u5DF2\u63D0\u4EA4\u5F00\u7968\u7533\u8BF7"),e.pop()}})};return Tr(Y,{trail:["\u53D1\u7968\u7BA1\u7406","\u7533\u8BF7\u5F00\u7968"],hints:o.name==="pick"?["\u2191\u2193 \u79FB\u52A8","Space \u52FE\u9009","a \u5168\u9009","Enter \u4E0B\u4E00\u6B65","r \u5237\u65B0"]:[],onEscape:p,isActive:a===null,children:Tr(V,{state:m,loading:"\u6B63\u5728\u8BFB\u53D6\u53EF\u5F00\u7968\u8BA2\u5355",width:t,children:({orders:b,profiles:h})=>{if(o.name==="pick")return b.length===0?Tr(ye,{tone:"info",width:t,title:"\u6682\u65E0\u53EF\u5F00\u7968\u8BA2\u5355",detail:"\u5B8C\u6210\u5145\u503C\u5E76\u652F\u4ED8\u540E\uFF0C\u8BA2\u5355\u4F1A\u663E\u793A\u5728\u8FD9\u91CC"}):Tr(gb,{items:b,width:t,height:n,columns:[{label:"\u8BA2\u5355\u53F7",shrink:!0},{label:"\u91D1\u989D",align:"right"}],row:g=>[g.orderNo,Ce(g.amountCny)],selected:new Set(b.flatMap((g,x)=>i.has(g.id)?[x]:[])),onToggle:g=>{let x=b[g]?.id;x!==void 0&&s(T=>{let k=new Set(T);return k.has(x)?k.delete(x):k.add(x),k})},onToggleAll:()=>s(g=>b.every(x=>g.has(x.id))?new Set:new Set(b.map(x=>x.id))),onSubmit:()=>{if(!b.some(g=>i.has(g.id))){e.toast("warn","\u8BF7\u5148\u52FE\u9009\u8981\u5F00\u7968\u7684\u8BA2\u5355");return}if(h.length===0){e.toast("warn","\u6682\u65E0\u5E38\u7528\u5F00\u7968\u4FE1\u606F\uFF0C\u8FD4\u56DE\u540E\u6309 p \u65B0\u589E");return}r({name:"preset"})},emptyLabel:"\u6682\u65E0\u53EF\u5F00\u7968\u8BA2\u5355"});if(o.name==="preset"){let g=[{heading:"\u5E38\u7528\u4FE1\u606F"},...h.map(x=>({value:x,label:`${uo(x.type)} \xB7 ${x.title}`,hint:x.taxId??void 0}))];return Tr(le,{items:g,width:t,height:n,onSelect:x=>r({name:"remark",profile:x})})}return Tr(te,{title:"\u7533\u8BF7\u5F00\u7968 \u2014 \u5907\u6CE8",width:t,submitLabel:"\u63D0\u4EA4\u7533\u8BF7",busy:a!==null,busyLabel:a??"\u6B63\u5728\u63D0\u4EA4",error:c,fields:[{kind:"textarea",name:"remark",label:"\u5907\u6CE8",rows:2,maxLength:200,placeholder:"\u5C55\u793A\u5728\u53D1\u7968\u7968\u9762\u5907\u6CE8\u680F\u7684\u5185\u5BB9",optional:!0}],onCancel:p,onSubmit:g=>d(b,o.profile,g)})}})})}import{Box as Cm}from"ink";import{useState as sR}from"react";function bb(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 Sb=e=>[{kind:"select",name:"type",label:"\u7C7B\u578B",options:[{value:"general",label:Gr("general")},{value:"special",label:Gr("special")}],initial:e?.type??"general"},{kind:"text",name:"title",label:"\u62AC\u5934",initial:e?.title??"",placeholder:"\u4E2A\u4EBA\u6216\u5355\u4F4D\u540D\u79F0"},{kind:"text",name:"taxId",label:"\u7A0E\u53F7",initial:e?.taxId??"",placeholder:"\u7EB3\u7A0E\u4EBA\u8BC6\u522B\u53F7",optional:t=>t.type!=="special"}];import{jsx as Un,jsxs as xb}from"react/jsx-runtime";var aR=8,cR=3;function Tb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=sR({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(b=>{b==="r"?e.reload():b==="n"&&r({name:"create"})},p);let d=()=>{o.name==="list"?e.pop():(a(),r({name:"list"}))};return Un(Y,{trail:["\u53D1\u7968\u7BA1\u7406","\u5E38\u7528\u4FE1\u606F"],hints:p?["\u2191\u2193 \u79FB\u52A8","Enter \u64CD\u4F5C","n \u65B0\u5EFA","r \u5237\u65B0"]:[],onEscape:d,isActive:i===null,children:Un(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u5E38\u7528\u5F00\u7968\u4FE1\u606F",width:t,children:b=>{let h=o.name==="list"?n:Math.max(cR,n-aR);return xb(Cm,{flexDirection:"column",children:[Un(Cm,{marginBottom:o.name==="list"?0:1,children:Un(de,{retain:"list",items:b,width:t,height:h,isActive:p,columns:[{label:"\u7C7B\u578B"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7A0E\u53F7"}],row:g=>[uo(g.type),g.title,g.taxId??"\u2014"],onOpen:g=>r({name:"actions",profile:g}),emptyLabel:"\u6682\u65E0\u5E38\u7528\u5F00\u7968\u4FE1\u606F",emptyDescription:"\u6309 n \u4FDD\u5B58\u4E00\u6761\u5E38\u7528\u5F00\u7968\u4FE1\u606F"})}),o.name==="actions"&&!m&&xb(pe,{title:o.profile.title,width:t,children:[Un(Ve,{width:t-ge,items:[["\u7C7B\u578B",Gr(o.profile.type)],["\u7A0E\u53F7",o.profile.taxId??"\u2014"]]}),Un(Cm,{marginTop:1,children:Un(le,{width:t-ge,items:[{value:"edit",label:"\u7F16\u8F91"},{value:"delete",label:"\u5220\u9664",labelTone:"danger"}],onSelect:g=>{a(),r(g==="edit"?{name:"edit",profile:o.profile}:{name:"confirm-delete",profile:o.profile})}})})]}),(o.name==="create"||o.name==="edit")&&Un(te,{title:o.name==="create"?"\u65B0\u589E\u5E38\u7528\u4FE1\u606F":`\u7F16\u8F91\u5E38\u7528\u4FE1\u606F \u2014 ${o.profile.title}`,width:t,submitLabel:"\u4FDD\u5B58",busy:m,busyLabel:i??"\u6B63\u5728\u4FDD\u5B58",error:s,fields:Sb(o.name==="edit"?o.profile:null),onCancel:d,onSubmit:g=>{let x=bb(g,c);if(x===null)return;let T=o.name==="edit"?()=>ub(o.profile.id,x):()=>mb(x);l("\u6B63\u5728\u4FDD\u5B58",T,{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u4FDD\u5B58")}})}}),o.name==="confirm-delete"&&Un(Ae,{width:t,title:"\u5220\u9664\u5E38\u7528\u5F00\u7968\u4FE1\u606F",detail:`\u786E\u8BA4\u5220\u9664\u300C${o.profile.title}\u300D\uFF1F`,confirmLabel:"\u5220\u9664",busy:i,error:s,onConfirm:()=>l("\u6B63\u5728\u5220\u9664",()=>db(o.profile.id),{onSuccess:()=>{r({name:"list"}),e.reload(),e.toast("ok","\u5DF2\u5220\u9664")}}),onCancel:d})]})}})})}import{Box as vi,Text as wr}from"ink";import{useState as Rm}from"react";import{jsx as nt,jsxs as wb}from"react/jsx-runtime";var lR=Pt(Za,Qi,"\u5168\u90E8\u72B6\u6001");function mR({id:e,width:t}){let n=O(),o=Q([e,n.revision],()=>ab(e)),r=t-ge,[i,s]=Rm(null),[a,c]=Rm(null),l=o.phase==="ready"?o.data:null;return G(u=>{if(u!=="d"||l===null||a!==null)return;let m=l.invoiceNo;!l.hasFile||m===null||(s(null),c(m))}),nt(V,{state:o,loading:"\u6B63\u5728\u8BFB\u53D6\u53D1\u7968\u8BE6\u60C5",width:t,children:u=>{if(a!==null)return nt(ur,{title:"\u4FDD\u5B58\u53D1\u7968\u6587\u4EF6",width:t,download:async()=>({fileName:`\u53D1\u7968-${a}.pdf`,bytes:await lb(u.id)}),onCancel:()=>c(null),onSaved:b=>{c(null),s(b),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 wb(pe,{title:u.title,note:K(u.createdAt),width:t,children:[wb(wr,{wrap:"truncate",children:[nt(wr,{color:f.mutedForeground,children:uo(u.type)}),nt(wr,{color:p===void 0?f.mutedForeground:et[p],children:` ${m.label}`})]}),nt(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(b=>nt(wr,{wrap:"truncate",color:f.faintForeground,children:_e([b.orderNo,Ce(b.amountCny)])},b.orderNo))}),u.hasFile&&i===null&&nt(vi,{marginTop:1,children:nt(wr,{wrap:"truncate",color:f.faintForeground,children:"\u6309 d \u4E0B\u8F7D\u53D1\u7968\u6587\u4EF6"})}),i!==null&&nt(vi,{marginTop:1,children:nt(wr,{wrap:"truncate",color:f.faintForeground,children:`\u5DF2\u4FDD\u5B58\u5230 ${i}`})})]})}})}function kb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=Rm({name:"list"}),[i,s]=Me("status",()=>""),a=Q([e.revision],sb);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:lR,initial:i}],onCancel:c,onSubmit:m=>{s(m.status??""),r({name:"list"})}});if(o.name==="detail")return nt(mR,{id:o.id,width:t});let u=i===""?l:l.filter(m=>m.status===i);return nt(de,{retain:"list",items:u,width:t,height:n,columns:[{label:"\u65F6\u95F4"},{label:"\u62AC\u5934",shrink:!0},{label:"\u7C7B\u578B"},{label:"\u91D1\u989D",align:"right"},{label:"\u72B6\u6001",align:"right"}],row:m=>[K(m.createdAt),m.title,uo(m.type),Ce(m.amountCny),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 uR}from"ink";import{useState as vb}from"react";import{jsx as kr,jsxs as pR}from"react/jsx-runtime";var dR=Pt(tc,zc,"\u5168\u90E8\u7C7B\u578B");function Cb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=vb("list"),[i,s]=vb(""),a=Q([e.revision],()=>Be(e.ctx.site)),c=ze([e.revision,i],m=>_h({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:dR,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=>pR(uR,{flexDirection:"column",children:[kr(de,{retain:"list",items:p.items,width:t,height:Math.max(3,n-1),columns:[{label:"\u65F6\u95F4"},{label:"\u7C7B\u578B"},{label:"\u53D8\u52A8",align:"right"},{label:"\u4F59\u989D",align:"right"},{label:"\u6765\u6E90",align:"right"}],row:d=>{let b=Xo(d.amount,m.quotaPerUsd);return[K(d.createdAt),zc(d.type),{text:d.amount>=0?`+${b}`:b,tone:d.amount>=0?"success":"danger"},Te(d.balanceAfter,m.quotaPerUsd),_e([xd(d.refType),d.refId??""])]},emptyLabel:i===""?"\u6682\u65E0\u989D\u5EA6\u6D41\u6C34":"\u65E0\u5339\u914D\u7ED3\u679C",emptyDescription:i===""?"\u5145\u503C\u6216\u6D88\u8017\u540E\uFF0C\u6BCF\u7B14\u53D8\u52A8\u4F1A\u8BB0\u5F55\u5728\u8FD9\u91CC":void 0}),kr(We,{page:c.page,pages:c.pages,total:c.total,width:t})]})})})})}import{Box as Mb}from"ink";import{useState as gR}from"react";import{z as fR}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(Ir,n)}:{kind:e,...await A(Nr,n)}}async function Rb(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(Lr,n,{method:"POST"});return{order:{kind:e,...o},qrCode:r}}var _b=(e,t)=>A(fR.array(gu),`${Ci[e]}/orders/${t}/refunds`),Pb=(e,t,n)=>A(se,`${Ci[e]}/orders/${t}/refund-request`,{method:"POST",json:{reason:n}}),Ab=(e,t)=>A(se,`${Ci[e]}/orders/${t}/refund-request/cancel`,{method:"POST"});import{Box as za,Text as wn}from"ink";import{jsx as on,jsxs as Ri}from"react/jsx-runtime";function Eb({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(pe,{title:e.kind==="recharge"?"\u5145\u503C":e.planName,note:e.orderNo,width:o,children:[Ri(wn,{wrap:"truncate",children:[on(wn,{color:s===void 0?f.mutedForeground:et[s],children:i.label}),e.kind==="subscription"&&on(wn,{color:f.faintForeground,children:` ${e.renewal?"\u7EED\u8D39":"\u65B0\u8D2D"}`})]}),on(za,{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(za,{marginTop:1,children:on(Ve,{width:r,items:a})}),t!==null&&Ri(za,{marginTop:1,flexDirection:"column",children:[on(wn,{color:f.mutedForeground,children:"\u9000\u6B3E\u8BB0\u5F55"}),t.length===0?on(wn,{color:f.faintForeground,children:"\u6682\u65E0\u9000\u6B3E\u8BB0\u5F55"}):t.map(c=>{let l=Td(c.status),u=yt(l);return Ri(za,{flexDirection:"column",children:[Ri(wn,{wrap:"truncate",children:[on(wn,{color:f.foreground,children:Ce(c.amountCny)}),on(wn,{color:u===void 0?f.mutedForeground:et[u],children:` ${l.label}`}),on(wn,{color:f.faintForeground,children:` ${K(c.createdAt)}`})]}),(c.reason!==null||c.rejectReason!==null||c.refundTradeNo!==null)&&on(wn,{wrap:"truncate",color:f.faintForeground,children:` ${_e([c.reason??"",c.rejectReason===null?"":`\u9A73\u56DE\uFF1A${c.rejectReason}`,c.refundTradeNo??""])}`})]},c.id)})]})]})}import{jsx as Do,jsxs as yR}from"react/jsx-runtime";var hR=new Set(["pending","expired","failed"]);function Wa(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 Ib({params:e}){let t=O(),{width:n}=j(),[o,r]=gR("main"),{busy:i,error:s,reset:a,fail:c,run:l}=ue();Re(i!==null);let u=Q([e.kind,e.orderNo,t.revision],async()=>{let[h,g]=await Promise.all([Ga(e.kind,e.orderNo),Be(t.ctx.site)]),x=hR.has(h.status)?null:await _b(e.kind,e.orderNo);return{order:h,refunds:x,site:g}});G(h=>{o==="main"&&i===null&&h==="r"&&t.reload()});let m=()=>{o==="main"?t.pop():(a(),r("main"))},p=h=>{l("\u6B63\u5728\u62C9\u8D77\u652F\u4ED8",()=>Rb(e.kind,e.orderNo),{failToast:!0,onSuccess:({order:g,qrCode:x})=>{t.push("pay",vr(g,x,h.quotaPerUsd))}})},d=h=>{l("\u6B63\u5728\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7",()=>Pb(e.kind,e.orderNo,h),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u63D0\u4EA4\u9000\u6B3E\u7533\u8BF7")}})},b=()=>{l("\u6B63\u5728\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",()=>Ab(e.kind,e.orderNo),{onSuccess:()=>{r("main"),t.reload(),t.toast("ok","\u5DF2\u64A4\u9500\u9000\u6B3E\u7533\u8BF7")}})};return Do(Y,{trail:["\u8BA2\u5355\u8BE6\u60C5"],hints:o==="main"?["\u2191\u2193 \u79FB\u52A8","Enter \u6267\u884C","r \u5237\u65B0"]:[],onEscape:m,isActive:i===null,children:Do(V,{state:u,loading:"\u6B63\u5728\u8BFB\u53D6\u8BA2\u5355",width:n,children:({order:h,refunds:g,site:x})=>{if(o==="refund")return Do(te,{title:`\u7533\u8BF7\u9000\u6B3E \u2014 ${h.orderNo}`,width:n,submitLabel:"\u63D0\u4EA4\u7533\u8BF7",busy:i!==null,busyLabel:i??"\u6B63\u5728\u63D0\u4EA4",error:s,fields:[{kind:"select",name:"reason",label:"\u9000\u6B3E\u539F\u56E0",options:[...Jc[e.kind].map(k=>({value:k,label:k})),{value:"other",label:"\u5176\u4ED6"}],initial:Jc[e.kind][0],hint:Pd[e.kind]},{kind:"textarea",name:"custom",label:"\u5177\u4F53\u8BF4\u660E",rows:3,maxLength:256,placeholder:"\u8BF4\u660E\u7533\u8BF7\u9000\u6B3E\u7684\u539F\u56E0",hint:"\u4EC5\u9000\u6B3E\u539F\u56E0\u9009\u300C\u5176\u4ED6\u300D\u65F6\u5FC5\u586B"}],onCancel:m,onSubmit:k=>{let S=k.reason??"",y=S==="other"?(k.custom??"").trim():S;if(y===""){c("\u8BF7\u586B\u5199\u5177\u4F53\u8BF4\u660E");return}d(y)}});if(o==="confirm-cancel")return Do(Ae,{width:n,title:"\u64A4\u9500\u9000\u6B3E\u7533\u8BF7",detail:`\u786E\u8BA4\u64A4\u9500\u8BA2\u5355 ${h.orderNo} \u7684\u9000\u6B3E\u7533\u8BF7\uFF1F${h.kind==="recharge"?"\u6536\u56DE\u7684\u989D\u5EA6":"\u51BB\u7ED3\u7684\u8BA2\u9605\u65F6\u957F"}\u5C06\u7ACB\u5373\u6062\u590D`,confirmLabel:"\u64A4\u9500\u7533\u8BF7",busy:i,error:s,onConfirm:b,onCancel:m});let T=[];return h.status==="pending"&&T.push({value:"pay",label:"\u7EE7\u7EED\u652F\u4ED8",hint:"\u91CD\u65B0\u62C9\u8D77\u652F\u4ED8\u5B9D\u4E8C\u7EF4\u7801"}),h.status==="refund_requested"&&T.push({value:"cancel-refund",label:"\u64A4\u9500\u7533\u8BF7",hint:"\u9000\u6B3E\u5C1A\u672A\u5BA1\u6838\uFF0C\u53EF\u64A4\u56DE"}),hu(h)&&T.push({value:"refund",label:"\u7533\u8BF7\u9000\u6B3E",labelTone:"danger"}),yR(Mb,{flexDirection:"column",children:[Do(Eb,{order:h,refunds:g,quotaPerUsd:x.quotaPerUsd,width:n}),T.length>0&&i===null&&Do(Mb,{marginTop:1,children:Do(le,{width:n,items:T,retain:"menu",onSelect:k=>{a(),k==="pay"?p(x):r(k==="refund"?"refund":"confirm-cancel")}})})]})}})})}import{useRef as SR,useState as Bb}from"react";import{Box as Nb,Text as $o}from"ink";import{Fragment as bR,jsx as zt,jsxs as Lb}from"react/jsx-runtime";var Ob={columns:20,rows:2};function Db(e,t,n){return Ws(e,t,Ob,n)}function $b({phase:e,qrCode:t,amountCny:n,summary:o,paidNote:r,expiredNote:i,pollError:s,width:a,layout:c}){let l=s===null?zt(Oe,{label:"\u7B49\u5F85\u652F\u4ED8\u5230\u8D26\u2026"}):zt($o,{wrap:"truncate",color:et.warning,children:`\u67E5\u8BE2\u5931\u8D25\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF1A${s}`});if(e==="paid")return zt(ye,{tone:"ok",width:a,title:"\u652F\u4ED8\u6210\u529F\uFF01",detail:r});if(e==="expired")return zt(ye,{tone:"warn",width:a,title:"\u8BA2\u5355\u5DF2\u8D85\u65F6",detail:i});if(!c.fits)return Lb(Nb,{flexDirection:"column",children:[zt(ye,{tone:"warn",width:a,title:"\u7EC8\u7AEF\u5C3A\u5BF8\u4E0D\u8DB3\uFF0C\u65E0\u6CD5\u7ED8\u5236\u4E8C\u7EF4\u7801",detail:`\u653E\u5927\u5230 ${c.target.columns} \xD7 ${c.target.rows} \u53EF\u663E\u793A\u4E8C\u7EF4\u7801\uFF0C\u6216\u6309 c \u590D\u5236\u4ED8\u6B3E\u94FE\u63A5`}),zt($o,{color:f.accent,children:t}),zt(Nb,{marginTop:1,children:zt($o,{bold:!0,color:f.foreground,children:Ce(n)})}),l]});let u=c.asideRows-Ob.rows,m=u>=1,p=u>=2,d=u>=2+o.length;return zt(Vs,{value:t,aside:Lb(bR,{children:[p&&zt($o,{bold:!0,color:f.foreground,children:"\u626B\u7801\u652F\u4ED8"}),zt($o,{bold:!0,color:f.foreground,children:Ce(n)}),m&&zt($o,{color:f.mutedForeground,children:"\u8BF7\u4F7F\u7528\u652F\u4ED8\u5B9D\u626B\u4E00\u626B\u5B8C\u6210\u652F\u4ED8"}),d&&o.map((b,h)=>zt($o,{wrap:"truncate",color:f.mutedForeground,children:b},h)),l]})})}import{jsx as Fb}from"react/jsx-runtime";var xR=5,TR=2e3;function Ub({params:e}){let t=O(),{width:n,columns:o,rows:r}=j(),i=ri(0),[s,a]=Bb("waiting"),[c,l]=Bb(null),u=SR(0);aa(TR,async()=>{let d;try{d=await Ga(e.kind,e.orderNo)}catch(b){l(Se(b));return}if(l(null),d.status==="paid"||d.credited){a("paid"),t.toast("ok",e.paidMessage);return}if(d.status==="expired"||d.status==="failed"){u.current+=1,u.current>=xR&&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=Db(e.qrCode,{width:n,rows:i},{columns:o-n,rows:r-i}),p=s==="waiting"&&m.fits;return Fb(Y,{trail:["\u626B\u7801\u652F\u4ED8"],bleed:p,hints:s==="waiting"?["c \u590D\u5236\u94FE\u63A5"]:[],children:Fb($b,{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 kR}from"react";import{z as jn}from"zod";var wR=jn.object({id:jn.number().int(),name:jn.string(),originalCny:jn.number().int(),discountPercent:jn.number().int(),payCny:jn.number().int(),quota:jn.number()}),jb=()=>A(jn.array(wR),"/recharge-packages"),Hb=e=>A(Di,"/recharge/orders",{method:"POST",json:e}),qb=()=>A(jn.array(Ir),"/recharge/orders");import{jsx as Cr}from"react/jsx-runtime";var vR=Pt(Pr,zn,"\u5168\u90E8\u72B6\u6001");function CR(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 Gb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=kR({name:"menu"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,fail:u,run:m}=ue();Re(a!==null);let p=Q([e.revision],async()=>{let[h,g,x]=await Promise.all([jb(),_a(e.ctx.site),qb()]);return{packages:h,pricing:g,orders:x}});G(h=>{o.name==="menu"&&(h==="r"?e.reload():h==="f"&&r({name:"filter"}))});let d=()=>{o.name==="menu"?e.pop():(l(),r({name:"menu"}))},b=(h,g)=>{m("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>Hb(h),{onSuccess:({order:x,qrCode:T})=>{r({name:"menu"}),e.push("pay",vr({kind:"recharge",...x},T,g))}})};return Cr(Y,{hints:o.name==="menu"?["\u2191\u2193 \u79FB\u52A8","Enter \u6253\u5F00","f \u7B5B\u9009\u8BB0\u5F55","r \u5237\u65B0"]:["Esc \u8FD4\u56DE"],onEscape:d,isActive:a===null,children:Cr(V,{state:p,loading:"\u6B63\u5728\u8BFB\u53D6\u5145\u503C\u5957\u9910",width:t,children:({packages:h,pricing:g,orders:x})=>{if(o.name==="confirm")return Cr(Ae,{width:t,title:`\u786E\u8BA4\u5145\u503C ${Ce(o.pkg.payCny)}\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>b({packageId:o.pkg.id},g.quotaPerUsd),onCancel:d});if(o.name==="custom")return Cr(te,{title:"\u81EA\u5B9A\u4E49\u91D1\u989D\u5145\u503C",width:t,submitLabel:"\u53BB\u652F\u4ED8",busy:a!==null,busyLabel:a??"\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",error:c,fields:[{kind:"text",name:"yuan",label:"\u5145\u503C\u91D1\u989D\uFF08\u5143\uFF09",placeholder:"\u8BF7\u8F93\u5165\u91D1\u989D",hint:`\u6700\u4F4E ${g.minTopupCny} \u5143 \xB7 \u5230\u8D26\u989D\u5EA6\u6309\u5145\u503C\u6C47\u7387\u6298\u7B97`}],onCancel:d,onSubmit:S=>{let y=Number((S.yuan??"").trim()),R=Fc(y);if(!Number.isFinite(y)||R<Fc(g.minTopupCny)||R>lc){u(`\u8BF7\u8F93\u5165 ${g.minTopupCny} \u5230 ${dd(lc)} \u5143\u4E4B\u95F4\u7684\u91D1\u989D`);return}b({amountCny:R},g.quotaPerUsd)}});if(o.name==="filter")return Cr(te,{title:"\u7B5B\u9009\u5145\u503C\u8BB0\u5F55",width:t,submitLabel:"\u67E5\u8BE2",fields:[{kind:"select",name:"status",label:"\u72B6\u6001",options:vR,initial:i}],onCancel:d,onSubmit:S=>{s(S.status??""),r({name:"menu"})}});let T=i===""?x:x.filter(S=>S.status===i),k=[{heading:"\u5145\u503C\u5957\u9910"},...h.map(S=>({value:{kind:"pkg",pkg:S},label:S.name,hint:CR(S,g.quotaPerUsd)})),{value:{kind:"custom"},label:"\u81EA\u5B9A\u4E49\u91D1\u989D",hint:"\u8F93\u5165\u4EFB\u610F\u91D1\u989D\u5145\u503C"},{heading:""},{heading:"\u5145\u503C\u8BB0\u5F55"},...T.length===0?[{value:{kind:"none"},label:i===""?"\u6682\u65E0\u5145\u503C\u8BB0\u5F55":"\u65E0\u5339\u914D\u7ED3\u679C",...i===""?{hint:"\u9009\u62E9\u4E0A\u65B9\u5957\u9910\u6216\u8F93\u5165\u81EA\u5B9A\u4E49\u91D1\u989D\u5373\u53EF\u5145\u503C"}:{},disabled:!0}]:T.map(S=>({value:{kind:"order",orderNo:S.orderNo},label:Ce(S.amountCny),...Wa(S),hint:`${K(S.createdAt)} \xB7 \u5230\u8D26\u989D\u5EA6 ${Te(S.quota,g.quotaPerUsd)}`}))];return Cr(le,{items:k,width:t,height:n,retain:"menu",onSelect:S=>{l(),S.kind==="custom"?r({name:"custom"}):S.kind==="order"?e.push("order",{kind:"recharge",orderNo:S.orderNo}):S.kind==="pkg"&&r({name:"confirm",pkg:S.pkg})}})}})})}import{Box as Hn,Text as _i}from"ink";import{useState as AR}from"react";import ER from"string-width";import{z as xe}from"zod";var RR=xe.object({windowId:xe.number().int(),durationMinutes:xe.number().int(),quota:xe.number(),used:xe.number(),resetAt:xe.string()}),zb=xe.object({name:xe.string(),multiplier:xe.number()}),_R=xe.object({billingPreference:Xa,subscriptions:xe.array(xe.object({id:xe.number().int(),planName:xe.string(),groups:xe.array(zb),startsAt:xe.string(),expiresAt:xe.string(),revokedAt:xe.string().nullable(),renewable:xe.boolean(),windows:xe.array(RR)}))}),Wb=()=>A(_R,"/subscriptions"),PR=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(zb),windows:xe.array(xe.object({durationMinutes:xe.number().int(),quota:xe.number()}))}),Vb=()=>A(xe.array(PR),"/subscription-plans"),Kb=e=>A(Lr,"/subscriptions/orders",{method:"POST",json:e}),Yb=e=>A(Lr,`/subscriptions/${e}/renew`,{method:"POST"}),Jb=()=>A(xe.array(Nr),"/subscriptions/orders"),Xb=e=>A(xe.object({billingPreference:Xa}),"/subscriptions/preference",{method:"PUT",json:e});import{jsx as je,jsxs as Bo}from"react/jsx-runtime";var MR=Pt(Pr,zn,"\u5168\u90E8\u72B6\u6001");function IR(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 NR=3;function LR({win:e,quotaPerUsd:t,width:n}){let o=Kc(e),r=Rd(e.durationMinutes),i=`\u5DF2\u7528 ${o}% ${ae.bullet} ${Te(e.used,t)} / ${Te(e.quota,t)}`;return Bo(Hn,{flexDirection:"column",children:[Bo(_i,{wrap:"truncate",children:[je(_i,{color:f.foreground,children:r}),je(_i,{color:o>=100?f.danger:f.mutedForeground,children:Kn(i,Math.max(0,n-ER(r)))})]}),je(xg,{used:e.used,total:e.quota,width:n}),je(_i,{wrap:"truncate",color:f.faintForeground,children:`\u5C06\u4E8E ${K(e.resetAt)} \u91CD\u7F6E`})]})}function OR(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 DR(e){let t=e.windows.length*4;return X+Xe+2+t+(e.renewable?X+1:0)}function $R(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 Qb(){let e=O(),{width:t}=j(),n=Z(),[o,r]=AR({name:"menu"}),[i,s]=Me("status",()=>""),{busy:a,error:c,reset:l,run:u}=ue();Re(a!==null);let m=Q([e.revision],async()=>{let[g,x,T,k]=await Promise.all([Wb(),Vb(),Jb(),Be(e.ctx.site)]);return{mine:g,plans:x,orders:T,site:k}});G(g=>{o.name!=="menu"||a!==null||(g==="r"?e.reload():g==="f"&&r({name:"filter"}))});let p=()=>{l(),o.name==="menu"?e.pop():o.name==="confirm-renew"?r({name:"sub",id:o.id}):o.name==="confirm-buy"?r({name:"plan",id:o.id}):r({name:"menu"})},d=g=>{u("\u6B63\u5728\u4FDD\u5B58\u504F\u597D",()=>Xb({billingPreference:g}),{onSuccess:()=>{r({name:"menu"}),e.reload(),e.toast("ok","\u504F\u597D\u5DF2\u4FDD\u5B58")}})},b=(g,x)=>{u("\u6B63\u5728\u521B\u5EFA\u7EED\u8D39\u8BA2\u5355",()=>Yb(g.id),{onSuccess:({order:T,qrCode:k})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...T},k,x.quotaPerUsd))}})},h=(g,x)=>{u("\u6B63\u5728\u521B\u5EFA\u8BA2\u5355",()=>Kb({planId:g.id}),{onSuccess:({order:T,qrCode:k})=>{r({name:"menu"}),e.push("pay",vr({kind:"subscription",...T},k,x.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:x,orders:T,site:k})=>{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:Sd,initial:g.billingPreference,hint:Gc}],onCancel:p,onSubmit:v=>{d(v.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:MR,initial:i}],onCancel:p,onSubmit:v=>{s(v.status??""),r({name:"menu"})}});let S=IR(o,g.subscriptions,x);if(S.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(S.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(S.kind==="sub"&&S.confirm)return je(Ae,{width:t,title:`\u786E\u8BA4\u7EED\u8D39\u300C${S.sub.planName}\u300D\uFF1F`,detail:"\u5C06\u6309\u5957\u9910\u5F53\u524D\u4EF7\u683C\u4E0E\u65F6\u957F\u5728\u5230\u671F\u65F6\u95F4\u4E0A\u987A\u5EF6",confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>b(S.sub,k),onCancel:p});if(S.kind==="plan"&&S.confirm)return je(Ae,{width:t,title:`\u786E\u8BA4\u8BA2\u9605\u300C${S.plan.name}\u300D\uFF08${Ce(S.plan.priceCny)} / ${S.plan.durationDays} \u5929\uFF09\uFF1F`,confirmLabel:"\u53BB\u652F\u4ED8",busy:a,error:c,onConfirm:()=>h(S.plan,k),onCancel:p});let y=S.kind==="plan"?S.plan.description:"",R=i===""?T:T.filter(v=>v.status===i),N=[{heading:"\u6211\u7684\u8BA2\u9605"},...g.subscriptions.length===0?[{value:{kind:"none"},label:"\u6682\u65E0\u8BA2\u9605",hint:"\u8BA2\u9605\u4E0B\u65B9\u5957\u9910\u540E\uFF0C\u8986\u76D6\u8303\u56F4\u5185\u7684\u8C03\u7528\u5C06\u6309\u6263\u8D39\u65B9\u5F0F\u4F7F\u7528\u8BA2\u9605\u989D\u5EA6",disabled:!0}]:g.subscriptions.map(v=>{let _=Yc(v);return{value:{kind:"sub",id:v.id},label:v.planName,badge:_.label,badgeTone:yt(_),hint:OR(v)}}),{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"},...x.length===0?[{value:{kind:"none"},label:"\u6682\u65E0\u53EF\u9009\u5957\u9910",hint:"\u8BA2\u9605\u5957\u9910\u4E0A\u67B6\u540E\u5C06\u663E\u793A\u5728\u8FD9\u91CC",disabled:!0}]:x.map(v=>({value:{kind:"plan",id:v.id},label:v.name,...v.enabled?{}:{badge:"\u5DF2\u505C\u552E",badgeTone:"warning"},hint:`${Ce(v.priceCny)} / ${v.durationDays} \u5929 \xB7 ${v.groups.map(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(v=>({value:{kind:"order",orderNo:v.orderNo},label:`${v.planName}${v.renewal?"\uFF08\u7EED\u8D39\uFF09":""}`,...Wa(v),hint:`${K(v.createdAt)} \xB7 ${Ce(v.amountCny)}`}))],E=S.kind==="sub"?DR(S.sub):S.kind==="plan"?$R(S.plan):0,W=E===0?n:n-E>=NR?n-E:0,M=t-ge,C=o.name==="menu"&&a===null;return Bo(Hn,{flexDirection:"column",children:[W>0&&je(le,{items:N,width:t,height:W,isActive:C,retain:"menu",onSelect:v=>{l(),v.kind==="preference"?r({name:"preference"}):v.kind==="order"?e.push("order",{kind:"subscription",orderNo:v.orderNo}):v.kind==="sub"?r({name:"sub",id:v.id}):v.kind==="plan"&&r({name:"plan",id:v.id})}}),S.kind==="sub"&&Bo(Hn,{marginTop:W>0?X:0,flexDirection:"column",children:[Bo(pe,{title:S.sub.planName,note:S.sub.revokedAt!==null?`${K(S.sub.revokedAt)} \u4F5C\u5E9F`:`${K(S.sub.expiresAt)} \u5230\u671F`,width:t,children:[je(Ve,{width:M,items:[["\u72B6\u6001",Yc(S.sub).label],["\u8986\u76D6\u5206\u7EC4",S.sub.groups.map(rs).join("\u3001")],["\u751F\u6548\u65F6\u95F4",K(S.sub.startsAt)]]}),je(Hn,{marginTop:1,flexDirection:"column",children:S.sub.windows.map((v,_)=>je(Hn,{marginTop:_===0?0:1,flexDirection:"column",children:je(LR,{win:v,quotaPerUsd:k.quotaPerUsd,width:M})},v.windowId))})]}),S.sub.renewable&&a===null&&je(Hn,{marginTop:X,children:je(le,{width:t,items:[{value:"renew",label:"\u7EED\u8D39"}],onSelect:()=>r({name:"confirm-renew",id:S.sub.id})})})]}),S.kind==="plan"&&Bo(Hn,{marginTop:W>0?X:0,flexDirection:"column",children:[Bo(pe,{title:S.plan.name,note:`${Ce(S.plan.priceCny)} / ${S.plan.durationDays} \u5929`,width:t,children:[y!==""&&je(_i,{wrap:"truncate",color:f.mutedForeground,children:y}),je(Hn,{marginTop:y===""?0:Ge,children:je(Ve,{width:M,items:[["\u8986\u76D6\u5206\u7EC4",S.plan.groups.map(rs).join("\u3001")],..._d(S.plan,k.quotaPerUsd).map((v,_)=>[_===0?"\u7528\u91CF\u7A97\u53E3":"",v])]})})]}),a===null&&je(Hn,{marginTop:X,children:je(le,{width:t,items:[{value:"subscribe",label:S.plan.enabled?"\u8BA2\u9605":"\u5DF2\u505C\u552E",disabled:!S.plan.enabled}],onSelect:()=>r({name:"confirm-buy",id:S.plan.id})})})]})]})}})})}import{jsx as be}from"react/jsx-runtime";var Zb={home:{render:()=>be(Qy,{})},help:{render:()=>be(Yy,{})},login:{render:()=>be(Kg,{})},register:{render:()=>be(Yg,{})},forgot:{render:()=>be(Gg,{})},agreement:{render:e=>be(Bg,{params:e})},tokens:{render:()=>be(Ly,{})},logs:{render:()=>be(Uh,{})},usage:{render:()=>be(Nh,{})},ledger:{render:()=>be(Cb,{})},subscription:{render:()=>be(Qb,{})},models:{render:()=>be(Vh,{})},docs:{render:()=>be(jy,{})},doc:{render:e=>be(Gy,{params:e})},recharge:{render:()=>be(Gb,{})},order:{render:e=>be(Ib,{params:e})},pay:{render:e=>be(Ub,{params:e})},invoices:{render:()=>be(kb,{})},"invoice-apply":{render:()=>be(yb,{})},"invoice-profiles":{render:()=>be(Tb,{})},invite:{render:()=>be(ob,{})},tickets:{render:()=>be($g,{})},ticket:{render:e=>be(Dg,{params:e})},community:{render:()=>be(ph,{})},post:{render:e=>be(wh,{params:e})},floor:{render:e=>be(sh,{params:e})},compose:{render:e=>be(Zg,{params:e})},"post-edit":{render:e=>be(eh,{params:e})},homepage:{render:e=>be(lh,{params:e})},inbox:{render:()=>be(Zy,{})},announcements:{render:()=>be(nf,{})},"announce-gate":{render:e=>be(Zp,{params:e}),lockNav:!0},profile:{render:()=>be(Rg,{})},"my-posts":{render:e=>be(hh,{params:e})},"my-comments":{render:e=>be(yh,{params:e})},bookmarks:{render:()=>be(bh,{})},drafts:{render:()=>be(Sh,{})}};function eS(e){return Zb[e].lockNav===!0}function tS(e){let t=Zb[e.id].render;return t(e.params)}import{jsx as oo,jsxs as JR}from"react/jsx-runtime";function HR(){let e=O(),{rows:t}=j(),n=hs(),o=eS(e.current.id)||n,r=e.depth===1&&Ss(e.current.id)&&wt().session===null;return _m(()=>{r&&e.home()}),UR((i,s)=>{s.ctrl&&i==="c"&&e.exit()}),G(i=>{if(i==="?"){e.current.id==="help"?e.pop():o||e.push("help");return}i==="q"&&!o&&(e.depth>1?e.pop():e.exit())}),oo(BR,{flexDirection:"column",height:Math.max(1,t),paddingX:1,paddingTop:1,overflow:"hidden",children:tS(e.current)})}function qR(){let e=O(),t=Q([e.revision],async()=>{if(e.gate.announcementsChecked||wt().session===null)return null;let n;try{n=await Kd()}catch{return null}return e.gate.announcementsChecked=!0,n});return _m(()=>{t.phase!=="ready"||t.data===null||e.gate.announcementsShown||(e.gate.announcementsShown=!0,e.push("announce-gate",{item:t.data}))}),null}function GR(){let e=O(),t=jR(!1);return _m(()=>{t.current||(t.current=!0,Wd().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 zR({ctx:e,mouse:t}){return oo(up,{subscribe:t.subscribe,children:oo(tp,{children:oo(hp,{ctx:e,children:JR(Yp,{children:[oo(GR,{}),oo(qR,{}),oo(HR,{})]})})})})}var WR="\x1B[2J\x1B[3J\x1B[H",VR="\x1B[H\x1B[J",KR="\x1B[3J";function YR(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(WR).join(VR).split(KR).join("");return t.write(s,...i)}}})}async function nS(e){let t=lp(process.stdin,process.stdout);try{await FR(oo(zR,{ctx:e,mouse:t}),{exitOnCtrlC:!0,alternateScreen:!0,stdin:t.stdin,stdout:YR(process.stdout)}).waitUntilExit()}finally{t.dispose()}}var e_=`${Wt} v${Vt} \u2014 CodeFlow \u547D\u4EE4\u884C\u5BA2\u6237\u7AEF
27
27
 
28
28
  \u7528\u6CD5
29
29
  ${Wt} \u8FDB\u5165\u4EA4\u4E92\u754C\u9762
30
30
  ${Wt} help \u67E5\u770B\u672C\u8BF4\u660E
31
31
  ${Wt} update \u68C0\u67E5\u5E76\u5B89\u88C5\u65B0\u7248\u672C
32
32
  ${Wt} uninstall \u9000\u51FA\u767B\u5F55\u3001\u5220\u9664\u672C\u5730\u6587\u4EF6\u5E76\u5378\u8F7D\u672C\u7A0B\u5E8F
33
- `;async function JR(){let e;try{({positionals:e}=KR({args:process.argv.slice(2),allowPositionals:!0,options:{}}))}catch(n){throw new U(xe(n),{hint:`\u8FD0\u884C ${Wt} help \u67E5\u770B\u7528\u6CD5`,exitCode:qa})}let[t]=e;if(t==="help")return process.stdout.write(YR),Rr;if(t==="update")return XR();if(t==="uninstall")return ZR();if(t!==void 0)throw new U(`\u672A\u77E5\u547D\u4EE4 ${t}\uFF0C\u8FD0\u884C ${Wt} help \u67E5\u770B\u7528\u6CD5`,{exitCode:qa});return t_(),await Zb(Dm()),Rr}async function XR(){let e=process.stdout,t=QR(e,"\u6B63\u5728\u68C0\u67E5\u65B0\u7248\u672C"),n;try{n=await jd()}finally{t()}let o=io(e,f.accent,"\u2714");return e.write(n===null?`${o} \u5DF2\u662F\u6700\u65B0\u7248\u672C v${Vt}
33
+ `;async function t_(){let e;try{({positionals:e}=ZR({args:process.argv.slice(2),allowPositionals:!0,options:{}}))}catch(o){throw new F(Se(o),{hint:`\u8FD0\u884C ${Wt} help \u67E5\u770B\u7528\u6CD5`,exitCode:Ka})}let[t]=e;if(t==="help")return process.stdout.write(e_),Rr;if(t==="update")return n_();if(t==="uninstall")return o_();if(t!==void 0)throw new F(`\u672A\u77E5\u547D\u4EE4 ${t}\uFF0C\u8FD0\u884C ${Wt} help \u67E5\u770B\u7528\u6CD5`,{exitCode:Ka});i_();let n=Fd();if(n!==null){let o=rS(process.stdout,"\u6B63\u5728\u6838\u5BF9\u7AD9\u70B9\u5730\u5740");try{await Ud(n)}finally{o()}}return await nS($m()),Rr}async function n_(){let e=process.stdout,t=rS(e,"\u6B63\u5728\u68C0\u67E5\u65B0\u7248\u672C"),n;try{n=await zd()}finally{t()}let o=io(e,f.accent,"\u2714");return e.write(n===null?`${o} \u5DF2\u662F\u6700\u65B0\u7248\u672C v${Vt}
34
34
  `:`${o} \u5DF2\u66F4\u65B0\u5230 v${n}
35
- `),Rr}function QR(e,t){if(!e.isTTY)return e.write(`${t}
36
- `),()=>{};let n=io(e,f.mutedForeground,t),o=0,r=()=>{let s=Qo[o%Qo.length]??"";o+=1,e.write(`\r\x1B[2K${io(e,f.accent,s)} ${n}`)};r();let i=setInterval(r,bs);return()=>{clearInterval(i),e.write("\r\x1B[2K")}}async function ZR(){let e=process.stdout;if(e.write(`\u5378\u8F7D\u4F1A\u9000\u51FA\u767B\u5F55\u3001\u5220\u9664\u672C\u5730\u6587\u4EF6\u5E76\u5378\u8F7D\u672C\u7A0B\u5E8F
37
- `),!await e_("\u8F93\u5165 y \u786E\u8BA4\u5378\u8F7D\uFF1A"))return e.write(`\u5DF2\u53D6\u6D88
38
- `),Uo;let t=await $d({done:n=>e.write(`${io(e,f.accent,"\u2714")} ${n}
35
+ `),Rr}function rS(e,t){if(!e.isTTY)return e.write(`${t}
36
+ `),()=>{};let n=io(e,f.mutedForeground,t),o=0,r=()=>{let s=Qo[o%Qo.length]??"";o+=1,e.write(`\r\x1B[2K${io(e,f.accent,s)} ${n}`)};r();let i=setInterval(r,ks);return()=>{clearInterval(i),e.write("\r\x1B[2K")}}async function o_(){let e=process.stdout;if(e.write(`\u5378\u8F7D\u4F1A\u9000\u51FA\u767B\u5F55\u3001\u5220\u9664\u672C\u5730\u6587\u4EF6\u5E76\u5378\u8F7D\u672C\u7A0B\u5E8F
37
+ `),!await r_("\u8F93\u5165 y \u786E\u8BA4\u5378\u8F7D\uFF1A"))return e.write(`\u5DF2\u53D6\u6D88
38
+ `),Uo;let t=await jd({done:n=>e.write(`${io(e,f.accent,"\u2714")} ${n}
39
39
  `),failed:n=>e.write(`${io(e,f.danger,"\u2718")} ${n}
40
40
  `)});if(t.length===0)return e.write(`\u767B\u5F55\u72B6\u6001\u3001\u672C\u5730\u6587\u4EF6\u4E0E\u672C\u7A0B\u5E8F\u5747\u5DF2\u6E05\u9664
41
41
  `),Rr;e.write(`\u4EE5\u4E0B\u9879\u76EE\u672A\u80FD\u6E05\u7406\uFF1A
42
42
  `);for(let n of t)e.write(` ${n}
43
- `);return Uo}async function e_(e){let t=VR({input:process.stdin,output:process.stdout});t.once("SIGINT",()=>t.close());let n=await Promise.race([t.question(e),WR(t,"close").then(()=>"")]);return t.close(),n.trim().toLowerCase()==="y"}function t_(){if(!process.stdin.isTTY||!process.stdout.isTTY)throw new U("\u4EA4\u4E92\u754C\u9762\u9700\u8981\u5728\u7EC8\u7AEF\u4E2D\u76F4\u63A5\u8FD0\u884C")}var eS=(e,t)=>io(process.stderr,e,t);try{process.exitCode=await JR()}catch(e){process.stderr.write(`${eS(f.danger,"\u2718")} ${xe(e)}
44
- `),e instanceof U&&e.hint&&process.stderr.write(` ${eS(f.faintForeground,e.hint)}
45
- `),process.exitCode=e instanceof U?e.exitCode:Uo}
43
+ `);return Uo}async function r_(e){let t=QR({input:process.stdin,output:process.stdout});t.once("SIGINT",()=>t.close());let n=await Promise.race([t.question(e),XR(t,"close").then(()=>"")]);return t.close(),n.trim().toLowerCase()==="y"}function i_(){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 oS=(e,t)=>io(process.stderr,e,t);try{process.exitCode=await t_()}catch(e){process.stderr.write(`${oS(f.danger,"\u2718")} ${Se(e)}
44
+ `),e instanceof F&&e.hint&&process.stderr.write(` ${oS(f.faintForeground,e.hint)}
45
+ `),process.exitCode=e instanceof F?e.exitCode:Uo}