Spaces:
3SCError404
/
Paused

dushyantsingh0 commited on
Commit
6c00e74
·
1 Parent(s): e6dd383

backend stabilization

Browse files
api/v1/nexus.py CHANGED
@@ -312,21 +312,41 @@ async def trigger_history_recovery(
312
  )
313
 
314
  # 3. Persist Job Metadata for secure lookup
315
- from models.worker_job import WorkerJob
316
  from agents.utils import get_deterministic_uuid
 
317
 
318
  # Arq job ids are strings or bytes, we use get_deterministic_uuid to match worker.py logic
319
  job_uuid = get_deterministic_uuid(job.job_id)
320
 
321
- # Update metadata_json to track owner
322
- upd_stmt = update(WorkerJob).where(WorkerJob.id == job_uuid).values(
323
- metadata_json={
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  "owner_id": str(current_user.id),
325
  "thread_id": str(thread_id),
326
  "type": "history_recovery"
327
  }
328
- )
329
- await db.execute(upd_stmt)
330
  await db.commit()
331
 
332
  return {"status": "queued", "job_id": job.job_id}
 
312
  )
313
 
314
  # 3. Persist Job Metadata for secure lookup
315
+ from models.worker_job import WorkerJob, JobStatus
316
  from agents.utils import get_deterministic_uuid
317
+ from datetime import datetime
318
 
319
  # Arq job ids are strings or bytes, we use get_deterministic_uuid to match worker.py logic
320
  job_uuid = get_deterministic_uuid(job.job_id)
321
 
322
+ # Proactive Job Telemetry: Ensure the record exists for polling immediately
323
+ # We use a select/insert pattern to be safe, though a new job_id should involve a new UUID
324
+ job_stmt = select(WorkerJob).where(WorkerJob.id == job_uuid)
325
+ existing_job = (await db.execute(job_stmt)).scalar_one_or_none()
326
+
327
+ if not existing_job:
328
+ new_job = WorkerJob(
329
+ id=job_uuid,
330
+ task_name="recover_nexus_history",
331
+ status=JobStatus.QUEUED,
332
+ args=None,
333
+ kwargs=None,
334
+ started_at=None,
335
+ metadata_json={
336
+ "owner_id": str(current_user.id),
337
+ "thread_id": str(thread_id),
338
+ "type": "history_recovery"
339
+ }
340
+ )
341
+ db.add(new_job)
342
+ else:
343
+ # Update existing record if it somehow already exists
344
+ existing_job.metadata_json = {
345
  "owner_id": str(current_user.id),
346
  "thread_id": str(thread_id),
347
  "type": "history_recovery"
348
  }
349
+
 
350
  await db.commit()
351
 
352
  return {"status": "queued", "job_id": job.job_id}
frontend/apps/customer/src/components/Analytics.tsx CHANGED
@@ -3,6 +3,7 @@ import { StatusBadge, PriorityBadge } from './Badges';
3
  import { useReports, useServiceNarrative, NexusMarkdown } from '@nexus/shared';
4
  import { Skeleton } from './Skeleton';
5
  import { BarChart, Bar, XAxis, YAxis, PieChart, Pie, Cell, ResponsiveContainer, Tooltip, Sector } from 'recharts';
 
6
 
