umer6016 commited on
Commit
c951f9c
·
1 Parent(s): f148dc8

Pass user_id from frontend to backend for Supabase metrics logging

Browse files
backend/app/api/chat.py CHANGED
@@ -43,7 +43,7 @@ async def chat(req: ChatRequest):
43
  question=req.messages[-1].content if req.messages else "",
44
  answer=answer,
45
  system_prompt=req.system_prompt,
46
- user_id=None,
47
  url=None,
48
  )
49
  except Exception as log_exc:
 
43
  question=req.messages[-1].content if req.messages else "",
44
  answer=answer,
45
  system_prompt=req.system_prompt,
46
+ user_id=req.user_id,
47
  url=None,
48
  )
49
  except Exception as log_exc:
backend/app/api/jobs.py CHANGED
@@ -36,7 +36,7 @@ async def run_job(body: JobCreate) -> JobStatus:
36
  save_job_metrics_to_supabase(
37
  url=str(body.url),
38
  stats=stats,
39
- user_id=None, # user id not available in this dev endpoint
40
  )
41
  except Exception as exc:
42
  print(f"⚠️ Metrics logging skipped: {exc}")
 
36
  save_job_metrics_to_supabase(
37
  url=str(body.url),
38
  stats=stats,
39
+ user_id=body.user_id,
40
  )
41
  except Exception as exc:
42
  print(f"⚠️ Metrics logging skipped: {exc}")
backend/app/models/chat.py CHANGED
@@ -10,6 +10,7 @@ class ChatMessage(BaseModel):
10
  class ChatRequest(BaseModel):
11
  system_prompt: str
12
  messages: List[ChatMessage]
 
13
 
14
 
15
  class ChatResponse(BaseModel):
 
10
  class ChatRequest(BaseModel):
11
  system_prompt: str
12
  messages: List[ChatMessage]
13
+ user_id: Optional[str] = None
14
 
15
 
16
  class ChatResponse(BaseModel):
backend/app/models/jobs.py CHANGED
@@ -5,6 +5,7 @@ from typing import Optional, Any, List
5
  class JobCreate(BaseModel):
6
  url: HttpUrl
7
  force_refresh: bool = False
 
8
 
9
 
10
  class JobStatus(BaseModel):
 
5
  class JobCreate(BaseModel):
6
  url: HttpUrl
7
  force_refresh: bool = False
8
+ user_id: Optional[str] = None
9
 
10
 
11
  class JobStatus(BaseModel):
frontend/src/App.jsx CHANGED
@@ -255,7 +255,11 @@ export default function App() {
255
  const resp = await fetch(`${API_BASE_URL}/jobs/run`, {
256
  method: "POST",
257
  headers: { "Content-Type": "application/json" },
258
- body: JSON.stringify({ url: targetUrl, force_refresh: forceRefresh }),
 
 
 
 
259
  });
260
  if (!resp.ok) {
261
  const msg = await resp.text();
@@ -488,6 +492,7 @@ export default function App() {
488
  body: JSON.stringify({
489
  system_prompt: systemPrompt,
490
  messages: newMessages,
 
491
  }),
492
  });
493
  if (!resp.ok) {
 
255
  const resp = await fetch(`${API_BASE_URL}/jobs/run`, {
256
  method: "POST",
257
  headers: { "Content-Type": "application/json" },
258
+ body: JSON.stringify({
259
+ url: targetUrl,
260
+ force_refresh: forceRefresh,
261
+ user_id: session?.user?.id
262
+ }),
263
  });
264
  if (!resp.ok) {
265
  const msg = await resp.text();
 
492
  body: JSON.stringify({
493
  system_prompt: systemPrompt,
494
  messages: newMessages,
495
+ user_id: session?.user?.id
496
  }),
497
  });
498
  if (!resp.ok) {