@@ -227,7 +227,7 @@ export async function executeTool(
227227 const isInternalRoute = endpointUrl . startsWith ( '/api/' )
228228
229229 if ( isInternalRoute || skipProxy ) {
230- const result = await handleInternalRequest ( toolId , tool , contextParams )
230+ const result = await handleInternalRequest ( toolId , tool , contextParams , executionContext )
231231
232232 // Apply post-processing if available and not skipped
233233 let finalResult = result
@@ -414,7 +414,8 @@ function isErrorResponse(
414414async function handleInternalRequest (
415415 toolId : string ,
416416 tool : ToolConfig ,
417- params : Record < string , any >
417+ params : Record < string , any > ,
418+ executionContext ?: ExecutionContext
418419) : Promise < ToolResponse > {
419420 const requestId = generateRequestId ( )
420421
@@ -427,7 +428,11 @@ async function handleInternalRequest(
427428 const endpointUrl =
428429 typeof tool . request . url === 'function' ? tool . request . url ( params ) : tool . request . url
429430
430- const fullUrl = new URL ( endpointUrl , baseUrl ) . toString ( )
431+ const fullUrlObj = new URL ( endpointUrl , baseUrl )
432+ if ( executionContext ?. workflowId && typeof window === 'undefined' ) {
433+ fullUrlObj . searchParams . set ( 'workflowId' , executionContext . workflowId )
434+ }
435+ const fullUrl = fullUrlObj . toString ( )
431436
432437 // For custom tools, validate parameters on the client side before sending
433438 if ( toolId . startsWith ( 'custom_' ) && tool . request . body ) {
@@ -445,10 +450,21 @@ async function handleInternalRequest(
445450 }
446451 }
447452
453+ const headers = new Headers ( requestParams . headers )
454+ if ( typeof window === 'undefined' ) {
455+ try {
456+ const internalToken = await generateInternalToken ( )
457+ headers . set ( 'Authorization' , `Bearer ${ internalToken } ` )
458+ logger . info ( `[${ requestId } ] Added internal auth token for ${ toolId } ` )
459+ } catch ( error ) {
460+ logger . error ( `[${ requestId } ] Failed to generate internal token for ${ toolId } :` , error )
461+ }
462+ }
463+
448464 // Prepare request options
449465 const requestOptions = {
450466 method : requestParams . method ,
451- headers : new Headers ( requestParams . headers ) ,
467+ headers : headers ,
452468 body : requestParams . body ,
453469 }
454470
0 commit comments