7
  const COLORS = {
8
  brand: "var(--primary)",
@@ -183,6 +184,8 @@ export const Analytics: React.FC<AnalyticsProps> = ({ tickets }) => {
183
  value: showReportsLoading ? <Skeleton width={60} height={32} /> : total - resolvedCount,
184
  footer: showReportsLoading ? <Skeleton width={100} height={12} /> : `${total} Total Tickets`,
185
  color: "hsl(217, 91%, 60%)",
 
 
186
  viz: showReportsLoading ? <Skeleton width={100} height={30} /> : <Sparkline data={volumeValues.length > 0 ? volumeValues : [0,0,0]} color="hsl(217, 91%, 60%)" />
187
  },
188
  {
@@ -190,6 +193,8 @@ export const Analytics: React.FC<AnalyticsProps> = ({ tickets }) => {
190
  value: showReportsLoading ? <Skeleton width={80} height={32} /> : (sla ? `${Math.round(sla.sla_compliance_rate * 100)}%` : "100%"),
191
  footer: showReportsLoading ? <Skeleton width={100} height={12} /> : `${sla?.breached_tickets || 0} Rule Breaches`,
192
  color: "var(--success)",
 
 
193
  viz: showReportsLoading ? <Skeleton height={4} /> : <div style={{ height: 4, width: '100%', background: "rgba(255,255,255,0.05)", borderRadius: 2 }}>
194
  <div style={{ height: '100%', width: sla ? `${sla.sla_compliance_rate * 100}%` : '100%', background: "var(--success)", borderRadius: 2 }} />
195
  </div>
@@ -199,6 +204,8 @@ export const Analytics: React.FC<AnalyticsProps> = ({ tickets }) => {
199
  value: showReportsLoading ? <Skeleton width={70} height={32} /> : (avgResHours > 0 ? `${avgResHours.toFixed(1)}h` : "-"),
200
  footer: showReportsLoading ? <Skeleton width={100} height={12} /> : `${resolvedCount} Resolved Tickets`,
201
  color: "hsl(262, 83%, 58%)",
 
 
202
  viz: showReportsLoading ? <Skeleton width={120} height={11} /> : <div style={{ fontSize: 11, fontWeight: 600, color: COLORS.gray400 }}>Operational Threshold: 24h</div>
203
  },
204
  {
@@ -206,6 +213,8 @@ export const Analytics: React.FC<AnalyticsProps> = ({ tickets }) => {
206
  value: showReportsLoading ? <Skeleton width={60} height={32} /> : (csat ? csat.average_rating.toFixed(1) : "-"),
207
  footer: showReportsLoading ? <Skeleton width={100} height={12} /> : (csat?.total_responses ? `${csat.total_responses} Total Ratings` : "No Ratings Yet"),
208
  color: "hsl(38, 92%, 50%)",
 
 
209
  viz: null
210
  },
211
  ].map(s => (
@@ -218,17 +227,24 @@ export const Analytics: React.FC<AnalyticsProps> = ({ tickets }) => {
218
  flexDirection: "column",
219
  justifyContent: "space-between",
220
  height: 140,
221
- boxShadow: "0 4px 12px rgba(0,0,0,0.1)",
222
  position: 'relative',
223
  overflow: 'hidden'
224
  }}>
225
- <div style={{ flex: 1, display: "flex", flexDirection: "column", justifyContent: "center" }}>
226
- <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 }}>
 
 
 
 
227
  <span style={{ fontSize: 10, color: COLORS.muted, fontWeight: 800, textTransform: "uppercase", letterSpacing: "0.1em" }}>{s.label}</span>
 
 
 
228
  </div>
229
- <div style={{ fontSize: 26, fontWeight: 800, color: COLORS.text, marginBottom: 4 }}>{s.value}</div>
230
  </div>
231
- <div style={{ height: 30, display: "flex", flexDirection: "column", justifyContent: "flex-end" }}>
232
  <div style={{ marginBottom: 6 }}>{s.viz}</div>
233
  <div style={{ fontSize: 11, color: COLORS.muted, fontWeight: 600 }}>{s.footer}</div>
234
  </div>
 
3
  import { useReports, useServiceNarrative, NexusMarkdown } from '@nexus/shared';
4
  import { Skeleton } from './Skeleton';
5
  import { BarChart, Bar, XAxis, YAxis, PieChart, Pie, Cell, ResponsiveContainer, Tooltip, Sector } from 'recharts';
6
+ import { Ticket, Activity, Clock, Target, Star } from 'lucide-react';
7
 
8
  const COLORS = {
9
  brand: "var(--primary)",
 
184
  value: showReportsLoading ? <Skeleton width={60} height={32} /> : total - resolvedCount,
185
  footer: showReportsLoading ? <Skeleton width={100} height={12} /> : `${total} Total Tickets`,
186
  color: "hsl(217, 91%, 60%)",
187
+ icon: <Ticket size={18} />,
188
+ bgIcon: <Ticket size={80} />,
189
  viz: showReportsLoading ? <Skeleton width={100} height={30} /> : <Sparkline data={volumeValues.length > 0 ? volumeValues : [0,0,0]} color="hsl(217, 91%, 60%)" />
190
  },
191
  {
 
193
  value: showReportsLoading ? <Skeleton width={80} height={32} /> : (sla ? `${Math.round(sla.sla_compliance_rate * 100)}%` : "100%"),
194
  footer: showReportsLoading ? <Skeleton width={100} height={12} /> : `${sla?.breached_tickets || 0} Rule Breaches`,
195
  color: "var(--success)",
196
+ icon: <Target size={18} />,
197
+ bgIcon: <Target size={80} />,
198
  viz: showReportsLoading ? <Skeleton height={4} /> : <div style={{ height: 4, width: '100%', background: "rgba(255,255,255,0.05)", borderRadius: 2 }}>
199
  <div style={{ height: '100%', width: sla ? `${sla.sla_compliance_rate * 100}%` : '100%', background: "var(--success)", borderRadius: 2 }} />
200
  </div>
 
204
  value: showReportsLoading ? <Skeleton width={70} height={32} /> : (avgResHours > 0 ? `${avgResHours.toFixed(1)}h` : "-"),
205
  footer: showReportsLoading ? <Skeleton width={100} height={12} /> : `${resolvedCount} Resolved Tickets`,
206
  color: "hsl(262, 83%, 58%)",
207
+ icon: <Clock size={18} />,
208
+ bgIcon: <Clock size={80} />,
209
  viz: showReportsLoading ? <Skeleton width={120} height={11} /> : <div style={{ fontSize: 11, fontWeight: 600, color: COLORS.gray400 }}>Operational Threshold: 24h</div>
210
  },
211
  {
 
213
  value: showReportsLoading ? <Skeleton width={60} height={32} /> : (csat ? csat.average_rating.toFixed(1) : "-"),
214
  footer: showReportsLoading ? <Skeleton width={100} height={12} /> : (csat?.total_responses ? `${csat.total_responses} Total Ratings` : "No Ratings Yet"),
215
  color: "hsl(38, 92%, 50%)",
216
+ icon: <Star size={18} />,
217
+ bgIcon: <Star size={80} />,
218
  viz: null
219
  },
220
  ].map(s => (
 
227
  flexDirection: "column",
228
  justifyContent: "space-between",
229
  height: 140,
230
+ boxShadow: "0 4px 12px rgba(0,0,0,0.05)",
231
  position: 'relative',
232
  overflow: 'hidden'
233
  }}>
234
+ <div style={{ position: 'absolute', right: -15, bottom: -15, opacity: 0.03, color: s.color, transform: 'rotate(-10deg)' }}>
235
+ {s.bgIcon}
236
+ </div>
237
+
238
+ <div style={{ flex: 1, display: "flex", flexDirection: "column", justifyContent: "center", position: 'relative', zIndex: 1 }}>
239
+ <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 12 }}>
240
  <span style={{ fontSize: 10, color: COLORS.muted, fontWeight: 800, textTransform: "uppercase", letterSpacing: "0.1em" }}>{s.label}</span>
