{
  "openapi": "3.0.1",
  "info": {
    "title": "CodeSherpa",
    "description": "CodeSherpa is a tool that allows you to execute Python code in a REPL session, maintaining the state between requests, run terminal commands, and returns the output or error message.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:3333"
    }
  ],
  "paths": {
    "/repl": {
      "post": {
        "summary": "Execute code in a REPL-session like environment.",
        "description": "Executes the provided code in a specified language. Python code is executed in a REPL-like environment, \nmaintaining the state between requests. Code in C++ and Rust is also supported, but state is not preserved \nbetween requests for these languages.\n",
        "operationId": "executeReplCode",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeExecutionRequest"
              },
              "examples": {
                "pythonExample": {
                  "summary": "Python code example",
                  "value": {
                    "code": "def greet(name): return f'Hello, {name}!'\n\nprint(greet('Python'))",
                    "language": "python"
                  }
                },
                "cppExample": {
                  "summary": "C++ code example",
                  "value": {
                    "code": "#include<iostream>\n\nint main() {\n  std::string name = \"C++\";\n  std::cout << \"Hello, \" << name << \"!\" << std::endl;\n  return 0;\n}",
                    "language": "c++"
                  }
                },
                "rustExample": {
                  "summary": "Rust code example",
                  "value": {
                    "code": "fn main() {\n  let name = \"Rust\";\n  println!(\"Hello, {}!\", name);\n}",
                    "language": "rust"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Execution result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "result": {
                      "type": "string",
                      "description": "The output of the executed code."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Error Details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "A brief description of the error."
                    },
                    "returnCode": {
                      "type": "integer",
                      "description": "The return code of the failed process."
                    },
                    "command": {
                      "type": "string",
                      "description": "The command that was attempted."
                    },
                    "output": {
                      "type": "string",
                      "description": "Any output that resulted from the attempted command."
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/command": {
      "post": {
        "summary": "Run terminal commands",
        "description": "Runs the provided terminal command and returns the output or error message.",
        "operationId": "runCommand",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CommandExecutionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Execution result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "result": {
                      "type": "string",
                      "description": "The output of the executed command."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/upload": {
      "post": {
        "summary": "Upload a file",
        "description": "Endpoint to upload a file.",
        "operationId": "uploadFile",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File upload result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "description": "The message indicating the success of the file upload."
                    },
                    "url": {
                      "type": "string",
                      "description": "The URL of the uploaded file."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CodeExecutionRequest": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "The code to be executed in the REPL-like environment.",
            "example": "print('Hello, world!')"
          },
          "language": {
            "type": "string",
            "description": "The programming language of the code to be executed.",
            "example": "python"
          }
        }
      },
      "CommandExecutionRequest": {
        "type": "object",
        "properties": {
          "command": {
            "type": "string",
            "description": "The terminal command to be executed.",
            "example": "echo \"Hello, terminal!\""
          }
        }
      }
    }
  }
}