refactor(agent-handler): simplify agent handler, update tests, fix resolution of env vars in function execution (#437)

* refactored agent handler, fixed envvar resolution for function block

* resolve missing envvar resolution from function execution for custom tool

* fix path traversal risk

* removed extraneous comments

* ack PR comments
This commit is contained in:
Waleed Latif
2025-05-29 18:20:19 -07:00
committed by GitHub
parent 3b82e7d224
commit b2450530d1
22 changed files with 1090 additions and 763 deletions

View File

@@ -38,7 +38,7 @@ function resolveCodeVariables(
for (const match of tagMatches) {
const tagName = match.slice(1, -1).trim()
const tagValue = params[tagName] || ''
resolvedCode = resolvedCode.replace(match, tagValue)
resolvedCode = resolvedCode.replace(match, JSON.stringify(tagValue))
}
return resolvedCode
@@ -61,6 +61,14 @@ export async function POST(req: NextRequest) {
isCustomTool = false,
} = body
logger.info(`[${requestId}] Function execution request`, {
hasCode: !!code,
paramsCount: Object.keys(params).length,
timeout,
workflowId,
isCustomTool,
})
// Extract internal parameters that shouldn't be passed to the execution context
const executionParams = { ...params }
executionParams._context = undefined
@@ -181,7 +189,7 @@ export async function POST(req: NextRequest) {
const errorMessage = `${args
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
.join(' ')}\n`
logger.error(`[${requestId}] Code Console Error:`, errorMessage)
logger.error(`[${requestId}] Code Console Error: ${errorMessage}`)
stdout += `ERROR: ${errorMessage}`
},
},
@@ -234,7 +242,7 @@ export async function POST(req: NextRequest) {
const errorMessage = `${args
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
.join(' ')}\n`
logger.error(`[${requestId}] Code Console Error:`, errorMessage)
logger.error(`[${requestId}] Code Console Error: ${errorMessage}`)
stdout += `ERROR: ${errorMessage}`
},
},