mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
Added prettier, added husky pre-commit hook to ensure formatting
This commit is contained in:
+32
-30
@@ -1,8 +1,8 @@
|
||||
import { ToolConfig, ToolResponse } from '../types'
|
||||
|
||||
export interface CodeExecutionInput {
|
||||
code: Array<{content: string, id: string}> | string
|
||||
input?: Record<string, any>
|
||||
code: Array<{ content: string; id: string }> | string
|
||||
input?: Record<string, any>
|
||||
}
|
||||
|
||||
export interface CodeExecutionOutput extends ToolResponse {
|
||||
@@ -17,13 +17,13 @@ export const functionExecuteTool: ToolConfig<CodeExecutionInput, CodeExecutionOu
|
||||
name: 'Function Execute',
|
||||
description: 'Execute code in a sandboxed environment',
|
||||
version: '1.0.0',
|
||||
|
||||
|
||||
params: {
|
||||
code: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The code to execute',
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
@@ -31,66 +31,68 @@ export const functionExecuteTool: ToolConfig<CodeExecutionInput, CodeExecutionOu
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
body: (params) => {
|
||||
const codeContent = Array.isArray(params.code)
|
||||
? params.code.map(c => c.content).join('\n')
|
||||
: params.code
|
||||
? params.code.map((c) => c.content).join('\n')
|
||||
: params.code
|
||||
|
||||
return {
|
||||
language: 'js',
|
||||
version: '*',
|
||||
files: [{
|
||||
name: 'code.js',
|
||||
content: codeContent
|
||||
}],
|
||||
files: [
|
||||
{
|
||||
name: 'code.js',
|
||||
content: codeContent,
|
||||
},
|
||||
],
|
||||
stdin: '',
|
||||
args: [],
|
||||
compile_timeout: 10000,
|
||||
run_timeout: 3000,
|
||||
compile_memory_limit: -1,
|
||||
run_memory_limit: -1
|
||||
}
|
||||
run_memory_limit: -1,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response) => {
|
||||
const result = await response.json()
|
||||
|
||||
const result = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(result.message || 'Execution failed')
|
||||
throw new Error(result.message || 'Execution failed')
|
||||
}
|
||||
|
||||
if (result.run?.stderr) {
|
||||
throw new Error(result.run.stderr)
|
||||
throw new Error(result.run.stderr)
|
||||
}
|
||||
|
||||
const stdout = result.run?.stdout || ''
|
||||
|
||||
const stdout = result.run?.stdout || ''
|
||||
|
||||
try {
|
||||
// Try parsing the output as JSON
|
||||
const parsed = JSON.parse(stdout)
|
||||
return {
|
||||
const parsed = JSON.parse(stdout)
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
result: parsed,
|
||||
stdout
|
||||
}
|
||||
}
|
||||
stdout,
|
||||
},
|
||||
}
|
||||
} catch {
|
||||
// If not JSON, return as string
|
||||
return {
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
result: stdout,
|
||||
stdout
|
||||
}
|
||||
}
|
||||
stdout,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
transformError: (error: any) => {
|
||||
return error.message || 'Code execution failed'
|
||||
return error.message || 'Code execution failed'
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user