import{Aw as I,Bw as P,Ew as t,on as W,pn as n}from"./cli-0.5.4-k5fz4zd3.mjs";import{XY as H,YY as p}from"./cli-0.5.4-5shjmmkz.mjs";import{$Y as i,ZY as C}from"./cli-0.5.4-zb412kkm.mjs";import{B3 as l,C2 as v,IZ as S,NZ as c,b3 as R,h3 as V}from"./cli-0.5.4-jqt00ywx.mjs";import{F5 as Q,X5 as O}from"./cli-0.5.4-j7kkqxv6.mjs";import{B6 as _,Eaa as T,Haa as X,J6 as f,_aa as y,aca as k,bca as Y,hca as g,kca as D,nca as m,w6 as Z,x6 as M}from"./cli-0.5.4-cbq01zg3.mjs";import{Gca as G,Ica as h,Jca as $,Kca as A}from"./cli-0.5.4-37v5fhf1.mjs";import{Gea as q,Lea as E,Mea as u}from"./cli-0.5.4-e822fzaq.mjs";import{Pfa as x,Sfa as b}from"./cli-0.5.4-end8wj9r.mjs";import{Zma as U}from"./cli-0.5.4-aacw1src.mjs";async function s(){if(Z())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=`${E().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":q};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}=k(),J=await P({baseUrl:F,apiKey:D()?.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"),T((B)=>({...B,clientDataCache:J,additionalModelOptionsCache:j,additionalModelOptionsCacheScope:z}))}catch(w){_(w)}}var d;var r=U(()=>{O();n();l();h();u();y();b();p();A();f();c();M();t();i();m();g();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 Eb,r as Fb};
