@@ -31,36 +31,13 @@ type CapabilityProviderRegistryKey =
3131 | "videoGenerationProviders"
3232 | "musicGenerationProviders" ;
3333
34- type CapabilityContractKey =
35- | "embeddingProviders"
36- | "speechProviders"
37- | "realtimeTranscriptionProviders"
38- | "realtimeVoiceProviders"
39- | "mediaUnderstandingProviders"
40- | "transcriptSourceProviders"
41- | "imageGenerationProviders"
42- | "videoGenerationProviders"
43- | "musicGenerationProviders" ;
44-
4534export type CapabilityProviderFor < K extends CapabilityProviderRegistryKey > =
4635 PluginRegistry [ K ] [ number ] [ "provider" ] ;
4736type CapabilityPluginResolution = {
4837 runtimePluginIds : string [ ] ;
4938 bundledCompatPluginIds : string [ ] ;
5039} ;
5140
52- const CAPABILITY_CONTRACT_KEY : Record < CapabilityProviderRegistryKey , CapabilityContractKey > = {
53- embeddingProviders : "embeddingProviders" ,
54- speechProviders : "speechProviders" ,
55- realtimeTranscriptionProviders : "realtimeTranscriptionProviders" ,
56- realtimeVoiceProviders : "realtimeVoiceProviders" ,
57- mediaUnderstandingProviders : "mediaUnderstandingProviders" ,
58- transcriptSourceProviders : "transcriptSourceProviders" ,
59- imageGenerationProviders : "imageGenerationProviders" ,
60- videoGenerationProviders : "videoGenerationProviders" ,
61- musicGenerationProviders : "musicGenerationProviders" ,
62- } ;
63-
6441function shouldMergeManifestProvidersWhenActive ( key : CapabilityProviderRegistryKey ) : boolean {
6542 return (
6643 key === "imageGenerationProviders" ||
@@ -98,13 +75,12 @@ function resolveCapabilityPluginIds(params: {
9875 providerId ?: string ;
9976 pluginMetadataSnapshot ?: Pick < PluginMetadataSnapshot , "index" | "plugins" > ;
10077} ) : CapabilityPluginResolution {
101- const contractKey = CAPABILITY_CONTRACT_KEY [ params . key ] ;
10278 const snapshot = loadCapabilityManifestSnapshot ( params ) ;
10379 const availableContractPlugins = snapshot . plugins . filter (
10480 ( plugin ) =>
10581 hasManifestContractValue ( {
10682 plugin,
107- contract : contractKey ,
83+ contract : params . key ,
10884 value : params . providerId ,
10985 } ) &&
11086 isManifestPluginAvailableForControlPlane ( {
@@ -181,30 +157,6 @@ function findProviderById<K extends CapabilityProviderRegistryKey>(
181157 return undefined ;
182158}
183159
184- function mergeCapabilityProviders < K extends CapabilityProviderRegistryKey > (
185- left : PluginRegistry [ K ] ,
186- right : PluginRegistry [ K ] ,
187- ) : CapabilityProviderFor < K > [ ] {
188- const merged = new Map < string , CapabilityProviderFor < K > > ( ) ;
189- const unnamed : CapabilityProviderFor < K > [ ] = [ ] ;
190- const addEntries = ( entries : PluginRegistry [ K ] ) => {
191- for ( const entry of entries ) {
192- const provider = entry . provider as CapabilityProviderFor < K > & { id ?: string } ;
193- if ( ! provider . id ) {
194- unnamed . push ( provider ) ;
195- continue ;
196- }
197- if ( ! merged . has ( provider . id ) ) {
198- merged . set ( provider . id , provider ) ;
199- }
200- }
201- } ;
202-
203- addEntries ( left ) ;
204- addEntries ( right ) ;
205- return [ ...merged . values ( ) , ...unnamed ] ;
206- }
207-
208160function mergeCapabilityProviderEntries < K extends CapabilityProviderRegistryKey > (
209161 left : PluginRegistry [ K ] ,
210162 right : PluginRegistry [ K ] ,
@@ -460,23 +412,14 @@ function loadCapabilityProviderEntries<K extends CapabilityProviderRegistryKey>(
460412 ( registry ?. [ params . key ] ?? [ ] ) . filter ( ( entry ) =>
461413 allowedPluginIds . has ( entry . pluginId ) ,
462414 ) as PluginRegistry [ K ] ;
463- const loadedRegistry = getLoadedRuntimePluginRegistry ( {
464- env : params . loadOptions . env ,
465- loadOptions : params . loadOptions ,
466- workspaceDir : params . loadOptions . workspaceDir ,
467- requiredPluginIds : params . loadOptions . onlyPluginIds ,
468- } ) ;
469- const loadedEntries = filterAllowedEntries ( loadedRegistry ) ;
470- const coldRegistry = loadedRegistry
471- ? undefined
472- : resolveRuntimePluginRegistry ( params . loadOptions ) ;
473- const coldEntries = filterAllowedEntries ( coldRegistry ) ;
474- const entries =
475- loadedEntries . length > 0 && coldEntries . length > 0
476- ? mergeCapabilityProviderEntries ( loadedEntries , coldEntries )
477- : loadedEntries . length > 0
478- ? loadedEntries
479- : coldEntries ;
415+ const registry =
416+ getLoadedRuntimePluginRegistry ( {
417+ env : params . loadOptions . env ,
418+ loadOptions : params . loadOptions ,
419+ workspaceDir : params . loadOptions . workspaceDir ,
420+ requiredPluginIds : params . loadOptions . onlyPluginIds ,
421+ } ) ?? resolveRuntimePluginRegistry ( params . loadOptions ) ;
422+ const entries = filterAllowedEntries ( registry ) ;
480423 const missingRequested =
481424 params . requested && params . requested . size > 0 ? new Set ( params . requested ) : undefined ;
482425 if ( missingRequested ) {
@@ -645,7 +588,9 @@ export function resolvePluginCapabilityProviders<K extends CapabilityProviderReg
645588 entries : requestedLoadedProviders ,
646589 } )
647590 : requestedLoadedProviders ;
648- return mergeCapabilityProviders ( activeProviders , mergeLoadedProviders ) ;
591+ return mergeCapabilityProviderEntries ( activeProviders , mergeLoadedProviders ) . map (
592+ ( entry ) => entry . provider as CapabilityProviderFor < K > ,
593+ ) ;
649594}
650595
651596export function prepareMediaCapabilityProviders ( params : {
@@ -670,7 +615,7 @@ export function prepareMediaCapabilityProviders(params: {
670615 params . pluginMetadataSnapshot . plugins . some ( ( plugin ) =>
671616 hasManifestContractValue ( {
672617 plugin,
673- contract : CAPABILITY_CONTRACT_KEY [ key ] ,
618+ contract : key ,
674619 } ) ,
675620 )
676621 ) {
0 commit comments