import{Bw as I,Cw as P,Fw as t,Kn as W,Ln as n}from"./cli-0.5.12-zc0qwdy2.mjs";import{JZ as H,KZ as p}from"./cli-0.5.12-5d3qcvf5.mjs";import{LZ as C,NZ as i}from"./cli-0.5.12-f141d2qa.mjs";import{F3 as R,L3 as V,d4 as l,e3 as v,n0 as S,s0 as c}from"./cli-0.5.12-pycnjaeg.mjs";import{Bca as D,Jaa as E,Jca as m,Maa as X,cca as T,dca as Y,eba as O,gaa as q,haa as u,jca as y,mca as k,pca as g}from"./cli-0.5.12-g4wb8mj2.mjs";import{Oda as G,Qda as f,Rda as $,Sda as h}from"./cli-0.5.12-7vxpqr5a.mjs";import{Yea as Z,bfa as _,cfa as M}from"./cli-0.5.12-k1crwtdc.mjs";import{fga as x,iga as b}from"./cli-0.5.12-p5ps8gf0.mjs";import{Dna as A,lna as Q}from"./cli-0.5.12-495d826j.mjs";import{aoa as U}from"./cli-0.5.12-xzeb7mtb.mjs";async function s(){if(q())return x("[Bootstrap] Skipped: Nonessential traffic disabled"),null;if(S()!=="firstParty")return x("[Bootstrap] Skipped: 3P provider"),null;let w=v();if(!(R()?.accessToken&&V())&&!w)return x("[Bootstrap] Skipped: no usable OAuth or API key"),null;let J=`${_().BASE_API_URL}/api/claude_cli/bootstrap`;try{return await H(async()=>{let j=R()?.accessToken,z;if(j&&V())z={Authorization:`Bearer ${j}`,"anthropic-beta":Z};else if(w)z={"x-api-key":w};else return x("[Bootstrap] No auth available on retry, aborting"),null;x("[Bootstrap] Fetching");let N=await Q.get(J,{headers:{"Content-Type":"application/json","User-Agent":C(),...z},timeout:5000}),B=d().safeParse(N.data);if(!B.success)return x(`[Bootstrap] Response failed validation: ${B.error.message}`),null;return x("[Bootstrap] Fetch ok"),B.data})}catch(j){if(Q.isAxiosError(j)){let z=j.response?.status??"no-response",N=j.code??"unknown-code",B=j.config?.method?.toUpperCase()??"UNKNOWN",K=j.config?.url??"unknown-url",L=j.message??"unknown axios error";x(`[Bootstrap] Fetch failed: status=${z} code=${N} method=${B} url=${K} message=${L}`)}else{let z=j instanceof Error?j.message:String(j);x(`[Bootstrap] Fetch failed: ${z}`)}throw j}}async function a(){let w=Y();if(!w?.startsWith("openai:"))return null;let{baseUrl:F}=T(),J=await P({baseUrl:F,apiKey:k()?.apiKey});if(J===null)return x("[Bootstrap] Local OpenAI model discovery failed"),null;let j=I(F);return{clientData:X().clientDataCache??null,additionalModelOptionsScope:w,additionalModelOptions:J.map((z)=>({value:z,label:z,description:`Detected from ${j}`}))}}async function Yj(){try{let w=Y(),F=null;if(w==="firstParty"){let B=await s();if(!B)return;F={clientData:B.client_data??null,additionalModelOptions:B.additional_model_options??[],additionalModelOptionsScope:w}}else if(w?.startsWith("openai:")){if(F=await a(),!F)return}else{x("[Bootstrap] Skipped: no additional model source");return}let{clientData:J,additionalModelOptions:j,additionalModelOptionsScope:z}=F,N=X();if(W(N.clientDataCache,J)&&W(N.additionalModelOptionsCache,j)&&N.additionalModelOptionsCacheScope===z){x("[Bootstrap] Cache unchanged, skipping write");return}x("[Bootstrap] Cache updated, persisting to disk"),E((B)=>({...B,clientDataCache:J,additionalModelOptionsCache:j,additionalModelOptionsCacheScope:z}))}catch(w){D(w)}}var d;var r=U(()=>{A();n();l();f();M();O();b();p();h();m();c();u();t();i();g();y();d=$(()=>G.object({client_data:G.record(G.string(),G.unknown()).nullish(),additional_model_options:G.array(G.object({model:G.string(),name:G.string(),description:G.string()}).transform(({model:w,name:F,description:J})=>({value:w,label:F,description:J}))).nullish()}))});
export{Yj as Kb,r as Lb};
