@@ -49,6 +49,28 @@ def get_agent(request: Request) -> Agent:
49
49
return request .app .state .agent
50
50
51
51
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
+
52
74
def serialize_sse_event (data : Dict ) -> str :
53
75
return f"data: { json .dumps (data )} \n \n "
54
76
@@ -132,7 +154,18 @@ async def on_run_step(self, step: RunStep) -> Optional[str]:
132
154
133
155
@router .get ("/" , response_class = HTMLResponse )
134
156
async 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
+ )
136
169
137
170
138
171
async def get_result (thread_id : str , agent_id : str , ai_client : AIProjectClient ) -> AsyncGenerator [str , None ]:
0 commit comments