241
+ <div style={{ width: 32, height: 32, borderRadius: 8, background: `rgba(${s.color.includes('hsl') ? '124, 58, 237' : '16, 185, 129'}, 0.1)`, display: 'flex', alignItems: 'center', justifyContent: 'center', color: s.color }}>
242
+ {s.icon}
243
+ </div>
244
  </div>
245
+ <div style={{ fontSize: 28, fontWeight: 800, color: COLORS.text, marginBottom: 4 }}>{s.value}</div>
246
  </div>
247
+ <div style={{ height: 30, display: "flex", flexDirection: "column", justifyContent: "flex-end", position: 'relative', zIndex: 1 }}>
248
  <div style={{ marginBottom: 6 }}>{s.viz}</div>
249
  <div style={{ fontSize: 11, color: COLORS.muted, fontWeight: 600 }}>{s.footer}</div>
250
  </div>
frontend/packages/shared/src/components/NexusHub.tsx CHANGED
@@ -103,21 +103,25 @@ export const NexusHub: React.FC = () => {
103
  position: 'relative'
104
  }}>
105
  <style>{`
106
- @keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
107
- @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
108
- @keyframes pulse-soft { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
109
- .session-item:hover .rename-btn { opacity: 1 !important; }
110
- .drawer-overlay {
111
- position: absolute;
112
- inset: 0;
113
- background: rgba(0,0,0,0.1);
114
- backdrop-filter: blur(4px);
115
- z-index: 40;
116
- opacity: 0;
117
- pointer-events: none;
118
- transition: opacity 0.3s;
119
- }
120
- .drawer-overlay.active { opacity: 1; pointer-events: auto; }
 
 
 
 
121
  `}</style>
