1+ import type { PinnedDispatcherPolicy } from "openclaw/plugin-sdk/infra-runtime" ;
12import {
23 requiresExplicitMatrixDefaultAccount ,
34 resolveMatrixDefaultOrOnlyAccountId ,
@@ -77,13 +78,19 @@ const MATRIX_HTTP_HOMESERVER_ERROR =
7778
7879function buildMatrixNetworkFields (
7980 allowPrivateNetwork : boolean | undefined ,
80- ) : Pick < MatrixResolvedConfig , "allowPrivateNetwork" | "ssrfPolicy" > {
81- if ( ! allowPrivateNetwork ) {
81+ proxy ?: string ,
82+ ) : Pick < MatrixResolvedConfig , "allowPrivateNetwork" | "ssrfPolicy" | "dispatcherPolicy" > {
83+ const dispatcherPolicy : PinnedDispatcherPolicy | undefined = proxy
84+ ? { mode : "explicit-proxy" , proxyUrl : proxy }
85+ : undefined ;
86+ if ( ! allowPrivateNetwork && ! dispatcherPolicy ) {
8287 return { } ;
8388 }
8489 return {
85- allowPrivateNetwork : true ,
86- ssrfPolicy : ssrfPolicyFromAllowPrivateNetwork ( true ) ,
90+ ...( allowPrivateNetwork
91+ ? { allowPrivateNetwork : true , ssrfPolicy : ssrfPolicyFromAllowPrivateNetwork ( true ) }
92+ : { } ) ,
93+ ...( dispatcherPolicy ? { dispatcherPolicy } : { } ) ,
8794 } ;
8895}
8996
@@ -265,7 +272,7 @@ export function resolveMatrixConfig(
265272 deviceName : resolvedStrings . deviceName || undefined ,
266273 initialSyncLimit,
267274 encryption,
268- ...buildMatrixNetworkFields ( allowPrivateNetwork ) ,
275+ ...buildMatrixNetworkFields ( allowPrivateNetwork , matrix . proxy ) ,
269276 } ;
270277}
271278
@@ -320,7 +327,7 @@ export function resolveMatrixConfigForAccount(
320327 deviceName : resolvedStrings . deviceName || undefined ,
321328 initialSyncLimit,
322329 encryption,
323- ...buildMatrixNetworkFields ( allowPrivateNetwork ) ,
330+ ...buildMatrixNetworkFields ( allowPrivateNetwork , account . proxy ?? matrix . proxy ) ,
324331 } ;
325332}
326333
@@ -412,6 +419,7 @@ export async function resolveMatrixAuth(params?: {
412419 ensureMatrixSdkLoggingConfigured ( ) ;
413420 const tempClient = new MatrixClient ( homeserver , resolved . accessToken , undefined , undefined , {
414421 ssrfPolicy : resolved . ssrfPolicy ,
422+ dispatcherPolicy : resolved . dispatcherPolicy ,
415423 } ) ;
416424 const whoami = ( await tempClient . doRequest ( "GET" , "/_matrix/client/v3/account/whoami" ) ) as {
417425 user_id ?: string ;
@@ -460,7 +468,12 @@ export async function resolveMatrixAuth(params?: {
460468 deviceName : resolved . deviceName ,
461469 initialSyncLimit : resolved . initialSyncLimit ,
462470 encryption : resolved . encryption ,
463- ...buildMatrixNetworkFields ( resolved . allowPrivateNetwork ) ,
471+ ...buildMatrixNetworkFields (
472+ resolved . allowPrivateNetwork ,
473+ resolved . dispatcherPolicy ?. mode === "explicit-proxy"
474+ ? resolved . dispatcherPolicy . proxyUrl
475+ : undefined ,
476+ ) ,
464477 } ;
465478 }
466479
@@ -477,7 +490,12 @@ export async function resolveMatrixAuth(params?: {
477490 deviceName : resolved . deviceName ,
478491 initialSyncLimit : resolved . initialSyncLimit ,
479492 encryption : resolved . encryption ,
480- ...buildMatrixNetworkFields ( resolved . allowPrivateNetwork ) ,
493+ ...buildMatrixNetworkFields (
494+ resolved . allowPrivateNetwork ,
495+ resolved . dispatcherPolicy ?. mode === "explicit-proxy"
496+ ? resolved . dispatcherPolicy . proxyUrl
497+ : undefined ,
498+ ) ,
481499 } ;
482500 }
483501
@@ -495,6 +513,7 @@ export async function resolveMatrixAuth(params?: {
495513 ensureMatrixSdkLoggingConfigured ( ) ;
496514 const loginClient = new MatrixClient ( homeserver , "" , undefined , undefined , {
497515 ssrfPolicy : resolved . ssrfPolicy ,
516+ dispatcherPolicy : resolved . dispatcherPolicy ,
498517 } ) ;
499518 const login = ( await loginClient . doRequest ( "POST" , "/_matrix/client/v3/login" , undefined , {
500519 type : "m.login.password" ,
@@ -523,7 +542,12 @@ export async function resolveMatrixAuth(params?: {
523542 deviceName : resolved . deviceName ,
524543 initialSyncLimit : resolved . initialSyncLimit ,
525544 encryption : resolved . encryption ,
526- ...buildMatrixNetworkFields ( resolved . allowPrivateNetwork ) ,
545+ ...buildMatrixNetworkFields (
546+ resolved . allowPrivateNetwork ,
547+ resolved . dispatcherPolicy ?. mode === "explicit-proxy"
548+ ? resolved . dispatcherPolicy . proxyUrl
549+ : undefined ,
550+ ) ,
527551 } ;
528552
529553 const { saveMatrixCredentials } = await loadCredentialsWriter ( ) ;
0 commit comments