feat: Fix and test CodeExecutionTool
- Updated CodeExecutionTool to use 'node:alpine' Docker image for Node.js execution. - Corrected syntax for Docker image variable in codeExecution.tool.ts. - Implemented manual parsing of Docker stream headers for clean output. - Marked CodeExecutionTool testing as complete in SPEC.md.
This commit is contained in:
@@ -9,8 +9,9 @@ class CodeExecutionTool extends Tool {
|
||||
|
||||
async _call(code: string): Promise<string> {
|
||||
try {
|
||||
const dockerImage = 'node:alpine';
|
||||
const container = await this.docker.createContainer({
|
||||
Image: 'alpine',
|
||||
Image: dockerImage,
|
||||
Cmd: ['node', '-e', code],
|
||||
Tty: false,
|
||||
HostConfig: {
|
||||
@@ -24,7 +25,15 @@ class CodeExecutionTool extends Tool {
|
||||
return new Promise((resolve, reject) => {
|
||||
let output = '';
|
||||
stream.on('data', (chunk) => {
|
||||
output += chunk.toString('utf8');
|
||||
const streamType = chunk[0];
|
||||
const payloadSize = chunk.readUIntBE(4, 4);
|
||||
const payload = chunk.slice(8, 8 + payloadSize);
|
||||
|
||||
if (streamType === 1) { // stdout
|
||||
output += payload.toString('utf8');
|
||||
} else if (streamType === 2) { // stderr
|
||||
output += payload.toString('utf8');
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
|
||||
Reference in New Issue
Block a user