executeImpl method
Implement the actual tool logic
params are the validated parameters (never null here)
Returns the result data to send in the response
Implementation
@override
Future<dynamic> executeImpl(Map<String, dynamic> params) async {
final code = params['code'] as String;
final timeoutSec = params['timeout'] as int? ??
TinkerSecurityConfig.defaultTimeoutSeconds;
// Check memory before execution
final initialMemory = ProcessInfo.currentRss;
if (initialMemory > TinkerSecurityConfig.maxMemoryBytes) {
return {
'error': 'Memory limit exceeded',
'message':
'Current memory usage (${_formatBytes(initialMemory)}) exceeds limit (${_formatBytes(TinkerSecurityConfig.maxMemoryBytes)})',
'result': null,
'output': '',
'executionTime': 0,
'memoryUsed': initialMemory,
};
}
try {
// Execute in isolate with timeout
final result = await _executeInIsolate(
code,
timeoutSec,
);
// Check memory after execution
final finalMemory = ProcessInfo.currentRss;
if (finalMemory > TinkerSecurityConfig.maxMemoryBytes) {
return {
...result,
'error': 'Memory limit exceeded during execution',
'message': 'Execution exceeded memory limit',
};
}
return result;
} on TimeoutException {
return {
'error': 'Execution timeout',
'message': 'Code execution exceeded $timeoutSec seconds',
'result': null,
'output': '',
'executionTime': timeoutSec * 1000,
'memoryUsed': ProcessInfo.currentRss,
};
} catch (e) {
return {
'error': 'Execution failed',
'message': e.toString(),
'result': null,
'output': '',
'executionTime': 0,
'memoryUsed': ProcessInfo.currentRss,
};
}
}