import"./rolldown-runtime-DIIn1E2Q.js";import{D as e,c as t,kt as n,pt as r}from"./vendor-vue-core-DO0afONr.js";import{D as i}from"./vendor-other-CiPV8GBG.js";import{n as a,t as o}from"./types-DPJvCrdo.js";import{Y as s}from"./vendor-vueuse-DUMtJaL2.js";import{t as c}from"./vendor-axios-B2OLCPxZ.js";import{dt as l}from"./api-Cw7jP9TY.js";import{Ui as u,i as d}from"./dialogService-CfgsFapJ.js";import{D as f}from"./formatUtil-CeKPWstn.js";import{r as p}from"./extensionStore-MnMxnUwx.js";var m=c.create({baseURL:u(),headers:{"Content-Type":`application/json`}}),useReleaseService=()=>{let e=n(!1),t=n(null);r(()=>u(),e=>{m.defaults.baseURL=e});let handleApiError=(e,t,n)=>{if(!c.isAxiosError(e))return e instanceof Error?`${t}: ${e.message}`:`${t}: Unknown error occurred`;let r=e;if(r.response){let{status:e,data:i}=r.response;if(n&&n[e])return n[e];switch(e){case 400:return`Bad request: ${i?.message||`Invalid input`}`;case 401:return`Unauthorized: Authentication required`;case 403:return`Forbidden: ${i?.message||`Access denied`}`;case 404:return`Not found: ${i?.message||`Resource not found`}`;case 500:return`Server error: ${i?.message||`Internal server error`}`;default:return`${t}: ${i?.message||r.message}`}}return`${t}: ${r.message}`},executeApiRequest=async(n,r,i)=>{e.value=!0,t.value=null;try{return(await n()).data}catch(e){return l(e)||(t.value=handleApiError(e,r,i)),null}finally{e.value=!1}},getReleases=async(e,t)=>await executeApiRequest(()=>m.get(`/releases`,{params:e,signal:t}),`Failed to get releases`,{400:`Invalid project or version parameter`});return{isLoading:e,error:t,getReleases}},h=i(),g=t(`release`,()=>{let t=n([]),r=n(!1),i=n(null),c=useReleaseService(),l=p(),u=d(),m=e(()=>o?l?.systemStats?.system?.cloud_version??``:l?.systemStats?.system?.comfyui_version??``),g=e(()=>u.get(`Comfy.Locale`)),_=e(()=>u.get(`Comfy.Release.Version`)),v=e(()=>u.get(`Comfy.Release.Status`)),y=e(()=>u.get(`Comfy.Release.Timestamp`)),b=e(()=>u.get(`Comfy.Notification.ShowVersionUpdates`)),x=e(()=>t.value[0]??null),S=e(()=>t.value.slice(0,3)),compareVersions=(e,t)=>(0,h.valid)(e)&&(0,h.valid)(t)?(0,h.compare)(e,t):e===t?0:1,C=e(()=>!!x.value&&compareVersions(x.value.version,m.value||`0.0.0`)>0),w=e(()=>!!x.value&&compareVersions(x.value.version,m.value||`0.0.0`)===0),T=e(()=>{let e=x.value?.attention;return e===`medium`||e===`high`}),E=e(()=>!(!a||o||!b.value||!C.value||!T.value||_.value===x.value?.version&&[`skipped`,`changelog seen`].includes(v.value))),D=e(()=>{if(!a||o||!b.value||!C.value)return!1;let{version:e}=x.value;return _.value===e&&v.value===`changelog seen`?!1:T.value?!0:!(_.value===e&&v.value===`skipped`&&y.value&&Date.now()-y.value>=2592e5)}),O=e(()=>!(!a&&!o||!b.value||!x.value||(0,h.valid)(m.value)&&!w.value||_.value===x.value.version&&v.value===`what's new seen`));async function handleSkipRelease(e){e!==x.value?.version||v.value===`changelog seen`||await u.setMany({"Comfy.Release.Version":e,"Comfy.Release.Status":`skipped`,"Comfy.Release.Timestamp":Date.now()})}async function handleShowChangelog(e){e===x.value?.version&&await u.setMany({"Comfy.Release.Version":e,"Comfy.Release.Status":`changelog seen`,"Comfy.Release.Timestamp":Date.now()})}async function handleWhatsNewSeen(e){e===x.value?.version&&await u.setMany({"Comfy.Release.Version":e,"Comfy.Release.Status":`what's new seen`,"Comfy.Release.Timestamp":Date.now()})}async function fetchReleases(){if(!r.value&&!(!o&&!b.value)&&!l.systemStats?.system?.argv?.includes(`--disable-api-nodes`)){r.value=!0,i.value=null;try{l.systemStats||await s(l.isInitialized);let e=await c.getReleases({project:o?`cloud`:`comfyui`,current_version:m.value,form_factor:l.getFormFactor(),locale:f(g.value)});e===null?c.error.value&&(i.value=c.error.value):t.value=e}catch(e){i.value=e instanceof Error?e.message:`Unknown error occurred`}finally{r.value=!1}}}async function initialize(){await fetchReleases()}return{releases:t,isLoading:r,error:i,recentRelease:x,recentReleases:S,shouldShowToast:E,shouldShowRedDot:D,shouldShowPopup:O,shouldShowUpdateButton:C,handleSkipRelease,handleShowChangelog,handleWhatsNewSeen,fetchReleases,initialize}});export{g as t};
//# sourceMappingURL=releaseStore-CbpVNz_l.js.map