import{$ as e,At as t,Dt as n,H as r,Mt as i,Ot as a,W as o,at as s,fs as c,jt as l,kt as u,v as d,wt as f}from"./app-server-manager-signals-Yn0WSnoY.js";import{F as p,I as m,P as h,g,h as _,lt as v}from"./vscode-api-DjORcpSo.js";import{g as y}from"./persisted-signal-CweW-bgN.js";import{t as b}from"./invalidate-queries-and-broadcast-CivBKbpC.js";import{c as x}from"./config-queries-Br8rhpJn.js";import{n as S}from"./use-auth-CI-WraL2.js";import{a as C,i as w,n as T,t as E}from"./use-model-settings-DfS1n7_R.js";import{n as D}from"./model-queries-CuDRhJFc.js";import{n as O}from"./use-webview-execution-target-B5MTa9cH.js";var k=v();function A(e){let t=(0,k.c)(6),n=m(d),r=e?.hostId??n,i=S(r),a=i?.authMethod===`chatgpt`,o=i?.authMethod??null,s;t[0]!==r||t[1]!==o?(s={authMethod:o,hostId:r},t[0]=r,t[1]=o,t[2]=s):s=t[2];let{data:c,isPending:l}=h(x,s),u=!!i?.isLoading||a&&l,f=a&&!u&&c!=null&&c?.requirements?.featureRequirements?.fast_mode!==!1,p;return t[3]!==u||t[4]!==f?(p={isServiceTierAllowed:f,isLoading:u},t[3]=u,t[4]=f,t[5]=p):p=t[5],p}function j(t){let n=(0,k.c)(12),r=m(e),i;n[0]!==t||n[1]!==r?(i=r.includes(t),n[0]=t,n[1]=r,n[2]=i):i=n[2];let a=i,o;n[3]===t?o=n[4]:(o={hostId:t},n[3]=t,n[4]=o);let{data:c,isLoading:u}=h(C,o),d=h(s,t),f=c?.service_tier??null,p;n[5]!==d||n[6]!==f?(p=l(d,f),n[5]=d,n[6]=f,n[7]=p):p=n[7];let g=p,_=typeof c?.profile==`string`?c.profile:null,v=!a||u,y;return n[8]!==g||n[9]!==_||n[10]!==v?(y={activeProfileForWrite:_,isLoading:v,serviceTier:g},n[8]=g,n[9]=_,n[10]=v,n[11]=y):y=n[11],y}function M(e,n){let r=(0,k.c)(5),a=p(_),o=b(),l;return r[0]!==e||r[1]!==o||r[2]!==n||r[3]!==a?(l=async r=>{let l=i(r);c(`batch-write-config-value`,{hostId:e,edits:[{keyPath:N(n),value:l,mergeStrategy:`upsert`}],filePath:null,expectedVersion:null,reloadUserConfig:!0}),a.set(s,e,t(r)),await Promise.all([o([`config`]),o([...w,e,null])]),await a.query.fetch(C,{hostId:e})},r[0]=e,r[1]=o,r[2]=n,r[3]=a,r[4]=l):l=r[4],l}function N(e){return e==null?`service_tier`:`profiles.${e}.service_tier`}function P(e){let t=(0,k.c)(29),s=e===void 0?null:e,l=p(_),d=O(s),{modelSettings:m}=E(s),v;t[0]===d.hostId?v=t[1]:(v={hostId:d.hostId},t[0]=d.hostId,t[1]=v);let{data:b,isLoading:x}=D(v),S=h(r,s),C=h(o,s),w=j(d.hostId),N=M(d.hostId,w.activeProfileForWrite),P;t[2]===d.hostId?P=t[3]:(P={hostId:d.hostId},t[2]=d.hostId,t[3]=P);let{isServiceTierAllowed:F}=A(P),I,L,R,z,B;if(t[4]!==s||t[5]!==x||t[6]!==F||t[7]!==S||t[8]!==C||t[9]!==b?.models||t[10]!==m.isLoading||t[11]!==m.model||t[12]!==l||t[13]!==N||t[14]!==w.isLoading||t[15]!==w.serviceTier){let e=T(b?.models,m.model),r=s!=null&&S?.serviceTier!==void 0?S.serviceTier:s!=null&&C?.params.serviceTier!==void 0?C.params.serviceTier:w.serviceTier;R=s!=null&&(S?.serviceTier!==void 0||C?.params.serviceTier!==void 0)?F?r:null:u(e,r,F),L=R==null?null:n(e,R);let o=a(R??null);I=m.isLoading||x||w.isLoading,z=async(e,t)=>{let n=i(e)!==w.serviceTier,r=s!=null&&e!==S?.serviceTier;try{r&&await c(`update-thread-settings-for-next-turn`,{conversationId:s,threadSettings:{serviceTier:e}}),n&&await N(e)}catch(e){let t=e;g.error(`Failed to set service tier`,{safe:{},sensitive:{error:t}});return}if(n||r){let n=a(e);if(o===n)return;y(l,{eventName:`codex_service_tier_changed`,metadata:{previous_service_tier:o,service_tier:n,source:t}})}},B=f(e),t[4]=s,t[5]=x,t[6]=F,t[7]=S,t[8]=C,t[9]=b?.models,t[10]=m.isLoading,t[11]=m.model,t[12]=l,t[13]=N,t[14]=w.isLoading,t[15]=w.serviceTier,t[16]=I,t[17]=L,t[18]=R,t[19]=z,t[20]=B}else I=t[16],L=t[17],R=t[18],z=t[19],B=t[20];let V;t[21]!==I||t[22]!==L||t[23]!==R||t[24]!==B?(V={availableOptions:B,isLoading:I,selectedServiceTier:L,serviceTierForRequest:R},t[21]=I,t[22]=L,t[23]=R,t[24]=B,t[25]=V):V=t[25];let H;return t[26]!==z||t[27]!==V?(H={serviceTierSettings:V,setServiceTier:z},t[26]=z,t[27]=V,t[28]=H):H=t[28],H}export{A as n,P as t};
//# sourceMappingURL=use-service-tier-settings-CZz5xU_T.js.map