UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.62 kB
import{c as normalizeOptionalLowercaseString}from"./string-coerce-CpTFcSwY.mjs";import{c as normalizePluginId}from"./config-state-C1eV6UWf.mjs";import{t as compileSafeRegex}from"./safe-regex-DzqdzmXn.mjs";import{m as hasMissingConfigPathActivationMetadata,v as getInstalledPluginIndexFacts}from"./installed-plugin-index-B04a42mO.mjs";import{t as normalizeLowercaseStringSet}from"./normalized-string-set-BuDEgK2s.mjs"; //!src/plugins/installed-plugin-index-scope-lookup.ts const PROVIDER_CONTRIBUTION_CONTRACTS=[`externalAuthProviders`,`embeddingProviders`,`decisionProviders`,`speechProviders`,`realtimeTranscriptionProviders`,`realtimeVoiceProviders`,`mediaUnderstandingProviders`,`transcriptSourceProviders`,`meetingNotesSourceProviders`,`imageGenerationProviders`,`videoGenerationProviders`,`musicGenerationProviders`,`webFetchProviders`,`webSearchProviders`,`workerProviders`,`storageProviders`,`usageProviders`];function createOwnerLookup(){const e=/* @__PURE__ */ new Map;const resolve=t=>e.get(normalizeOptionalLowercaseString(t)??``);return{index(t,n){for(const r of n){const n=normalizeOptionalLowercaseString(r);if(n){const r=e.get(n)??/* @__PURE__ */ new Set;r.add(t);e.set(n,r)}}},add:(e,t)=>{for(const n of t)for(const t of resolve(n)??[])e.add(t)},has:e=>e.every(e=>resolve(e)!==void 0)}}function modelSupportOwnerMatches(e,t){const n=t.trim();if(!n)return false;if(e.prefixes.some(e=>n.startsWith(e)))return true;return e.patterns.some(e=>e.test(n))}function createInstalledPluginIndexScopeLookup(e){const t=getInstalledPluginIndexFacts(e);if(t?.scopeLookup)return{...t.scopeLookup};const n=createOwnerLookup();const r=createOwnerLookup();const i=createOwnerLookup();const a=createOwnerLookup();const o=createOwnerLookup();const s=/* @__PURE__ */ new Map;const c=[];for(const t of e.plugins){const e=normalizeOptionalLowercaseString(t.pluginId);if(e){s.set(e,t.pluginId);a.index(t.pluginId,[t.pluginId])}i.index(t.pluginId,[t.pluginId,t.packageChannel?.id]);n.index(t.pluginId,t.startup.agentHarnesses);r.index(t.pluginId,[t.pluginId,t.packageChannel?.id,...t.contributions?.channels??[],...t.contributions?.channelConfigs??[]]);o.index(t.pluginId,[t.pluginId,...t.contributions?.providers??[],...t.contributions?.modelCatalogProviders??[],...t.contributions?.autoEnableProviderIds??[],...PROVIDER_CONTRIBUTION_CONTRACTS.flatMap(e=>t.contributions?.contracts?.[e]??[])]);c.push({pluginId:t.pluginId,prefixes:t.contributions?.modelSupportPrefixes??[],patterns:(t.contributions?.modelSupportPatterns??[]).flatMap(e=>{const t=compileSafeRegex(e,`u`);return t?[t]:[]})})}const normalizeInstalledPluginId=e=>{const t=normalizePluginId(e);const n=normalizeOptionalLowercaseString(t);return n?s.get(n)??t:t};const l={addAgentHarnessOwners:n.add,addDirectChannelOwners:i.add,addDirectProviderOwners:a.add,addProviderContributionOwners:o.add,addShorthandModelOwners:(e,t)=>{for(const n of t)for(const t of c)if(modelSupportOwnerMatches(t,n))e.add(t.pluginId)},canResolveDirectProviderIds:(e,t)=>{const n=normalizeLowercaseStringSet(t);return e.every(e=>{const t=normalizeOptionalLowercaseString(e);return Boolean(t&&(a.has([t])||n.has(t)))})},hasChannelContributionOwners:r.has,hasAgentHarnessOwners:n.has,hasCompleteConfigPathActivationMetadata:()=>!hasMissingConfigPathActivationMetadata(e),hasDirectChannelOwners:i.has,hasInstalledPluginIds:e=>a.has([...e]),hasProviderContributionOwners:o.has,hasShorthandModelOwners:e=>e.every(e=>c.some(t=>modelSupportOwnerMatches(t,e))),normalizePluginId:normalizeInstalledPluginId};if(t)t.scopeLookup={...l};return l}export{createInstalledPluginIndexScopeLookup as t};