( data: any[], code: string )
| 15 | * In production, consider using a more robust sandboxing solution. |
| 16 | */ |
| 17 | export async function executeDataCode( |
| 18 | data: any[], |
| 19 | code: string |
| 20 | ): Promise<any> { |
| 21 | try { |
| 22 | // Execute code with data and helper functions |
| 23 | const func = new Function('data', 'stat', ` |
| 24 | ${code} |
| 25 | return result; |
| 26 | `); |
| 27 | |
| 28 | const result = func(data, stat); |
| 29 | |
| 30 | return result; |
| 31 | } catch (error) { |
| 32 | throw new Error(`Failed to execute data code: ${error instanceof Error ? error.message : String(error)}`); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Generate JavaScript code from natural language using LLM |
no outgoing calls
no test coverage detected