@@ -49,6 +49,28 @@ def get_agent(request: Request) -> Agent:
4949 return request .app .state .agent
5050
5151
52+ def get_react_bundle_path () -> str :
53+ """Get the path to the latest React bundle from the Vite manifest file."""
54+ manifest_path = os .path .join (os .path .dirname (__file__ ), "static" , "react" , ".vite" , "manifest.json" )
55+ try :
56+ with open (manifest_path , 'r' ) as f :
57+ manifest = json .load (f )
58+ # Get the main entry point bundle
59+ if "src/main.jsx" in manifest :
60+ return f"/static/react/{ manifest ['src/main.jsx' ]['file' ]} "
61+ # Fallback to any entry point if the expected one isn't found
62+ for key , value in manifest .items ():
63+ if value .get ("isEntry" , False ):
64+ return f"/static/react/{ value ['file' ]} "
65+ # If no entries are found, return a default path
66+ logger .warning ("No entries found in Vite manifest, using fallback path" )
67+ return "/static/react/assets/main.js"
68+ except (FileNotFoundError , json .JSONDecodeError , KeyError ) as e :
69+ logger .error (f"Error reading Vite manifest: { e } " )
70+ # Return a default path if the manifest can't be read
71+ return "/static/react/assets/main.js"
72+
73+
5274def serialize_sse_event (data : Dict ) -> str :
5375 return f"data: { json .dumps (data )} \n \n "
5476
@@ -132,7 +154,18 @@ async def on_run_step(self, step: RunStep) -> Optional[str]:
132154
133155@router .get ("/" , response_class = HTMLResponse )
134156async def index (request : Request ):
135- return templates .TemplateResponse ("index.html" , {"request" : request })
157+ # Check if the useReactApp query parameter is present and set to 'true'
158+ use_react_app = request .query_params .get ('useReactApp' , '' ).lower () == 'true'
159+
160+ # Use different template files based on whether React is enabled
161+ template_name = "index_react.html" if use_react_app else "index.html"
162+
163+ return templates .TemplateResponse (
164+ template_name ,
165+ {
166+ "request" : request ,
167+ }
168+ )
136169
137170
138171async def get_result (thread_id : str , agent_id : str , ai_client : AIProjectClient ) -> AsyncGenerator [str , None ]:
0 commit comments