@@ -8,7 +8,6 @@ import type {
88 BundledChannelEntryContract ,
99 BundledChannelSetupEntryContract ,
1010} from "../../plugin-sdk/channel-entry-contract.js" ;
11- import { discoverOpenClawPlugins } from "../../plugins/discovery.js" ;
1211import { loadPluginManifestRegistry } from "../../plugins/manifest-registry.js" ;
1312import type { PluginRuntime } from "../../plugins/runtime/types.js" ;
1413import {
@@ -24,20 +23,6 @@ type GeneratedBundledChannelEntry = {
2423 setupEntry ?: BundledChannelSetupEntryContract ;
2524} ;
2625
27- type BundledChannelDiscoveryCandidate = {
28- rootDir : string ;
29- packageManifest ?: {
30- extensions ?: string [ ] ;
31- } ;
32- } ;
33-
34- const BUNDLED_CHANNEL_ENTRY_BASENAMES = [
35- "channel-entry.ts" ,
36- "channel-entry.mts" ,
37- "channel-entry.js" ,
38- "channel-entry.mjs" ,
39- ] as const ;
40-
4126const log = createSubsystemLogger ( "channels" ) ;
4227const nodeRequire = createRequire ( import . meta. url ) ;
4328
@@ -155,53 +140,19 @@ function resolveCompiledBundledModulePath(modulePath: string): string {
155140 : modulePath ;
156141}
157142
158- function resolvePreferredBundledChannelSource (
159- candidate : BundledChannelDiscoveryCandidate ,
160- manifest : ReturnType < typeof loadPluginManifestRegistry > [ "plugins" ] [ number ] ,
161- ) : string {
162- for ( const basename of BUNDLED_CHANNEL_ENTRY_BASENAMES ) {
163- const preferred = resolveCompiledBundledModulePath ( path . resolve ( candidate . rootDir , basename ) ) ;
164- if ( fs . existsSync ( preferred ) ) {
165- return preferred ;
166- }
167- }
168- const declaredEntry = candidate . packageManifest ?. extensions ?. find (
169- ( entry ) : entry is string => typeof entry === "string" && entry . trim ( ) . length > 0 ,
170- ) ;
171- if ( declaredEntry ) {
172- return resolveCompiledBundledModulePath ( path . resolve ( candidate . rootDir , declaredEntry ) ) ;
173- }
174- return resolveCompiledBundledModulePath ( manifest . source ) ;
175- }
176-
177143function loadGeneratedBundledChannelEntries ( ) : readonly GeneratedBundledChannelEntry [ ] {
178- const discovery = discoverOpenClawPlugins ( { cache : false } ) ;
179- const manifestRegistry = loadPluginManifestRegistry ( {
180- cache : false ,
181- config : { } ,
182- candidates : discovery . candidates ,
183- diagnostics : discovery . diagnostics ,
184- } ) ;
185- const manifestByRoot = new Map (
186- manifestRegistry . plugins . map ( ( plugin ) => [ plugin . rootDir , plugin ] as const ) ,
187- ) ;
188- const seenIds = new Set < string > ( ) ;
144+ const manifestRegistry = loadPluginManifestRegistry ( { cache : false , config : { } } ) ;
189145 const entries : GeneratedBundledChannelEntry [ ] = [ ] ;
190146
191- for ( const candidate of discovery . candidates ) {
192- const manifest = manifestByRoot . get ( candidate . rootDir ) ;
193- if ( ! manifest || manifest . origin !== "bundled" || manifest . channels . length === 0 ) {
194- continue ;
195- }
196- if ( seenIds . has ( manifest . id ) ) {
147+ for ( const manifest of manifestRegistry . plugins ) {
148+ if ( manifest . origin !== "bundled" || manifest . channels . length === 0 ) {
197149 continue ;
198150 }
199- seenIds . add ( manifest . id ) ;
200151
201152 try {
202- const sourcePath = resolvePreferredBundledChannelSource ( candidate , manifest ) ;
153+ const sourcePath = resolveCompiledBundledModulePath ( manifest . source ) ;
203154 const entry = resolveChannelPluginModuleEntry (
204- loadBundledModule ( sourcePath , candidate . rootDir ) ,
155+ loadBundledModule ( sourcePath , manifest . rootDir ) ,
205156 ) ;
206157 if ( ! entry ) {
207158 log . warn (
@@ -213,7 +164,7 @@ function loadGeneratedBundledChannelEntries(): readonly GeneratedBundledChannelE
213164 ? resolveChannelSetupModuleEntry (
214165 loadBundledModule (
215166 resolveCompiledBundledModulePath ( manifest . setupSource ) ,
216- candidate . rootDir ,
167+ manifest . rootDir ,
217168 ) ,
218169 )
219170 : null ;
@@ -225,7 +176,7 @@ function loadGeneratedBundledChannelEntries(): readonly GeneratedBundledChannelE
225176 } catch ( error ) {
226177 const detail = error instanceof Error ? error . message : String ( error ) ;
227178 log . warn (
228- `[channels] failed to load bundled channel ${ manifest . id } from ${ candidate . source } : ${ detail } ` ,
179+ `[channels] failed to load bundled channel ${ manifest . id } from ${ manifest . source } : ${ detail } ` ,
229180 ) ;
230181 }
231182 }
0 commit comments