122
 
123
  {/* Sidebar Drawer: Session History */}
@@ -286,7 +290,7 @@ export const NexusHub: React.FC = () => {
286
  <div style={{ width: 1, height: 24, background: COLORS.gray200 }} />
287
  <div>
288
  <div style={{ fontSize: 15, fontWeight: 800, color: COLORS.gray900 }}>
289
- {threadId ? sessions.find(s => s.id === threadId)?.title : "New Nexus Intelligence Session"}
290
  </div>
291
  <div style={{ fontSize: 11, color: COLORS.gray400, fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.02em' }}>
292
  Secure AI Link Active
@@ -314,20 +318,6 @@ export const NexusHub: React.FC = () => {
314
  >
315
  <span>+</span> New Session
316
  </button>
317
- <div style={{
318
- padding: '6px 12px',
319
- borderRadius: 20,
320
- background: '#ECFDF5',
321
- color: '#059669',
322
- fontSize: 11,
323
- fontWeight: 800,
324
- display: 'flex',
325
- alignItems: 'center',
326
- gap: 6
327
- }}>
328
- <div style={{ width: 6, height: 6, borderRadius: '50%', background: '#10B981' }} />
329
- ENCRYPTED
330
- </div>
331
  </div>
332
  </div>
333
 
@@ -362,9 +352,29 @@ export const NexusHub: React.FC = () => {
362
  )}
363
 
364
  {messages.length === 0 && !loading && !historyLoading && (
365
- <div style={{ textAlign: 'center', marginTop: '15vh', maxWidth: 640, alignSelf: 'center' }}>
366
- <div style={{ fontSize: 44, marginBottom: 24, opacity: 0.8 }}>🛡️</div>
367
- <h2 style={{ fontSize: 24, fontWeight: 800, color: COLORS.gray900, marginBottom: 12 }}>Nexus Command Gateway</h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
  <p style={{ fontSize: 15, color: COLORS.gray500, marginBottom: 48, fontWeight: 500 }}>
369
  Secure workspace orchestration and multi-agent intelligence.
370
  </p>
@@ -504,7 +514,7 @@ export const NexusHub: React.FC = () => {
504
  onBlurCapture={e => { e.currentTarget.style.borderColor = COLORS.gray200; e.currentTarget.style.boxShadow = '0 20px 50px -10px rgba(0,0,0,0.06)'; }}
505
  >
506
  <input
507
- placeholder="Ask Nexus anything: 'Summarize my tickets', 'Reassign to SC_AGENT'..."
508
  value={inputText}
509
  onChange={e => setInputText(e.target.value)}
510
  disabled={loading}
@@ -545,7 +555,7 @@ export const NexusHub: React.FC = () => {
545
  </button>
546
  </form>
547
  <div style={{ textAlign: 'center', marginTop: 16, fontSize: 11, color: COLORS.gray400, fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.05em' }}>
548
- Enterprise Grade Intelligence • SOC-2 Compliant Link
549
  </div>
550
  </div>
551
  </div>
 
103
  position: 'relative'
104
  }}>
105
  <style>{`
106
+ @keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
107
+ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
108
+ @keyframes pulse-soft { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
109
+ @keyframes nexus-pulse {
110
+ 0% { transform: scale(1); opacity: 0.6; }
111
+ 100% { transform: scale(1.6); opacity: 0; }
112
+ }
113
+ .session-item:hover .rename-btn { opacity: 1 !important; }
114
+ .drawer-overlay {
115
+ position: absolute;
116
+ inset: 0;
117
+ background: rgba(0,0,0,0.1);
118
+ backdrop-filter: blur(4px);
119
+ z-index: 40;
120
+ opacity: 0;
121
+ pointer-events: none;
122
+ transition: opacity 0.3s;
123
+ }
124
+ .drawer-overlay.active { opacity: 1; pointer-events: auto; }
125
  `}</style>
126
 
127
  {/* Sidebar Drawer: Session History */}
 
290
  <div style={{ width: 1, height: 24, background: COLORS.gray200 }} />
291
  <div>
292
  <div style={{ fontSize: 15, fontWeight: 800, color: COLORS.gray900 }}>
293
+ {threadId ? sessions.find(s => s.id === threadId)?.title : "Nexus Hub"}
294
  </div>
295
  <div style={{ fontSize: 11, color: COLORS.gray400, fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.02em' }}>
296
  Secure AI Link Active
 
318
  >
319
  <span>+</span> New Session
320
  </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  </div>
322
  </div>
323
 
 
352
  )}
353
 
354
  {messages.length === 0 && !loading && !historyLoading && (
355
+ <div style={{ textAlign: 'center', marginTop: '10vh', maxWidth: 640, alignSelf: 'center' }}>
356
+ <div style={{ position: 'relative', width: 72, height: 72, margin: '0 auto 32px' }}>
357
+ <div style={{
358
+ width: 72, height: 72, borderRadius: '50%',
359
+ background: 'linear-gradient(135deg, #7C3AED 0%, #6D28D9 100%)',
360
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
361
+ fontSize: 28, color: '#fff', fontWeight: 900, position: 'relative', zIndex: 2,
362
+ boxShadow: '0 8px 30px rgba(124, 58, 237, 0.4)'
363
+ }}>N</div>
364
+ <div style={{
365
+ position: 'absolute', inset: 0, borderRadius: '50%',
366
+ border: `2px solid ${COLORS.brand}`,
367
+ animation: 'nexus-pulse 2s infinite',
368
+ pointerEvents: 'none'
369
+ }} />
370
+ <div style={{
371
+ position: 'absolute', top: 0, right: 0, width: 18, height: 18,
372
+ borderRadius: '50%', background: '#10B981', border: '3px solid #fff',
373
+ boxShadow: '0 0 10px rgba(16, 185, 129, 0.5)', zIndex: 3
374
+ }} />
375
+ </div>
376
+
377
+ <h2 style={{ fontSize: 24, fontWeight: 800, color: COLORS.gray900, marginBottom: 12 }}>Nexus Hub</h2>
378
  <p style={{ fontSize: 15, color: COLORS.gray500, marginBottom: 48, fontWeight: 500 }}>
379
  Secure workspace orchestration and multi-agent intelligence.
380
  </p>
 
514
  onBlurCapture={e => { e.currentTarget.style.borderColor = COLORS.gray200; e.currentTarget.style.boxShadow = '0 20px 50px -10px rgba(0,0,0,0.06)'; }}
515
  >
516
  <input
517
+ placeholder="Ask Nexus anything..."
518
  value={inputText}
519
  onChange={e => setInputText(e.target.value)}
520
  disabled={loading}
 
555
  </button>
556
  </form>
557
  <div style={{ textAlign: 'center', marginTop: 16, fontSize: 11, color: COLORS.gray400, fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.05em' }}>
558
+ Powered by 3sc
559
  </div>
560
  </div>
561
  </div>