@@ -44,6 +44,7 @@ export type ProviderRuntimePluginLookupParams = {
4444 config ?: OpenClawConfig ;
4545 workspaceDir ?: string ;
4646 env ?: NodeJS . ProcessEnv ;
47+ allowGatewayRegistryWorkspaceReuse ?: boolean ;
4748 applyAutoEnable ?: boolean ;
4849 bundledProviderVitestCompat ?: boolean ;
4950 pluginMetadataSnapshot ?: PluginMetadataRegistryView ;
@@ -82,6 +83,7 @@ function resolveProviderRuntimePluginCacheKey(
8283 return JSON . stringify ( {
8384 provider : normalizeLowercaseStringOrEmpty ( params . provider ) ,
8485 modelId : resolveProviderRuntimeLookupModelId ( params ) ?? null ,
86+ allowGatewayRegistryWorkspaceReuse : params . allowGatewayRegistryWorkspaceReuse ?? false ,
8587 pluginControlPlane : resolvePluginControlPlaneFingerprint ( {
8688 config : params . config ,
8789 env : params . env ,
@@ -141,9 +143,19 @@ function findProviderRuntimePluginInLoadedRegistries(params: {
141143 lookup : ProviderRuntimePluginLookupParams ;
142144 apiOwnerHint ?: string ;
143145} ) : ProviderPlugin | undefined {
146+ const registryState = getPluginRegistryState ( ) ;
147+ const activeWorkspaceDir =
148+ params . lookup . allowGatewayRegistryWorkspaceReuse === true &&
149+ registryState ?. runtimeSubagentMode === "gateway-bindable"
150+ ? getActivePluginRegistryWorkspaceDirFromState ( )
151+ : undefined ;
152+ const lookupWorkspaceDir =
153+ activeWorkspaceDir && activeWorkspaceDir !== params . lookup . workspaceDir
154+ ? activeWorkspaceDir
155+ : params . lookup . workspaceDir ;
144156 const activeRegistry = getLoadedRuntimePluginRegistry ( {
145157 env : params . lookup . env ,
146- workspaceDir : params . lookup . workspaceDir ,
158+ workspaceDir : lookupWorkspaceDir ,
147159 } ) ;
148160 const activePlugin = activeRegistry
149161 ? findProviderRuntimePluginInRegistry ( {
@@ -158,7 +170,7 @@ function findProviderRuntimePluginInLoadedRegistries(params: {
158170 for ( const surface of PREPARED_PROVIDER_RUNTIME_SURFACES ) {
159171 const registry = getLoadedRuntimePluginRegistry ( {
160172 env : params . lookup . env ,
161- workspaceDir : params . lookup . workspaceDir ,
173+ workspaceDir : lookupWorkspaceDir ,
162174 surface,
163175 } ) ;
164176 const plugin = registry
@@ -371,6 +383,14 @@ export function ensureProviderRuntimePluginHandle(
371383 config : params . config ?? params . runtimeHandle ?. config ,
372384 workspaceDir : params . workspaceDir ?? params . runtimeHandle ?. workspaceDir ,
373385 env : params . env ?? params . runtimeHandle ?. env ,
386+ ...( ( params . allowGatewayRegistryWorkspaceReuse ??
387+ params . runtimeHandle ?. allowGatewayRegistryWorkspaceReuse )
388+ ? {
389+ allowGatewayRegistryWorkspaceReuse :
390+ params . allowGatewayRegistryWorkspaceReuse ??
391+ params . runtimeHandle ?. allowGatewayRegistryWorkspaceReuse ,
392+ }
393+ : { } ) ,
374394 applyAutoEnable : params . runtimeHandle ?. applyAutoEnable ,
375395 bundledProviderVitestCompat : params . runtimeHandle ?. bundledProviderVitestCompat ,
376396 pluginMetadataSnapshot :
@@ -385,6 +405,7 @@ export function prepareProviderExtraParams(params: {
385405 config ?: OpenClawConfig ;
386406 workspaceDir ?: string ;
387407 env ?: NodeJS . ProcessEnv ;
408+ allowGatewayRegistryWorkspaceReuse ?: boolean ;
388409 runtimeHandle ?: ProviderRuntimePluginHandle ;
389410 context : ProviderPrepareExtraParamsContext ;
390411} ) {
@@ -399,6 +420,7 @@ export function resolveProviderExtraParamsForTransport(params: {
399420 config ?: OpenClawConfig ;
400421 workspaceDir ?: string ;
401422 env ?: NodeJS . ProcessEnv ;
423+ allowGatewayRegistryWorkspaceReuse ?: boolean ;
402424 runtimeHandle ?: ProviderRuntimePluginHandle ;
403425 context : ProviderExtraParamsForTransportContext ;
404426} ) {
@@ -413,6 +435,7 @@ export function resolveProviderAuthProfileId(params: {
413435 config ?: OpenClawConfig ;
414436 workspaceDir ?: string ;
415437 env ?: NodeJS . ProcessEnv ;
438+ allowGatewayRegistryWorkspaceReuse ?: boolean ;
416439 runtimeHandle ?: ProviderRuntimePluginHandle ;
417440 context : ProviderResolveAuthProfileIdContext ;
418441} ) : string | undefined {
@@ -427,6 +450,7 @@ export function resolveProviderFollowupFallbackRoute(params: {
427450 config ?: OpenClawConfig ;
428451 workspaceDir ?: string ;
429452 env ?: NodeJS . ProcessEnv ;
453+ allowGatewayRegistryWorkspaceReuse ?: boolean ;
430454 runtimeHandle ?: ProviderRuntimePluginHandle ;
431455 context : ProviderFollowupFallbackRouteContext ;
432456} ) : ProviderFollowupFallbackRouteResult | undefined {
@@ -441,6 +465,7 @@ export function wrapProviderStreamFn(params: {
441465 config ?: OpenClawConfig ;
442466 workspaceDir ?: string ;
443467 env ?: NodeJS . ProcessEnv ;
468+ allowGatewayRegistryWorkspaceReuse ?: boolean ;
444469 runtimeHandle ?: ProviderRuntimePluginHandle ;
445470 context : ProviderWrapStreamFnContext ;
446471} ) {
@@ -454,6 +479,7 @@ export function wrapProviderSimpleCompletionStreamFn(params: {
454479 config ?: OpenClawConfig ;
455480 workspaceDir ?: string ;
456481 env ?: NodeJS . ProcessEnv ;
482+ allowGatewayRegistryWorkspaceReuse ?: boolean ;
457483 runtimeHandle ?: ProviderRuntimePluginHandle ;
458484 context : ProviderWrapStreamFnContext ;
459485} ) {
0 commit comments