mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-22 21:38:05 -05:00
* chore: replace prettier with biome and add linting * chore: update devcontainer settings to use biome for linting and remove eslint, prettier * chore: update docker-compose to use Postgres 17-alpine and standardize quotes * chore: fixed more BUT disabled most rules due to limit * added additional rules, fixed linting & ts errors * added additional rules * rebased & linted * fixed oauth * updated biome & minor modifications --------- Co-authored-by: Aditya Tripathi <aditya@climactic.co>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { createLogger } from '@/lib/logs/console-logger'
|
|
import type { BlockOutput } from '@/blocks/types'
|
|
import type { SerializedBlock } from '@/serializer/types'
|
|
import { executeTool } from '@/tools'
|
|
import type { BlockHandler, ExecutionContext } from '../../types'
|
|
|
|
const logger = createLogger('FunctionBlockHandler')
|
|
|
|
/**
|
|
* Handler for Function blocks that execute custom code.
|
|
*/
|
|
export class FunctionBlockHandler implements BlockHandler {
|
|
canHandle(block: SerializedBlock): boolean {
|
|
return block.metadata?.id === 'function'
|
|
}
|
|
|
|
async execute(
|
|
block: SerializedBlock,
|
|
inputs: Record<string, any>,
|
|
context: ExecutionContext
|
|
): Promise<BlockOutput> {
|
|
const codeContent = Array.isArray(inputs.code)
|
|
? inputs.code.map((c: { content: string }) => c.content).join('\n')
|
|
: inputs.code
|
|
|
|
// Directly use the function_execute tool which calls the API route
|
|
logger.info(`Executing function block via API route: ${block.id}`)
|
|
const result = await executeTool('function_execute', {
|
|
code: codeContent,
|
|
timeout: inputs.timeout || 5000,
|
|
_context: { workflowId: context.workflowId },
|
|
})
|
|
|
|
if (!result.success) {
|
|
throw new Error(result.error || 'Function execution failed')
|
|
}
|
|
|
|
return { response: result.output }
|
|
}
|
|
}
|