11import logging
22import sys
3- import uuid
43import httpx
54
65from typing import Dict , Union , Literal , Set
76
87from contextlib import asynccontextmanager
9- from fastapi import FastAPI
8+ from fastapi import FastAPI , Request
109from fastapi .responses import PlainTextResponse
1110
1211from api .models .context import Context
@@ -70,18 +69,18 @@ async def get_health():
7069
7170
7271@app .post ("/execute" )
73- async def post_execute (request : ExecutionRequest ):
74- logger .info (f"Executing code: { request .code } " )
72+ async def post_execute (request : Request , exec_request : ExecutionRequest ):
73+ logger .info (f"Executing code: { exec_request .code } " )
7574
76- if request .context_id and request .language :
75+ if exec_request .context_id and exec_request .language :
7776 return PlainTextResponse (
7877 "Only one of context_id or language can be provided" ,
7978 status_code = 400 ,
8079 )
8180
8281 context_id = None
83- if request .language :
84- language = normalize_language (request .language )
82+ if exec_request .language :
83+ language = normalize_language (exec_request .language )
8584
8685 async with await default_websockets .get_lock (language ):
8786 context_id = default_websockets .get (language )
@@ -97,8 +96,8 @@ async def post_execute(request: ExecutionRequest):
9796 context_id = context .id
9897 default_websockets [language ] = context_id
9998
100- elif request .context_id :
101- context_id = request .context_id
99+ elif exec_request .context_id :
100+ context_id = exec_request .context_id
102101
103102 if context_id :
104103 ws = websockets .get (context_id , None )
@@ -107,14 +106,14 @@ async def post_execute(request: ExecutionRequest):
107106
108107 if not ws :
109108 return PlainTextResponse (
110- f"Context { request .context_id } not found" ,
109+ f"Context { exec_request .context_id } not found" ,
111110 status_code = 404 ,
112111 )
113112
114113 return StreamingListJsonResponse (
115114 ws .execute (
116- request .code ,
117- env_vars = request .env_vars ,
115+ exec_request .code ,
116+ env_vars = exec_request .env_vars ,
118117 access_token = request .headers .get ("X-Access-Token" , None ),
119118 )
120119 )
0 commit comments