@@ -105,6 +105,14 @@ type ChannelManagerOptions = {
105105 * @see {@link ChannelGatewayContext.channelRuntime }
106106 */
107107 channelRuntime ?: PluginRuntime [ "channel" ] ;
108+ /**
109+ * Lazily resolves optional channel runtime helpers for external channel plugins.
110+ *
111+ * Use this when the caller wants to avoid instantiating the full plugin channel
112+ * runtime during gateway startup. The manager only needs the runtime surface once
113+ * a channel account actually starts.
114+ */
115+ resolveChannelRuntime ?: ( ) => PluginRuntime [ "channel" ] ;
108116} ;
109117
110118type StartChannelOptions = {
@@ -125,7 +133,8 @@ export type ChannelManager = {
125133
126134// Channel docking: lifecycle hooks (`plugin.gateway`) flow through this manager.
127135export function createChannelManager ( opts : ChannelManagerOptions ) : ChannelManager {
128- const { loadConfig, channelLogs, channelRuntimeEnvs, channelRuntime } = opts ;
136+ const { loadConfig, channelLogs, channelRuntimeEnvs, channelRuntime, resolveChannelRuntime } =
137+ opts ;
129138
130139 const channelStores = new Map < ChannelId , ChannelRuntimeStore > ( ) ;
131140 // Tracks restart attempts per channel:account. Reset on successful start.
@@ -219,6 +228,10 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
219228 return next ;
220229 } ;
221230
231+ const getChannelRuntime = ( ) : PluginRuntime [ "channel" ] | undefined => {
232+ return channelRuntime ?? resolveChannelRuntime ?.( ) ;
233+ } ;
234+
222235 const startChannelInternal = async (
223236 channelId : ChannelId ,
224237 accountId ?: string ,
@@ -297,6 +310,7 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
297310 } ) ;
298311
299312 const log = channelLogs [ channelId ] ;
313+ const resolvedChannelRuntime = getChannelRuntime ( ) ;
300314 const task = startAccount ( {
301315 cfg,
302316 accountId : id ,
@@ -306,7 +320,7 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
306320 log,
307321 getStatus : ( ) => getRuntime ( channelId , id ) ,
308322 setStatus : ( next ) => setRuntime ( channelId , id , next ) ,
309- ...( channelRuntime ? { channelRuntime } : { } ) ,
323+ ...( resolvedChannelRuntime ? { channelRuntime : resolvedChannelRuntime } : { } ) ,
310324 } ) ;
311325 const trackedPromise = Promise . resolve ( task )
312326 . catch ( ( err ) => {
0 commit comments