import{Ah as $,zh as U}from"./cli-0.5.12-vkgwh6kg.mjs";import{Zba as L,bca as N,cca as O,gca as Q,jca as Z,mca as R,pca as _}from"./cli-0.5.12-g4wb8mj2.mjs";import"./cli-0.5.12-vp5smcs1.mjs";import"./cli-0.5.12-y2kq7fe8.mjs";import"./cli-0.5.12-7vxpqr5a.mjs";import"./cli-0.5.12-hvtcdcev.mjs";import"./cli-0.5.12-asbn3d19.mjs";import"./cli-0.5.12-k1crwtdc.mjs";import"./cli-0.5.12-2jxq8gnm.mjs";import"./cli-0.5.12-p5ps8gf0.mjs";import"./cli-0.5.12-hp0508v9.mjs";import"./cli-0.5.12-tfdwzg37.mjs";import{Oga as K,Wga as Y}from"./cli-0.5.12-60w1a0bs.mjs";import"./cli-0.5.12-c8f4daey.mjs";import"./cli-0.5.12-0qasc0ef.mjs";import"./cli-0.5.12-f8850v2j.mjs";import"./cli-0.5.12-xzeb7mtb.mjs";_();Z();Y();$();var j=["ghp_","gho_","ghs_","ghr_","github_pat_"];function B(C,A="copilot"){if(j.some((w)=>C.startsWith(w))){if(A==="copilot")return"expired";return"valid"}let b=C.match(/exp=(\d+)/);if(b){let w=Number(b[1]);if(!Number.isNaN(w))return Date.now()>=w*1000?"expired":"valid"}let D=C.split(".");if(D.length===3&&D.every((w)=>/^[A-Za-z0-9_-]+$/.test(w)))try{let w=D[1].replace(/-/g,"+").replace(/_/g,"/"),I=w+"=".repeat((4-w.length%4)%4),X=Buffer.from(I,"base64").toString("utf8"),J=JSON.parse(X);if(J&&typeof J==="object"&&J.exp)return Date.now()>=J.exp*1000?"expired":"valid"}catch{return"invalid_format"}return"valid"}async function W(C,A){let b=R();if(!b)return null;if(b.transport==="gemini"){if((await(A?.resolveGeminiCredential??U)(process.env)).kind==="none")return"Configure Gemini auth via /provider — pick API key, access token, or rely on Google ADC.";return null}if(b.transport==="github_copilot"){let G=b.extras?.githubToken?.trim()||b.apiKey?.trim()||"";if(!G)return`GitHub Copilot authentication required.
Run /provider and choose GitHub Copilot.`;let w=N(b.baseUrl),I=B(G,w);if(I==="expired")return`GitHub Copilot token has expired.
Run /provider and choose GitHub Copilot.`;if(I==="invalid_format")return`GitHub Copilot token is invalid or corrupted.
Run /provider and choose GitHub Copilot.`;return null}if(b.transport!=="openai_compat"&&b.transport!=="codex_responses")return null;let D=O({model:b.model,baseUrl:b.baseUrl});if(b.apiKey==="SUA_CHAVE")return"Invalid API key: placeholder value SUA_CHAVE detected. Set a real key in /provider, or leave blank for local providers.";if(D.transport==="codex_responses"){let G=Q();if(!G.apiKey){let w=K()?"":", choose Codex OAuth in /provider",I=G.authPath?`${w} or put auth.json at ${G.authPath}`:w;return`Codex auth is required for ${D.requestedModel}. Configure it via /provider${I}.`}if(!G.accountId)return"Codex auth is missing chatgpt_account_id. Re-login with Codex OAuth via /provider, or import an auth.json with chatgpt_account_id.";return null}if(!b.apiKey&&!L(D.baseUrl))return"API key required for the active /provider profile. Run /provider to set it.";return null}async function H(C=process.env){let A=await W(C);if(A)console.error(A),process.exit(1)}function F(C={}){let A=C.args??process.argv.slice(2);if(!(C.stdoutIsTTY??process.stdout.isTTY))return!0;return A.includes("-p")||A.includes("--print")||A.includes("--init-only")||A.some((D)=>D.startsWith("--sdk-url"))}async function M(C=process.env,A){let b=await W(C);if(!b)return;if(F(A))console.error(b),process.exit(1);console.error(`Warning: provider configuration is incomplete.
${b}
Claudin will continue starting so you can run /provider and repair the saved provider settings.`)}export{H as validateProviderEnvOrExit,M as validateProviderEnvForStartupOrExit,F as shouldExitForStartupProviderValidationError,W as getProviderValidationError};
