mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-11 07:04:58 -05:00
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:
@@ -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}`
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user