import{Cw as t,mn as W,nn as n,yw as I,zw as P}from"./cli-0.5.3-jbzr8k4s.mjs";import{VY as H,WY as p}from"./cli-0.5.3-zg2apr51.mjs";import{XY as C,ZY as i}from"./cli-0.5.3-ngnshpb7.mjs";import{$2 as R,A2 as v,GZ as S,LZ as c,f3 as V,z3 as l}from"./cli-0.5.3-1vt6twff.mjs";import{D5 as Q,V5 as O}from"./cli-0.5.3-vpcrbd8n.mjs";import{$ba as Y,Caa as T,Faa as X,H6 as f,Yaa as y,_ba as k,fca as g,ica as D,lca as m,u6 as Z,v6 as M,z6 as _}from"./cli-0.5.3-t65dek0m.mjs";import{Eca as G,Gca as h,Hca as $,Ica as A}from"./cli-0.5.3-kavpx97n.mjs";import{Eea as q,Jea as E,Kea as u}from"./cli-0.5.3-66650sba.mjs";import{Nfa as x,Qfa as b}from"./cli-0.5.3-n3cxyxpg.mjs";import{Xma as U}from"./cli-0.5.3-0df3r78b.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};
