Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
219e91e
1
Parent(s): 47835df
backend stabilization
Browse files
frontend/apps/internal/src/components/ForensicsView.module.css
CHANGED
|
@@ -355,3 +355,83 @@
|
|
| 355 |
opacity: 0.5;
|
| 356 |
cursor: not-allowed;
|
| 357 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
opacity: 0.5;
|
| 356 |
cursor: not-allowed;
|
| 357 |
}
|
| 358 |
+
|
| 359 |
+
.aiBadge {
|
| 360 |
+
display: flex;
|
| 361 |
+
align-items: center;
|
| 362 |
+
gap: 8px;
|
| 363 |
+
padding: 6px 14px;
|
| 364 |
+
background: rgba(139, 92, 246, 0.1);
|
| 365 |
+
border: 1px solid rgba(139, 92, 246, 0.2);
|
| 366 |
+
border-radius: 20px;
|
| 367 |
+
color: var(--accent);
|
| 368 |
+
font-size: 11px;
|
| 369 |
+
font-weight: 700;
|
| 370 |
+
letter-spacing: 0.5px;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
.agentInfo {
|
| 374 |
+
display: flex;
|
| 375 |
+
flex-direction: column;
|
| 376 |
+
gap: 2px;
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
.agentName {
|
| 380 |
+
font-size: 12px;
|
| 381 |
+
font-weight: 700;
|
| 382 |
+
color: var(--text1);
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
.modelInfo {
|
| 386 |
+
font-size: 10px;
|
| 387 |
+
color: var(--text3);
|
| 388 |
+
font-family: var(--font-mono);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
.metricStack {
|
| 392 |
+
display: flex;
|
| 393 |
+
flex-direction: column;
|
| 394 |
+
gap: 4px;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
.metricItem {
|
| 398 |
+
display: flex;
|
| 399 |
+
align-items: center;
|
| 400 |
+
gap: 6px;
|
| 401 |
+
font-size: 10px;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
.mLabel {
|
| 405 |
+
color: var(--text3);
|
| 406 |
+
font-weight: 600;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
.mValue {
|
| 410 |
+
color: var(--text2);
|
| 411 |
+
font-weight: 700;
|
| 412 |
+
font-family: var(--font-mono);
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
.traceSection {
|
| 416 |
+
margin-bottom: 8px;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
.traceSection:last-child {
|
| 420 |
+
margin-bottom: 0;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
.traceLabel {
|
| 424 |
+
display: block;
|
| 425 |
+
font-size: 9px;
|
| 426 |
+
font-weight: 800;
|
| 427 |
+
color: var(--text3);
|
| 428 |
+
margin-bottom: 4px;
|
| 429 |
+
letter-spacing: 0.5px;
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
.traceDivider {
|
| 433 |
+
height: 1px;
|
| 434 |
+
background: var(--border);
|
| 435 |
+
margin: 12px 0;
|
| 436 |
+
opacity: 0.5;
|
| 437 |
+
}
|
frontend/apps/internal/src/components/ForensicsView.tsx
CHANGED
|
@@ -26,6 +26,18 @@ interface AuditLog {
|
|
| 26 |
created_at: string;
|
| 27 |
}
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
type ForensicsTab = 'ai' | 'security';
|
| 30 |
|
| 31 |
interface ForensicsViewProps {
|
|
@@ -36,6 +48,7 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 36 |
useAuth();
|
| 37 |
const [activeTab, setActiveTab] = useState<ForensicsTab>('security');
|
| 38 |
const [logs, setLogs] = useState<AuditLog[]>([]);
|
|
|
|
| 39 |
const [loading, setLoading] = useState(true);
|
| 40 |
const [filterType, setFilterType] = useState<string>('');
|
| 41 |
const [offset, setOffset] = useState(0);
|
|
@@ -71,11 +84,41 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 71 |
}
|
| 72 |
}, [filterType, workspaceId, offset]);
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
useEffect(() => {
|
|
|
|
|
|
|
| 75 |
if (activeTab === 'security') {
|
| 76 |
-
setOffset(0);
|
| 77 |
-
setHasMore(true);
|
| 78 |
fetchAuditLogs(false);
|
|
|
|
|
|
|
| 79 |
}
|
| 80 |
}, [activeTab, filterType, workspaceId]);
|
| 81 |
|
|
@@ -188,6 +231,113 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 188 |
</div>
|
| 189 |
);
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
return (
|
| 192 |
<div className={styles.container}>
|
| 193 |
<nav className={styles.tabNav}>
|
|
@@ -208,14 +358,7 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 208 |
</nav>
|
| 209 |
|
| 210 |
<div className={styles.content}>
|
| 211 |
-
{activeTab === 'security' ? renderSecurityAudit() : (
|
| 212 |
-
<div className={styles.placeholder}>
|
| 213 |
-
<AlertTriangle size={32} />
|
| 214 |
-
<h2>Neural Trace Forensics</h2>
|
| 215 |
-
<p>AI reasoning audit trails are currently migrating to the new stream protocol. Historical data is accessible via the Nexus Control panel.</p>
|
| 216 |
-
<button className={styles.actionBtn} onClick={() => setActiveTab('security')}>View Security Audit Instead</button>
|
| 217 |
-
</div>
|
| 218 |
-
)}
|
| 219 |
</div>
|
| 220 |
</div>
|
| 221 |
);
|
|
|
|
| 26 |
created_at: string;
|
| 27 |
}
|
| 28 |
|
| 29 |
+
interface AIInteraction {
|
| 30 |
+
id: string;
|
| 31 |
+
agent_name: string;
|
| 32 |
+
model_info: string;
|
| 33 |
+
input_data: any;
|
| 34 |
+
output_data: any;
|
| 35 |
+
status: string;
|
| 36 |
+
duration_ms: any;
|
| 37 |
+
usage_metadata: any;
|
| 38 |
+
created_at: string;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
type ForensicsTab = 'ai' | 'security';
|
| 42 |
|
| 43 |
interface ForensicsViewProps {
|
|
|
|
| 48 |
useAuth();
|
| 49 |
const [activeTab, setActiveTab] = useState<ForensicsTab>('security');
|
| 50 |
const [logs, setLogs] = useState<AuditLog[]>([]);
|
| 51 |
+
const [aiTraces, setAiTraces] = useState<AIInteraction[]>([]);
|
| 52 |
const [loading, setLoading] = useState(true);
|
| 53 |
const [filterType, setFilterType] = useState<string>('');
|
| 54 |
const [offset, setOffset] = useState(0);
|
|
|
|
| 84 |
}
|
| 85 |
}, [filterType, workspaceId, offset]);
|
| 86 |
|
| 87 |
+
const fetchAIInteractions = useCallback(async (isLoadMore = false) => {
|
| 88 |
+
setLoading(true);
|
| 89 |
+
try {
|
| 90 |
+
const currentOffset = isLoadMore ? offset + LIMIT : 0;
|
| 91 |
+
const params: any = {
|
| 92 |
+
limit: LIMIT,
|
| 93 |
+
offset: currentOffset
|
| 94 |
+
};
|
| 95 |
+
if (workspaceId) params.workspace_id = workspaceId;
|
| 96 |
+
|
| 97 |
+
const res = await api.get('system/interactions/', { params });
|
| 98 |
+
const newTraces = res.data || [];
|
| 99 |
+
|
| 100 |
+
if (isLoadMore) {
|
| 101 |
+
setAiTraces(prev => [...prev, ...newTraces]);
|
| 102 |
+
} else {
|
| 103 |
+
setAiTraces(newTraces);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
setOffset(currentOffset);
|
| 107 |
+
setHasMore(newTraces.length === LIMIT);
|
| 108 |
+
} catch (err) {
|
| 109 |
+
console.error('AI Forensics fetch failed', err);
|
| 110 |
+
} finally {
|
| 111 |
+
setLoading(false);
|
| 112 |
+
}
|
| 113 |
+
}, [workspaceId, offset]);
|
| 114 |
+
|
| 115 |
useEffect(() => {
|
| 116 |
+
setOffset(0);
|
| 117 |
+
setHasMore(true);
|
| 118 |
if (activeTab === 'security') {
|
|
|
|
|
|
|
| 119 |
fetchAuditLogs(false);
|
| 120 |
+
} else {
|
| 121 |
+
fetchAIInteractions(false);
|
| 122 |
}
|
| 123 |
}, [activeTab, filterType, workspaceId]);
|
| 124 |
|
|
|
|
| 231 |
</div>
|
| 232 |
);
|
| 233 |
|
| 234 |
+
const renderNeuralTrace = () => (
|
| 235 |
+
<div className={styles.auditContainer}>
|
| 236 |
+
<div className={styles.auditHeader}>
|
| 237 |
+
<div className={styles.filters}>
|
| 238 |
+
<button className={styles.refreshBtn} onClick={() => fetchAIInteractions(false)} disabled={loading}>
|
| 239 |
+
<RefreshCcw size={14} className={loading && aiTraces.length === 0 ? 'spinning' : ''} />
|
| 240 |
+
</button>
|
| 241 |
+
</div>
|
| 242 |
+
<div className={styles.aiBadge}>
|
| 243 |
+
<Activity size={14} />
|
| 244 |
+
<span>NEURAL STREAM: ACTIVE</span>
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
|
| 248 |
+
<div className={styles.auditTable}>
|
| 249 |
+
<div className={styles.tableHeader}>
|
| 250 |
+
<div className={styles.col}>TIMESTAMP</div>
|
| 251 |
+
<div className={styles.col}>AGENT / MODEL</div>
|
| 252 |
+
<div className={styles.col}>METRICS</div>
|
| 253 |
+
<div className={styles.col}>STATUS</div>
|
| 254 |
+
<div className={styles.col}>INTELLIGENCE</div>
|
| 255 |
+
</div>
|
| 256 |
+
|
| 257 |
+
<div className={styles.tableBody}>
|
| 258 |
+
<AnimatePresence mode="popLayout">
|
| 259 |
+
{aiTraces.map((trace, idx) => (
|
| 260 |
+
<motion.div
|
| 261 |
+
key={trace.id}
|
| 262 |
+
className={styles.tableRow}
|
| 263 |
+
initial={{ opacity: 0, y: 10 }}
|
| 264 |
+
animate={{ opacity: 1, y: 0 }}
|
| 265 |
+
transition={{ delay: idx * 0.02 }}
|
| 266 |
+
>
|
| 267 |
+
<div className={styles.col}>
|
| 268 |
+
<div className={styles.timeWrapper}>
|
| 269 |
+
<Clock size={12} />
|
| 270 |
+
{new Date(trace.created_at).toLocaleTimeString()}
|
| 271 |
+
</div>
|
| 272 |
+
<div className={styles.dateLabel}>{new Date(trace.created_at).toLocaleDateString()}</div>
|
| 273 |
+
</div>
|
| 274 |
+
|
| 275 |
+
<div className={styles.col}>
|
| 276 |
+
<div className={styles.agentInfo}>
|
| 277 |
+
<span className={styles.agentName}>{trace.agent_name.replace(/_/g, ' ').toUpperCase()}</span>
|
| 278 |
+
<span className={styles.modelInfo}>{trace.model_info || 'NEURAL_CORE_V1'}</span>
|
| 279 |
+
</div>
|
| 280 |
+
</div>
|
| 281 |
+
|
| 282 |
+
<div className={styles.col}>
|
| 283 |
+
<div className={styles.metricStack}>
|
| 284 |
+
<div className={styles.metricItem}>
|
| 285 |
+
<span className={styles.mLabel}>LATENCY:</span>
|
| 286 |
+
<span className={styles.mValue}>{trace.duration_ms?.total || trace.duration_ms || 0}ms</span>
|
| 287 |
+
</div>
|
| 288 |
+
<div className={styles.metricItem}>
|
| 289 |
+
<span className={styles.mLabel}>TOKENS:</span>
|
| 290 |
+
<span className={styles.mValue}>{trace.usage_metadata?.total_tokens || 0}</span>
|
| 291 |
+
</div>
|
| 292 |
+
</div>
|
| 293 |
+
</div>
|
| 294 |
+
|
| 295 |
+
<div className={styles.col}>
|
| 296 |
+
<div className={`${styles.actionPill} ${trace.status === 'error' ? styles.fail : styles.pass}`}>
|
| 297 |
+
{(trace.status || 'SUCCESS').toUpperCase()}
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
|
| 301 |
+
<div className={styles.col}>
|
| 302 |
+
<div className={styles.detailBox}>
|
| 303 |
+
<div className={styles.traceSection}>
|
| 304 |
+
<span className={styles.traceLabel}>PROMPT_GUIDE:</span>
|
| 305 |
+
<pre className={styles.jsonDetail}>{JSON.stringify(trace.input_data, null, 2)}</pre>
|
| 306 |
+
</div>
|
| 307 |
+
<div className={styles.traceDivider} />
|
| 308 |
+
<div className={styles.traceSection}>
|
| 309 |
+
<span className={styles.traceLabel}>RESULTANT_INFERENCE:</span>
|
| 310 |
+
<pre className={styles.jsonDetail}>{JSON.stringify(trace.output_data, null, 2)}</pre>
|
| 311 |
+
</div>
|
| 312 |
+
</div>
|
| 313 |
+
</div>
|
| 314 |
+
</motion.div>
|
| 315 |
+
))}
|
| 316 |
+
</AnimatePresence>
|
| 317 |
+
|
| 318 |
+
{hasMore && aiTraces.length > 0 && (
|
| 319 |
+
<div className={styles.paginationFooter}>
|
| 320 |
+
<button
|
| 321 |
+
className={styles.loadMoreBtn}
|
| 322 |
+
onClick={() => fetchAIInteractions(true)}
|
| 323 |
+
disabled={loading}
|
| 324 |
+
>
|
| 325 |
+
{loading ? 'SYNCHRONIZING...' : 'LOAD MORE NEURAL TRACES'}
|
| 326 |
+
</button>
|
| 327 |
+
</div>
|
| 328 |
+
)}
|
| 329 |
+
|
| 330 |
+
{aiTraces.length === 0 && !loading && (
|
| 331 |
+
<div className={styles.emptyState}>
|
| 332 |
+
<Activity size={48} opacity={0.2} />
|
| 333 |
+
<p>No neural traces found in current temporal window.</p>
|
| 334 |
+
</div>
|
| 335 |
+
)}
|
| 336 |
+
</div>
|
| 337 |
+
</div>
|
| 338 |
+
</div>
|
| 339 |
+
);
|
| 340 |
+
|
| 341 |
return (
|
| 342 |
<div className={styles.container}>
|
| 343 |
<nav className={styles.tabNav}>
|
|
|
|
| 358 |
</nav>
|
| 359 |
|
| 360 |
<div className={styles.content}>
|
| 361 |
+
{activeTab === 'security' ? renderSecurityAudit() : renderNeuralTrace()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
</div>
|
| 363 |
</div>
|
| 364 |
);
|
scratch/check_jobs.py
CHANGED
|
@@ -1,22 +1,31 @@
|
|
| 1 |
-
|
| 2 |
import asyncio
|
| 3 |
import sys
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
from core.database import async_session_factory
|
| 10 |
-
from sqlalchemy import select
|
| 11 |
from models.worker_job import WorkerJob
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
async def
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
| 22 |
-
asyncio.run(
|
|
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import sys
|
|
|
|
| 3 |
|
| 4 |
+
if sys.platform == 'win32':
|
| 5 |
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
| 6 |
|
| 7 |
from core.database import async_session_factory
|
|
|
|
| 8 |
from models.worker_job import WorkerJob
|
| 9 |
+
from sqlalchemy import select
|
| 10 |
+
import json
|
| 11 |
|
| 12 |
+
async def check():
|
| 13 |
+
try:
|
| 14 |
+
async with async_session_factory() as db:
|
| 15 |
+
stmt = select(WorkerJob).where(WorkerJob.task_name == "generate_workspace_insights").order_by(WorkerJob.created_at.desc())
|
| 16 |
+
res = await db.execute(stmt)
|
| 17 |
+
jobs = res.scalars().all()
|
| 18 |
+
if not jobs:
|
| 19 |
+
print("No 'generate_workspace_insights' jobs found.")
|
| 20 |
+
# Also check for any jobs without metadata to see what's going on
|
| 21 |
+
res = await db.execute(select(WorkerJob).limit(5))
|
| 22 |
+
for j in res.scalars().all():
|
| 23 |
+
print(f"Sample - Task: {j.task_name} | Meta: {j.metadata_json}")
|
| 24 |
+
return
|
| 25 |
+
for j in jobs:
|
| 26 |
+
print(f"Found! Task: {j.task_name} | Meta: {j.metadata_json}")
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print(f"Error: {e}")
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
+
asyncio.run(check())
|
scratch/trigger_job.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
if sys.platform == 'win32':
|
| 5 |
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
| 6 |
+
|
| 7 |
+
from core.tasks import enqueue_task
|
| 8 |
+
from core.config import get_redis_settings
|
| 9 |
+
from arq import create_pool
|
| 10 |
+
|
| 11 |
+
async def trigger():
|
| 12 |
+
redis_settings = get_redis_settings()
|
| 13 |
+
redis = await create_pool(redis_settings)
|
| 14 |
+
# Testing with a fixed ID to see if it shows up in Worker Lab when filtered
|
| 15 |
+
ws_id = "00000000-0000-0000-0000-000000000001"
|
| 16 |
+
print(f"Triggering insights for {ws_id}...")
|
| 17 |
+
await enqueue_task(redis, "generate_workspace_insights", ws_id)
|
| 18 |
+
print("Enqueued.")
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
asyncio.run(trigger())
|