import{r as e}from"./wsl-Ok7GaSJ6.js";function t(e){if(!e||typeof e!=`object`||!(`fallbacks`in e))return;let t=e.fallbacks;return Array.isArray(t)?t.map(e=>String(e)):void 0}function n(e,t){return{...e,agents:{...e.agents,defaults:{...e.agents?.defaults,models:t.agentModels}},models:{mode:e.models?.mode??`merge`,providers:t.providers}}}function r(e,n){let r=t(e.agents?.defaults?.model);return{...e,agents:{...e.agents,defaults:{...e.agents?.defaults,model:{...r?{fallbacks:r}:void 0,primary:n}}}}}function i(e,t){let n=s(e,t.providerId),r=t.defaultModels,i=t.defaultModelId??r[0]?.id,a=i?n.existingModels.some(e=>e.id===i):!0,o=n.existingModels.length>0?a||r.length===0?n.existingModels:[...n.existingModels,...r]:r;return c(e,{agentModels:t.agentModels,providerId:t.providerId,providerState:n,api:t.api,baseUrl:t.baseUrl,mergedModels:o,fallbackModels:r})}function a(e,t){return i(e,{agentModels:t.agentModels,providerId:t.providerId,api:t.api,baseUrl:t.baseUrl,defaultModels:[t.defaultModel],defaultModelId:t.defaultModelId??t.defaultModel.id})}function o(e,t){let n=s(e,t.providerId),r=t.catalogModels,i=n.existingModels.length>0?[...n.existingModels,...r.filter(e=>!n.existingModels.some(t=>t.id===e.id))]:r;return c(e,{agentModels:t.agentModels,providerId:t.providerId,providerState:n,api:t.api,baseUrl:t.baseUrl,mergedModels:i,fallbackModels:r})}function s(e,t){let n={...e.models?.providers},r=n[t];return{providers:n,existingProvider:r,existingModels:Array.isArray(r?.models)?r.models:[]}}function c(e,t){return t.providerState.providers[t.providerId]=l({existingProvider:t.providerState.existingProvider,api:t.api,baseUrl:t.baseUrl,mergedModels:t.mergedModels,fallbackModels:t.fallbackModels}),n(e,{agentModels:t.agentModels,providers:t.providerState.providers})}function l(e){let{apiKey:t,...n}=e.existingProvider??{},r=typeof t==`string`?t.trim():void 0;return{...n,baseUrl:e.baseUrl,api:e.api,...r?{apiKey:r}:{},models:e.mergedModels.length>0?e.mergedModels:e.fallbackModels}}function u(){return!!(process.env.SSH_CLIENT||process.env.SSH_TTY||process.env.SSH_CONNECTION||process.env.REMOTE_CONTAINERS||process.env.CODESPACES||process.platform===`linux`&&!process.env.DISPLAY&&!process.env.WAYLAND_DISPLAY&&!e())}export{i as a,a as i,r as n,o,n as r,u as t};
