@@ -28,7 +28,6 @@ type ProviderDiscoveryEntryResult = {
2828 complete : boolean ;
2929 pluginRecords : PluginManifestRecord [ ] ;
3030 entryPluginIds : Set < string > ;
31- manifestEntryPluginIds : Set < string > ;
3231 runtimeManifestCatalogPluginIds : Set < string > ;
3332} ;
3433
@@ -156,22 +155,40 @@ function providerConfigFromManifestRows(
156155 } ;
157156}
158157
159- function resolveManifestModelCatalogProviders (
158+ function prepareManifestCatalogDiscovery (
160159 pluginRecords : readonly PluginManifestRecord [ ] ,
161160 config : OpenClawConfig ,
162- ) : ProviderPlugin [ ] {
161+ includeProviders : boolean ,
162+ ) : Pick < ProviderDiscoveryEntryResult , "providers" | "runtimeManifestCatalogPluginIds" > {
163163 const providers : ProviderPlugin [ ] = [ ] ;
164+ const runtimeManifestCatalogPluginIds = new Set < string > ( ) ;
164165 for ( const plugin of pluginRecords ) {
165- if ( ! plugin . modelCatalog ?. providers ) {
166+ if ( ! plugin . modelCatalog ) {
166167 continue ;
167168 }
169+ const ownedProviders = new Set (
170+ plugin . providers . map ( ( provider ) => normalizeProviderId ( provider ) ) ,
171+ ) ;
172+ if (
173+ Object . entries ( plugin . modelCatalog . discovery ?? { } ) . some (
174+ ( [ provider , discovery ] ) =>
175+ ( discovery === "runtime" || discovery === "refreshable" ) &&
176+ ownedProviders . has ( normalizeProviderId ( provider ) ) ,
177+ )
178+ ) {
179+ runtimeManifestCatalogPluginIds . add ( plugin . id ) ;
180+ }
181+ if ( ! plugin . modelCatalog . providers ) {
182+ continue ;
183+ }
184+ // Static rows and runtime coverage must come from the same effective catalog.
168185 const plan = planEffectiveModelCatalogRows ( { registry : { plugins : [ plugin ] } , config } ) ;
169186 for ( const entry of plan . entries ) {
170- if (
171- entry . rows . length === 0 ||
172- entry . discovery === "runtime" ||
173- entry . discovery === "refreshable"
174- ) {
187+ if ( entry . discovery === "runtime" || entry . discovery === "refreshable" ) {
188+ runtimeManifestCatalogPluginIds . add ( plugin . id ) ;
189+ continue ;
190+ }
191+ if ( ! includeProviders || entry . rows . length === 0 ) {
175192 continue ;
176193 }
177194 const providerConfig = providerConfigFromManifestRows ( entry . rows ) ;
@@ -190,40 +207,7 @@ function resolveManifestModelCatalogProviders(
190207 } ) ;
191208 }
192209 }
193- return providers ;
194- }
195-
196- function resolveRuntimeManifestCatalogPluginIds (
197- pluginRecords : readonly PluginManifestRecord [ ] ,
198- config : OpenClawConfig ,
199- ) : Set < string > {
200- const pluginIds = new Set < string > ( ) ;
201- for ( const plugin of pluginRecords ) {
202- const ownedProviders = new Set (
203- plugin . providers . map ( ( provider ) => normalizeProviderId ( provider ) ) ,
204- ) ;
205- const ownsRuntimeDiscovery = Object . entries ( plugin . modelCatalog ?. discovery ?? { } ) . some (
206- ( [ provider , discovery ] ) =>
207- ( discovery === "runtime" || discovery === "refreshable" ) &&
208- ownedProviders . has ( normalizeProviderId ( provider ) ) ,
209- ) ;
210- if ( ownsRuntimeDiscovery ) {
211- pluginIds . add ( plugin . id ) ;
212- }
213-
214- if ( ! plugin . modelCatalog ?. providers ) {
215- continue ;
216- }
217- const plan = planEffectiveModelCatalogRows ( { registry : { plugins : [ plugin ] } , config } ) ;
218- if (
219- plan . entries . some (
220- ( entry ) => entry . discovery === "runtime" || entry . discovery === "refreshable" ,
221- )
222- ) {
223- pluginIds . add ( plugin . id ) ;
224- }
225- }
226- return pluginIds ;
210+ return { providers, runtimeManifestCatalogPluginIds } ;
227211}
228212
229213function resolveProviderDiscoveryEntryPlugins ( params : {
@@ -253,17 +237,14 @@ function resolveProviderDiscoveryEntryPlugins(params: {
253237 } ) ;
254238 const pluginIdSet = new Set ( pluginIds ) ;
255239 const pluginRecords = manifestRegistry . plugins . filter ( ( plugin ) => pluginIdSet . has ( plugin . id ) ) ;
256- const config = params . config ?? { } ;
257- const runtimeManifestCatalogPluginIds = resolveRuntimeManifestCatalogPluginIds (
258- pluginRecords ,
259- config ,
260- ) ;
240+ const { providers : manifestProviders , runtimeManifestCatalogPluginIds } =
241+ prepareManifestCatalogDiscovery (
242+ pluginRecords ,
243+ params . config ?? { } ,
244+ params . includeManifestModelCatalogProviders !== false ,
245+ ) ;
261246 const entryRecords = pluginRecords . filter ( ( plugin ) => plugin . providerDiscoverySource ) ;
262247 const entryPluginIds = new Set ( entryRecords . map ( ( plugin ) => plugin . id ) ) ;
263- const manifestProviders =
264- params . includeManifestModelCatalogProviders === false
265- ? [ ]
266- : resolveManifestModelCatalogProviders ( pluginRecords , config ) ;
267248 const manifestEntryPluginIds = new Set < string > ( ) ;
268249 for ( const pluginId of manifestProviders . map ( ( provider ) => provider . pluginId ) ) {
269250 if ( pluginId ) {
@@ -276,30 +257,23 @@ function resolveProviderDiscoveryEntryPlugins(params: {
276257 }
277258 }
278259 const complete = entryPluginIds . size === pluginIdSet . size ;
260+ const result = {
261+ providers : manifestProviders ,
262+ complete,
263+ pluginRecords,
264+ entryPluginIds,
265+ runtimeManifestCatalogPluginIds,
266+ } ;
279267 const entriesOnlyComplete =
280268 new Set ( [ ...entryPluginIds , ...manifestEntryPluginIds ] ) . size === pluginIdSet . size ;
281269 if ( entryRecords . length === 0 ) {
282- return {
283- providers : manifestProviders ,
284- complete,
285- pluginRecords,
286- entryPluginIds,
287- manifestEntryPluginIds,
288- runtimeManifestCatalogPluginIds,
289- } ;
270+ return result ;
290271 }
291272 if (
292273 params . requireCompleteDiscoveryEntryCoverage &&
293274 ! ( params . discoveryEntriesOnly === true ? entriesOnlyComplete : complete )
294275 ) {
295- return {
296- providers : [ ] ,
297- complete : false ,
298- pluginRecords,
299- entryPluginIds,
300- manifestEntryPluginIds,
301- runtimeManifestCatalogPluginIds,
302- } ;
276+ return { ...result , providers : [ ] , complete : false } ;
303277 }
304278 const providers : ProviderPlugin [ ] = [ ] ;
305279 for ( const manifest of entryRecords ) {
@@ -315,51 +289,12 @@ function resolveProviderDiscoveryEntryPlugins(params: {
315289 ) ,
316290 ) ;
317291 } catch {
318- // Discovery fast path is optional. Fall back to the full plugin loader
319- // below so existing plugin diagnostics/load behavior remains canonical.
320- return {
321- providers : manifestProviders ,
322- complete : false ,
323- pluginRecords,
324- entryPluginIds,
325- manifestEntryPluginIds,
326- runtimeManifestCatalogPluginIds,
327- } ;
292+ // Entry loading is all-or-nothing: discarded results no longer cover their owners.
293+ // Keep static manifest coverage for the scope-aware full-loader fallback.
294+ return { ...result , complete : false , entryPluginIds : manifestEntryPluginIds } ;
328295 }
329296 }
330- return {
331- providers : [ ...manifestProviders , ...providers ] ,
332- complete,
333- pluginRecords,
334- entryPluginIds,
335- manifestEntryPluginIds,
336- runtimeManifestCatalogPluginIds,
337- } ;
338- }
339-
340- function resolveSelectiveFullPluginIds ( params : {
341- entryResult : ProviderDiscoveryEntryResult ;
342- env : NodeJS . ProcessEnv ;
343- } ) : string [ ] {
344- const missingEntryCredentialPluginIds = params . entryResult . pluginRecords
345- . filter ( ( plugin ) => ! params . entryResult . entryPluginIds . has ( plugin . id ) )
346- . filter ( ( plugin ) => hasProviderAuthEnvCredential ( plugin , params . env ) )
347- . map ( ( plugin ) => plugin . id ) ;
348- const runtimeManifestCatalogPluginIds = listRuntimeManifestCatalogPluginIds ( params . entryResult ) ;
349- return sortUniqueStrings ( [
350- ...missingEntryCredentialPluginIds ,
351- ...runtimeManifestCatalogPluginIds ,
352- ] ) ;
353- }
354-
355- function listRuntimeManifestCatalogPluginIds ( entryResult : ProviderDiscoveryEntryResult ) : string [ ] {
356- return [ ...entryResult . runtimeManifestCatalogPluginIds ] ;
357- }
358-
359- function resolveMissingEntryPluginIds ( entryResult : ProviderDiscoveryEntryResult ) : string [ ] {
360- return entryResult . pluginRecords
361- . filter ( ( plugin ) => ! entryResult . entryPluginIds . has ( plugin . id ) )
362- . map ( ( plugin ) => plugin . id ) ;
297+ return { ...result , providers : [ ...manifestProviders , ...providers ] } ;
363298}
364299
365300function resolveRuntimeEntryProviders ( entryResult : ProviderDiscoveryEntryResult ) : ProviderPlugin [ ] {
@@ -375,17 +310,6 @@ function resolveRuntimeEntryProviders(entryResult: ProviderDiscoveryEntryResult)
375310 } ) ;
376311}
377312
378- function withoutFullLoadedPluginEntries (
379- providers : ProviderPlugin [ ] ,
380- pluginIds : readonly string [ ] ,
381- ) : ProviderPlugin [ ] {
382- if ( pluginIds . length === 0 ) {
383- return providers ;
384- }
385- const pluginIdSet = new Set ( pluginIds ) ;
386- return providers . filter ( ( provider ) => ! provider . pluginId || ! pluginIdSet . has ( provider . pluginId ) ) ;
387- }
388-
389313export function resolvePluginDiscoveryProvidersRuntime ( params : {
390314 config ?: OpenClawConfig ;
391315 workspaceDir ?: string ;
@@ -418,45 +342,42 @@ export function resolvePluginDiscoveryProvidersRuntime(params: {
418342 ) {
419343 return runtimeEntryProviders ;
420344 }
345+ let fullPluginIds = params . onlyPluginIds ;
346+ let retainedProviders : ProviderPlugin [ ] | undefined ;
421347 if ( runtimeEntryProviders . length > 0 || entryResult . runtimeManifestCatalogPluginIds . size > 0 ) {
422348 // Runtime manifest owners do not cover siblings without discovery entries.
423349 // Preserve the selected scope; unscoped discovery stays credential-bounded.
424- const fullPluginIds =
425- params . onlyPluginIds === undefined
426- ? resolveSelectiveFullPluginIds ( { entryResult, env } )
427- : sortUniqueStrings ( [
428- ...resolveMissingEntryPluginIds ( entryResult ) ,
429- ...listRuntimeManifestCatalogPluginIds ( entryResult ) ,
430- ] ) ;
431- const fullProviders =
432- fullPluginIds . length > 0
433- ? resolvePluginProvidersCore ( {
434- ...params ,
435- env,
436- onlyPluginIds : fullPluginIds ,
437- } )
438- : [ ] ;
439- return [
440- ...withoutFullLoadedPluginEntries ( runtimeEntryProviders , fullPluginIds ) ,
441- ...fullProviders ,
442- ] ;
443- }
444- if ( entryProviders . length > 0 ) {
445- const fullPluginIds = sortUniqueStrings (
350+ fullPluginIds = sortUniqueStrings ( [
351+ ...entryResult . pluginRecords
352+ . filter (
353+ ( plugin ) =>
354+ ! entryResult . entryPluginIds . has ( plugin . id ) &&
355+ ( params . onlyPluginIds !== undefined || hasProviderAuthEnvCredential ( plugin , env ) ) ,
356+ )
357+ . map ( ( plugin ) => plugin . id ) ,
358+ ...entryResult . runtimeManifestCatalogPluginIds ,
359+ ] ) ;
360+ if ( fullPluginIds . length === 0 ) {
361+ return [ ...runtimeEntryProviders ] ;
362+ }
363+ const fullPluginIdSet = new Set ( fullPluginIds ) ;
364+ retainedProviders = runtimeEntryProviders . filter (
365+ ( provider ) => ! provider . pluginId || ! fullPluginIdSet . has ( provider . pluginId ) ,
366+ ) ;
367+ } else if ( entryProviders . length > 0 ) {
368+ const entryPluginIds = sortUniqueStrings (
446369 entryProviders
447370 . map ( ( provider ) => provider . pluginId )
448371 . filter ( ( pluginId ) : pluginId is string => typeof pluginId === "string" && pluginId !== "" ) ,
449372 ) ;
450- if ( fullPluginIds . length > 0 ) {
451- return resolvePluginProvidersCore ( {
452- ...params ,
453- env,
454- onlyPluginIds : fullPluginIds ,
455- } ) ;
373+ if ( entryPluginIds . length > 0 ) {
374+ fullPluginIds = entryPluginIds ;
456375 }
457376 }
458- return resolvePluginProvidersCore ( {
377+ const fullProviders = resolvePluginProvidersCore ( {
459378 ...params ,
460379 env,
380+ ...( fullPluginIds ? { onlyPluginIds : fullPluginIds } : { } ) ,
461381 } ) ;
382+ return retainedProviders ? [ ...retainedProviders , ...fullProviders ] : fullProviders ;
462383}
0 commit comments