Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix client import; Improve types; Fix generating

Tomáš Valentae313720acf25
diff --git a/api-service/app.py b/api-service/app.py
index 3c096a42b..112d35656 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -7,7 +7,7 @@ from flask_cors import CORS
from codegen.base import generate_req_handler
from codegen.db.base import Database, DeploymentState
-from playground_client.base import NodeJSPlayground
+from playground_client import NodeJSPlayground
url = os.environ.get("SUPABASE_URL")
key = os.environ.get("SUPABASE_KEY")
@@ -16,7 +16,6 @@ db = Database(url, key)
app = Flask(__name__)
CORS(app)
-
def dump(obj):
for attr in dir(obj):
print("obj.%s = %r" % (attr, getattr(obj, attr)))
diff --git a/api-service/playground_client/Makefile b/api-service/playground_client/Makefile
new file mode 100644
index 000000000..054727e5c
--- /dev/null
+++ b/api-service/playground_client/Makefile
@@ -0,0 +1,3 @@
+generate:
+ rm -rf ./openapi_client
+ npx @openapitools/openapi-generator-cli generate -i ../playground/swagger.json -g python-nextgen -o ./ --additional-properties=generateSourceCodeOnly=true --additional-properties=disallowAdditionalPropertiesIfNotPresent=false
diff --git a/api-service/playground_client/__init__.py b/api-service/playground_client/__init__.py
index e69de29bb..778a7ab01 100644
--- a/api-service/playground_client/__init__.py
+++ b/api-service/playground_client/__init__.py
@@ -0,0 +1 @@
+from .main import NodeJSPlayground
diff --git a/api-service/playground_client/base.py b/api-service/playground_client/main.py
similarity index 79%
rename from api-service/playground_client/base.py
rename to api-service/playground_client/main.py
index 54b1d9ce8..dab949057 100644
--- a/api-service/playground_client/base.py
+++ b/api-service/playground_client/main.py
@@ -1,15 +1,25 @@
import openapi_client
from enum import Enum
+from typing import TypedDict, Union
+
configuration = openapi_client.Configuration(
host = 'https://localhost:9001',
)
-class FilesystemEntry(Enum):
+class FilesystemEntryType(Enum):
FILE = 'file'
DIR = 'directory'
+class FilesystemEntry(TypedDict):
+ name: str
+ type: FilesystemEntryType
+
+class CommandOutput(TypedDict):
+ error: Union[str, None]
+ output: str
+
class Playground:
def __init__(self, env_id: str):
self.client = openapi_client.ApiClient(configuration)
@@ -31,10 +41,10 @@ class Playground:
err_lines = [err.line for err in result.stderr]
out_lines = [out.line for out in result.stdout]
- return {
- 'error': '\n'.join(err_lines),
- 'output': '\n'.join(out_lines),
- }
+ return CommandOutput(
+ error=err_lines.join('\n') if len(err_lines) > 0 else None,
+ output='\n'.join(out_lines)
+ )
def read_file(self, path: str):
result = self.api.read_filesystem_file(self.session.id, path)
@@ -43,10 +53,10 @@ class Playground:
def list_dir(self, path: str):
result = self.api.list_filesystem_dir(self.session.id, path)
return [
- {
- 'type': FilesystemEntry.DIR.value if entry.is_dir else FilesystemEntry.FILE.value,
- 'name': entry.name,
- }
+ FilesystemEntry(
+ name=entry.name,
+ type=FilesystemEntryType.DIR if entry.is_dir else FilesystemEntryType.FILE
+ )
for entry in result.entries
]
diff --git a/api-service/openapitools.json b/api-service/playground_client/openapitools.json
similarity index 100%
rename from api-service/openapitools.json
rename to api-service/playground_client/openapitools.json
diff --git a/api-service/scripts/generate-playground-client.sh b/api-service/scripts/generate-playground-client.sh
deleted file mode 100755
index a72c195d0..000000000
--- a/api-service/scripts/generate-playground-client.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-cd playground && yarn build
-cd ..
-rm -rf ./playground_client/openapi_client
-npx @openapitools/openapi-generator-cli generate -i playground/swagger.json -g python-nextgen -o ./playground_client/ --additional-properties=generateSourceCodeOnly=true --additional-properties=disallowAdditionalPropertiesIfNotPresent=false