import{c as e}from"./home-dir-C44RaPME-B5iLWwCq.mjs";import{a as t}from"./runtime-Cym-fqI8-1GOIuRRQ.mjs";import{n,r,t as i}from"./loader-708jrx4Y-BbJRXNlQ.mjs";import{_ as a,v as o}from"./plugin-auto-enable-DdH3n9V8-Dr_bUXkG.mjs";import{r as s}from"./activation-context--5yu1dPF-XV0Y0pTy.mjs";import{n as c,t as l}from"./load-context-mb7uvLSn-3xYwSnOZ.mjs";import{i as u,l as d,n as f,o as p,r as m,s as h}from"./web-provider-public-artifacts-BlpRwIUS-DbVhDOrY.mjs";function g(t){return!(e(t.OPENCLAW_DISABLE_PLUGIN_DISCOVERY_CACHE)||e(t.OPENCLAW_DISABLE_PLUGIN_MANIFEST_CACHE)||e(t.OPENCLAW_PLUGIN_DISCOVERY_CACHE_MS)===`0`||e(t.OPENCLAW_PLUGIN_MANIFEST_CACHE_MS)===`0`)}function _(t,n){let r=e(t);if(r===``||r===`0`)return 0;if(!r)return n;let i=Number.parseInt(r,10);return Number.isFinite(i)?Math.max(0,i):n}function v(e){let t=_(e.OPENCLAW_PLUGIN_DISCOVERY_CACHE_MS,1e3),n=_(e.OPENCLAW_PLUGIN_MANIFEST_CACHE_MS,1e3);return Math.min(t,n)}function y(e){return JSON.stringify({OPENCLAW_BUNDLED_PLUGINS_DIR:e.OPENCLAW_BUNDLED_PLUGINS_DIR??``,OPENCLAW_DISABLE_PLUGIN_DISCOVERY_CACHE:e.OPENCLAW_DISABLE_PLUGIN_DISCOVERY_CACHE??``,OPENCLAW_DISABLE_PLUGIN_MANIFEST_CACHE:e.OPENCLAW_DISABLE_PLUGIN_MANIFEST_CACHE??``,OPENCLAW_PLUGIN_DISCOVERY_CACHE_MS:e.OPENCLAW_PLUGIN_DISCOVERY_CACHE_MS??``,OPENCLAW_PLUGIN_MANIFEST_CACHE_MS:e.OPENCLAW_PLUGIN_MANIFEST_CACHE_MS??``,OPENCLAW_HOME:e.OPENCLAW_HOME??``,OPENCLAW_STATE_DIR:e.OPENCLAW_STATE_DIR??``,OPENCLAW_CONFIG_PATH:e.OPENCLAW_CONFIG_PATH??``,HOME:e.HOME??``,USERPROFILE:e.USERPROFILE??``,VITEST:e.VITEST??``})}function b(){return new WeakMap}function x(e,n){let r=e.env??process.env,i=e.workspaceDir??t(),{config:s,activationSourceConfig:u,autoEnabledReasons:d}=n.resolveBundledResolutionConfig({...e,workspaceDir:i,env:r}),f=o(n.resolveCandidatePluginIds({config:s,workspaceDir:i,env:r,onlyPluginIds:e.onlyPluginIds,origin:e.origin}));return l({env:r,config:s,activationSourceConfig:u,autoEnabledReasons:d,workspaceDir:i,logger:c()},{cache:e.cache??!1,activate:e.activate??!1,...a(f)?{onlyPluginIds:f}:{}})}function S(e,a){let o=e.env??process.env,u=e.workspaceDir??t();if(e.mode===`setup`){let t=a.resolveCandidatePluginIds({config:e.config,workspaceDir:u,env:o,onlyPluginIds:e.onlyPluginIds,origin:e.origin})??[];if(t.length===0)return[];if(e.activate!==!0){let n=a.resolveBundledPublicArtifactProviders?.({config:e.config,workspaceDir:u,env:o,bundledAllowlistCompat:e.bundledAllowlistCompat,onlyPluginIds:t});if(n)return n}let r=n(l({config:s({config:e.config,pluginIds:t}),activationSourceConfig:e.config,autoEnabledReasons:{},workspaceDir:u,env:o,logger:c()},{onlyPluginIds:t,cache:e.cache??!1,activate:e.activate??!1}));return a.mapRegistryProviders({registry:r,onlyPluginIds:t})}let d=e.config,f=e.activate!==!0&&e.cache!==!0&&g(o),p=m({config:d,workspaceDir:u,bundledAllowlistCompat:e.bundledAllowlistCompat,onlyPluginIds:e.onlyPluginIds,origin:e.origin,envKey:y(o)});if(d&&f){let e=(a.snapshotCache.get(d)?.get(o))?.get(p);if(e&&e.expiresAt>Date.now())return e.providers}let h=e=>{if(!d||!f)return;let t=v(o),n=a.snapshotCache.get(d);n||(n=new WeakMap,a.snapshotCache.set(d,n));let r=n.get(o);r||(r=new Map,n.set(o,r)),r.set(p,{expiresAt:Date.now()+t,providers:e})},_=x(e,a),b=r(_);if(b){let t=a.mapRegistryProviders({registry:b,onlyPluginIds:e.onlyPluginIds});return h(t),t}if(i(_))return[];let S=a.mapRegistryProviders({registry:n(_),onlyPluginIds:e.onlyPluginIds});return h(S),S}let C=b();function w(e){return h({contract:`webSearchProviders`,configKey:`webSearch`,config:e.config,workspaceDir:e.workspaceDir,env:e.env,onlyPluginIds:e.onlyPluginIds,origin:e.origin})}function T(e){return u({entries:e.registry.webSearchProviders,onlyPluginIds:e.onlyPluginIds,sortProviders:d})}function E(e){return S(e,{snapshotCache:C,resolveBundledResolutionConfig:p,resolveCandidatePluginIds:w,mapRegistryProviders:T,resolveBundledPublicArtifactProviders:f})}export{b as n,S as r,E as t};