@@ -227,7 +227,7 @@ function unwrapRpcPayload(raw) {
227227}
228228
229229async function rpcCall ( method , params , options ) {
230- const { callGateway } = await loadCallGatewayModule ( ) ;
230+ const { callGateway } = await loadCallGatewayModule ( options . runner ) ;
231231 const payload = await callGateway ( {
232232 config : readJson ( options . env . OPENCLAW_CONFIG_PATH ) ,
233233 configPath : options . env . OPENCLAW_CONFIG_PATH ,
@@ -241,27 +241,35 @@ async function rpcCall(method, params, options) {
241241 return unwrapRpcPayload ( payload ) ;
242242}
243243
244- async function loadCallGatewayModule ( ) {
245- callGatewayModulePromise ??= importCallGatewayModule ( ) ;
244+ async function loadCallGatewayModule ( runner ) {
245+ callGatewayModulePromise ??= importCallGatewayModule ( runner ) ;
246246 return callGatewayModulePromise ;
247247}
248248
249- async function importCallGatewayModule ( ) {
249+ async function importCallGatewayModule ( runner ) {
250+ if ( ! usesPackagedOpenClawEntry ( runner ) ) {
251+ return import ( pathToFileURL ( path . join ( process . cwd ( ) , "src/gateway/call.ts" ) ) . href ) ;
252+ }
250253 const distDir = path . join ( process . cwd ( ) , "dist" ) ;
251- if ( fs . existsSync ( distDir ) ) {
252- const candidates = fs
253- . readdirSync ( distDir )
254- . filter ( ( name ) => / ^ c a l l (?: \. r u n t i m e ) ? - [ A - Z a - z 0 - 9 _ - ] + \. j s $ / u. test ( name ) )
255- . toSorted ( ( left , right ) => left . localeCompare ( right ) ) ;
256- for ( const name of candidates ) {
257- const module = await import ( pathToFileURL ( path . join ( distDir , name ) ) . href ) ;
258- if ( typeof module . callGateway === "function" ) {
259- return module ;
260- }
254+ const candidates = fs . existsSync ( distDir )
255+ ? fs
256+ . readdirSync ( distDir )
257+ . filter ( ( name ) => / ^ c a l l (?: \. r u n t i m e ) ? - [ A - Z a - z 0 - 9 _ - ] + \. j s $ / u. test ( name ) )
258+ . toSorted ( ( left , right ) => left . localeCompare ( right ) )
259+ : [ ] ;
260+ for ( const name of candidates ) {
261+ const module = await import ( pathToFileURL ( path . join ( distDir , name ) ) . href ) ;
262+ if ( typeof module . callGateway === "function" ) {
263+ return module ;
261264 }
262- throw new Error ( `unable to find callGateway export in dist (${ candidates . join ( ", " ) } )` ) ;
263265 }
264- return import ( pathToFileURL ( path . join ( process . cwd ( ) , "src/gateway/call.ts" ) ) . href ) ;
266+ throw new Error ( `unable to find callGateway export in dist (${ candidates . join ( ", " ) } )` ) ;
267+ }
268+
269+ function usesPackagedOpenClawEntry ( runner ) {
270+ return Boolean (
271+ process . env . OPENCLAW_ENTRY && runner ?. baseArgs ?. [ 0 ] === process . env . OPENCLAW_ENTRY ,
272+ ) ;
265273}
266274
267275async function retryRpcCall ( method , params , options ) {
0 commit comments