File size: 608 Bytes
3589760
 
 
ea51d47
 
 
 
 
 
 
 
 
 
 
 
 
7323886
ea51d47
 
 
 
 
 
 
 
7323886
ea51d47
 
3589760
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// src/agent/runner.js
import { api } from "../apiClient";

// Map language id -> file extension
const EXT_MAP = {
  python: ".py",
  javascript: ".js",
  typescript: ".ts",
  c: ".c",
  cpp: ".cpp",
  java: ".java",
  html: ".html",
  css: ".css",
  json: ".json",
};

export async function runCode(code, language, stdin = "") {
  const ext = EXT_MAP[language] || ".txt";

  // Use a consistent name – backend only cares about extension
  const filename = "main" + ext;

  const res = await api.post("/execute", {
    code,
    filename,
    input: stdin,
  });

  return res.data; // { output, error }
}