import{s as e}from"./home-dir-C44RaPME-B5iLWwCq.mjs";import{l as t}from"./bundled-compat-BpaDaAAu-DJtrIX6i.mjs";import{o as n}from"./manifest-registry-_hxKCS2K-OL8KK_o4.mjs";import{a as r}from"./runtime-Cym-fqI8-1GOIuRRQ.mjs";import{i,n as a,t as o}from"./loader-708jrx4Y-BbJRXNlQ.mjs";import{_ as s,a as c,d as l,f as u,g as d,n as f,o as p,r as m,s as h,u as g,v as _}from"./plugin-auto-enable-DdH3n9V8-Dr_bUXkG.mjs";import{r as v,t as y}from"./activation-context--5yu1dPF-XV0Y0pTy.mjs";import{n as b,t as x}from"./load-context-mb7uvLSn-3xYwSnOZ.mjs";function S(e){let t=d(_(e.onlyPluginIds));return[...new Set(n({config:e.config,workspaceDir:e.workspaceDir,env:e.env,cache:e.cache}).plugins.filter(n=>(!e.origin||n.origin===e.origin)&&(!t||t.has(n.id))&&C(n,e.trigger)).map(e=>e.id))].toSorted((e,t)=>e.localeCompare(t))}function C(e,n){switch(n.kind){case`command`:return T(e).includes(A(n.command));case`provider`:return E(e).includes(t(n.provider));case`agentHarness`:return w(e).includes(A(n.runtime));case`channel`:return D(e).includes(A(n.channel));case`route`:return O(e).includes(A(n.route));case`capability`:return k(e,n.capability)}return n}function w(e){return[...e.activation?.onAgentHarnesses??[]].map(A).filter(Boolean)}function T(e){return[...e.activation?.onCommands??[],...(e.commandAliases??[]).flatMap(e=>e.cliCommand??e.name)].map(A).filter(Boolean)}function E(e){return[...e.activation?.onProviders??[],...e.providers,...e.setup?.providers?.map(e=>e.id)??[]].map(e=>t(e)).filter(Boolean)}function D(e){return[...e.activation?.onChannels??[],...e.channels].map(A).filter(Boolean)}function O(e){return(e.activation?.onRoutes??[]).map(A).filter(Boolean)}function k(e,t){if(e.activation?.onCapabilities?.includes(t))return!0;switch(t){case`provider`:return E(e).length>0;case`channel`:return D(e).length>0;case`tool`:return(e.contracts?.tools?.length??0)>0;case`hook`:return e.hooks.length>0}return t}function A(t){return e(t)??``}function j(e){return[...new Set(e)].toSorted((e,t)=>e.localeCompare(t))}function M(e){return j(e.providerRefs.flatMap(t=>{let n=S({trigger:{kind:`provider`,provider:t},config:e.config,workspaceDir:e.workspaceDir,env:e.env});return n.length>0?n:l({provider:t,config:e.config,workspaceDir:e.workspaceDir,env:e.env})??[]}))}function N(e,t){return t.length===0?[...e]:j([...e,...t])}function P(e){let t=e.env??process.env,n=e.workspaceDir??r(),i=e.providerRefs?.length?M({providerRefs:e.providerRefs,config:e.config,workspaceDir:n,env:t}):[],a=e.modelRefs?.length?g({models:e.modelRefs,config:e.config,workspaceDir:n,env:t}):[];return{env:t,workspaceDir:n,requestedPluginIds:s(e.onlyPluginIds)||e.providerRefs?.length||e.modelRefs?.length||i.length>0||a.length>0?[...new Set([...e.onlyPluginIds??[],...i,...a])].toSorted((e,t)=>e.localeCompare(t)):void 0,explicitOwnerPluginIds:j([...i,...a]),rawConfig:e.config}}function F(e,t){let n=N(p({config:e.config,workspaceDir:t.workspaceDir,env:t.env,onlyPluginIds:t.requestedPluginIds,includeUntrustedWorkspacePlugins:e.includeUntrustedWorkspacePlugins}),c({pluginIds:t.explicitOwnerPluginIds,config:e.config,workspaceDir:t.workspaceDir,env:t.env,includeUntrustedWorkspacePlugins:e.includeUntrustedWorkspacePlugins}));if(n.length===0)return;let r=v({config:t.rawConfig,pluginIds:n});return{loadOptions:x({config:r,activationSourceConfig:r,autoEnabledReasons:{},workspaceDir:t.workspaceDir,env:t.env,logger:b()},{onlyPluginIds:n,pluginSdkResolution:e.pluginSdkResolution,cache:e.cache??!1,activate:e.activate??!1})}}function I(e,t){let n=f({pluginIds:t.explicitOwnerPluginIds,config:t.rawConfig,workspaceDir:t.workspaceDir,env:t.env,includeUntrustedWorkspacePlugins:e.includeUntrustedWorkspacePlugins}),r=t.requestedPluginIds===void 0?void 0:j([...e.onlyPluginIds??[],...n]),i=y({rawConfig:v({config:t.rawConfig,pluginIds:n}),env:t.env,workspaceDir:t.workspaceDir,onlyPluginIds:r,applyAutoEnable:!0,compatMode:{allowlist:e.bundledProviderAllowlistCompat,enablement:`allowlist`,vitest:e.bundledProviderVitestCompat},resolveCompatPluginIds:m}),a=e.bundledProviderVitestCompat?u({config:i.config,pluginIds:i.compatPluginIds,env:t.env}):i.config,o=N(h({config:a,workspaceDir:t.workspaceDir,env:t.env,onlyPluginIds:r}),n);return{loadOptions:x({config:a,activationSourceConfig:i.activationSourceConfig,autoEnabledReasons:i.autoEnabledReasons,workspaceDir:t.workspaceDir,env:t.env,logger:b()},{onlyPluginIds:o,pluginSdkResolution:e.pluginSdkResolution,cache:e.cache??!1,activate:e.activate??!1})}}function L(e){let t=P(e),n=e.mode===`setup`?F(e,t):I(e,t);return n?o(n.loadOptions):!1}function R(e){let t=P(e);if(e.mode===`setup`){let n=F(e,t);return n?a(n.loadOptions).providers.map(e=>Object.assign({},e.provider,{pluginId:e.pluginId})):[]}let n=i(I(e,t).loadOptions);return n?n.providers.map(e=>Object.assign({},e.provider,{pluginId:e.pluginId})):[]}export{R as n,L as t};