Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
eced686
1
Parent(s): e81b059
backend stabilisation
Browse files
api/v1/nexus.py
CHANGED
|
@@ -922,16 +922,15 @@ async def generate_workspace_story(
|
|
| 922 |
await db.refresh(story)
|
| 923 |
|
| 924 |
# 4. Enqueue background task (Explicitly route to HEAVY queue)
|
| 925 |
-
|
|
|
|
| 926 |
"generate_workspace_story_task",
|
| 927 |
-
|
| 928 |
user_id=current_user.id,
|
| 929 |
workspace_id=current_user.workspace_id,
|
| 930 |
-
role=str(current_user.role.value) if hasattr(current_user.role, 'value') else str(current_user.role)
|
| 931 |
-
_queue_name="arq:heavy"
|
| 932 |
)
|
| 933 |
-
|
| 934 |
-
story.arq_job_id = job.job_id
|
| 935 |
await db.commit()
|
| 936 |
|
| 937 |
return {"status": "success", "story_id": story.id}
|
|
|
|
| 922 |
await db.refresh(story)
|
| 923 |
|
| 924 |
# 4. Enqueue background task (Explicitly route to HEAVY queue)
|
| 925 |
+
from core.tasks import enqueue_task
|
| 926 |
+
job_uuid = await enqueue_task(
|
| 927 |
"generate_workspace_story_task",
|
| 928 |
+
story.id, # entity_id
|
| 929 |
user_id=current_user.id,
|
| 930 |
workspace_id=current_user.workspace_id,
|
| 931 |
+
role=str(current_user.role.value) if hasattr(current_user.role, 'value') else str(current_user.role)
|
|
|
|
| 932 |
)
|
| 933 |
+
story.arq_job_id = str(job_uuid) if job_uuid else None
|
|
|
|
| 934 |
await db.commit()
|
| 935 |
|
| 936 |
return {"status": "success", "story_id": story.id}
|
frontend/apps/internal/src/components/ForensicsView.module.css
CHANGED
|
@@ -150,9 +150,43 @@
|
|
| 150 |
}
|
| 151 |
|
| 152 |
.tableBody {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
flex: 1;
|
| 154 |
overflow-y: auto;
|
| 155 |
padding: 4px 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
}
|
| 157 |
|
| 158 |
.tableRow {
|
|
|
|
| 150 |
}
|
| 151 |
|
| 152 |
.tableBody {
|
| 153 |
+
flex: 1;
|
| 154 |
+
min-height: 0;
|
| 155 |
+
position: relative;
|
| 156 |
+
display: flex;
|
| 157 |
+
flex-direction: column;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
.tableScroll {
|
| 161 |
flex: 1;
|
| 162 |
overflow-y: auto;
|
| 163 |
padding: 4px 0;
|
| 164 |
+
transition: opacity 0.3s ease;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
.tableBody.loading .tableScroll {
|
| 168 |
+
opacity: 0.3;
|
| 169 |
+
pointer-events: none;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
.loadingOverlay {
|
| 173 |
+
position: absolute;
|
| 174 |
+
top: 0;
|
| 175 |
+
left: 0;
|
| 176 |
+
right: 0;
|
| 177 |
+
bottom: 0;
|
| 178 |
+
z-index: 100;
|
| 179 |
+
display: flex;
|
| 180 |
+
flex-direction: column;
|
| 181 |
+
align-items: center;
|
| 182 |
+
justify-content: center;
|
| 183 |
+
gap: 16px;
|
| 184 |
+
background: var(--bg-dark);
|
| 185 |
+
opacity: 0.95;
|
| 186 |
+
color: var(--accent);
|
| 187 |
+
font-size: 12px;
|
| 188 |
+
font-weight: 700;
|
| 189 |
+
letter-spacing: 1px;
|
| 190 |
}
|
| 191 |
|
| 192 |
.tableRow {
|
frontend/apps/internal/src/components/ForensicsView.tsx
CHANGED
|
@@ -56,6 +56,7 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 56 |
const [page, setPage] = useState(1);
|
| 57 |
const [hasMore, setHasMore] = useState(true);
|
| 58 |
const [searchTerm, setSearchTerm] = useState<string>('');
|
|
|
|
| 59 |
const LIMIT = 20; // Smaller limit for better pagination feel
|
| 60 |
|
| 61 |
const fetchAuditLogs = useCallback(async (targetPage = 1) => {
|
|
@@ -109,12 +110,19 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 109 |
|
| 110 |
useEffect(() => {
|
| 111 |
if (activeTab === 'security') {
|
| 112 |
-
fetchAuditLogs(
|
| 113 |
} else {
|
| 114 |
-
fetchAIInteractions(
|
| 115 |
}
|
| 116 |
}, [activeTab, filterType, searchTerm, workspaceId]);
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
const renderSecurityAudit = () => (
|
| 119 |
<div className={styles.auditContainer}>
|
| 120 |
<div className={styles.auditHeader}>
|
|
@@ -133,13 +141,14 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 133 |
<input
|
| 134 |
type="text"
|
| 135 |
placeholder="SEARCH ENTITY ID..."
|
| 136 |
-
value={
|
| 137 |
-
onChange={(e) =>
|
|
|
|
| 138 |
style={{ background: 'transparent', border: 'none', color: 'inherit', fontSize: '11px', outline: 'none', width: '150px' }}
|
| 139 |
/>
|
| 140 |
</div>
|
| 141 |
<button className={styles.refreshBtn} onClick={() => fetchAuditLogs(1)} disabled={loading}>
|
| 142 |
-
<RefreshCcw size={14} className={loading
|
| 143 |
</button>
|
| 144 |
</div>
|
| 145 |
<div className={styles.auditBadge}>
|
|
@@ -157,7 +166,21 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 157 |
<div className={styles.col}>INTELLIGENCE</div>
|
| 158 |
</div>
|
| 159 |
|
| 160 |
-
<div className={styles.tableBody}>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
<AnimatePresence mode="popLayout">
|
| 162 |
{logs.map((log, idx) => (
|
| 163 |
<motion.div
|
|
@@ -253,13 +276,14 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 253 |
<input
|
| 254 |
type="text"
|
| 255 |
placeholder="SEARCH TICKET ID..."
|
| 256 |
-
value={
|
| 257 |
-
onChange={(e) =>
|
|
|
|
| 258 |
style={{ background: 'transparent', border: 'none', color: 'inherit', fontSize: '11px', outline: 'none', width: '180px' }}
|
| 259 |
/>
|
| 260 |
</div>
|
| 261 |
<button className={styles.refreshBtn} onClick={() => fetchAIInteractions(1)} disabled={loading}>
|
| 262 |
-
<RefreshCcw size={14} className={loading
|
| 263 |
</button>
|
| 264 |
</div>
|
| 265 |
<div className={styles.aiBadge}>
|
|
@@ -277,7 +301,21 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 277 |
<div className={styles.col}>INTELLIGENCE</div>
|
| 278 |
</div>
|
| 279 |
|
| 280 |
-
<div className={styles.tableBody}>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
<AnimatePresence mode="popLayout">
|
| 282 |
{aiTraces.map((trace, idx) => (
|
| 283 |
<motion.div
|
|
@@ -376,14 +414,14 @@ export const ForensicsView: React.FC<ForensicsViewProps> = ({ workspaceId }) =>
|
|
| 376 |
<nav className={styles.tabNav}>
|
| 377 |
<button
|
| 378 |
className={`${styles.tabBtn} ${activeTab === 'security' ? styles.active : ''}`}
|
| 379 |
-
onClick={() => setActiveTab('security')}
|
| 380 |
>
|
| 381 |
<ShieldCheck size={18} />
|
| 382 |
SECURITY AUDIT LOG
|
| 383 |
</button>
|
| 384 |
<button
|
| 385 |
className={`${styles.tabBtn} ${activeTab === 'ai' ? styles.active : ''}`}
|
| 386 |
-
onClick={() => setActiveTab('ai')}
|
| 387 |
>
|
| 388 |
<Activity size={18} />
|
| 389 |
NEURAL TRACE FORENSICS
|
|
|
|
| 56 |
const [page, setPage] = useState(1);
|
| 57 |
const [hasMore, setHasMore] = useState(true);
|
| 58 |
const [searchTerm, setSearchTerm] = useState<string>('');
|
| 59 |
+
const [localSearch, setLocalSearch] = useState<string>('');
|
| 60 |
const LIMIT = 20; // Smaller limit for better pagination feel
|
| 61 |
|
| 62 |
const fetchAuditLogs = useCallback(async (targetPage = 1) => {
|
|
|
|
| 110 |
|
| 111 |
useEffect(() => {
|
| 112 |
if (activeTab === 'security') {
|
| 113 |
+
fetchAuditLogs(page);
|
| 114 |
} else {
|
| 115 |
+
fetchAIInteractions(page);
|
| 116 |
}
|
| 117 |
}, [activeTab, filterType, searchTerm, workspaceId]);
|
| 118 |
|
| 119 |
+
const handleSearchKeyDown = (e: React.KeyboardEvent) => {
|
| 120 |
+
if (e.key === 'Enter') {
|
| 121 |
+
setPage(1);
|
| 122 |
+
setSearchTerm(localSearch);
|
| 123 |
+
}
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
const renderSecurityAudit = () => (
|
| 127 |
<div className={styles.auditContainer}>
|
| 128 |
<div className={styles.auditHeader}>
|
|
|
|
| 141 |
<input
|
| 142 |
type="text"
|
| 143 |
placeholder="SEARCH ENTITY ID..."
|
| 144 |
+
value={localSearch}
|
| 145 |
+
onChange={(e) => setLocalSearch(e.target.value)}
|
| 146 |
+
onKeyDown={handleSearchKeyDown}
|
| 147 |
style={{ background: 'transparent', border: 'none', color: 'inherit', fontSize: '11px', outline: 'none', width: '150px' }}
|
| 148 |
/>
|
| 149 |
</div>
|
| 150 |
<button className={styles.refreshBtn} onClick={() => fetchAuditLogs(1)} disabled={loading}>
|
| 151 |
+
<RefreshCcw size={14} className={loading ? styles.spinning : ''} />
|
| 152 |
</button>
|
| 153 |
</div>
|
| 154 |
<div className={styles.auditBadge}>
|
|
|
|
| 166 |
<div className={styles.col}>INTELLIGENCE</div>
|
| 167 |
</div>
|
| 168 |
|
| 169 |
+
<div className={`${styles.tableBody} ${loading ? styles.loading : ''}`}>
|
| 170 |
+
<AnimatePresence>
|
| 171 |
+
{loading && (
|
| 172 |
+
<motion.div
|
| 173 |
+
className={styles.loadingOverlay}
|
| 174 |
+
initial={{ opacity: 0 }}
|
| 175 |
+
animate={{ opacity: 1 }}
|
| 176 |
+
exit={{ opacity: 0 }}
|
| 177 |
+
>
|
| 178 |
+
<RefreshCcw size={24} className={styles.spinning} />
|
| 179 |
+
<span>FILTERING AUDIT TRAILS...</span>
|
| 180 |
+
</motion.div>
|
| 181 |
+
)}
|
| 182 |
+
</AnimatePresence>
|
| 183 |
+
<div className={styles.tableScroll}>
|
| 184 |
<AnimatePresence mode="popLayout">
|
| 185 |
{logs.map((log, idx) => (
|
| 186 |
<motion.div
|
|
|
|
| 276 |
<input
|
| 277 |
type="text"
|
| 278 |
placeholder="SEARCH TICKET ID..."
|
| 279 |
+
value={localSearch}
|
| 280 |
+
onChange={(e) => setLocalSearch(e.target.value)}
|
| 281 |
+
onKeyDown={handleSearchKeyDown}
|
| 282 |
style={{ background: 'transparent', border: 'none', color: 'inherit', fontSize: '11px', outline: 'none', width: '180px' }}
|
| 283 |
/>
|
| 284 |
</div>
|
| 285 |
<button className={styles.refreshBtn} onClick={() => fetchAIInteractions(1)} disabled={loading}>
|
| 286 |
+
<RefreshCcw size={14} className={loading ? styles.spinning : ''} />
|
| 287 |
</button>
|
| 288 |
</div>
|
| 289 |
<div className={styles.aiBadge}>
|
|
|
|
| 301 |
<div className={styles.col}>INTELLIGENCE</div>
|
| 302 |
</div>
|
| 303 |
|
| 304 |
+
<div className={`${styles.tableBody} ${loading ? styles.loading : ''}`}>
|
| 305 |
+
<AnimatePresence>
|
| 306 |
+
{loading && (
|
| 307 |
+
<motion.div
|
| 308 |
+
className={styles.loadingOverlay}
|
| 309 |
+
initial={{ opacity: 0 }}
|
| 310 |
+
animate={{ opacity: 1 }}
|
| 311 |
+
exit={{ opacity: 0 }}
|
| 312 |
+
>
|
| 313 |
+
<Activity size={24} className={styles.spinning} />
|
| 314 |
+
<span>ISOLATING NEURAL TRACES...</span>
|
| 315 |
+
</motion.div>
|
| 316 |
+
)}
|
| 317 |
+
</AnimatePresence>
|
| 318 |
+
<div className={styles.tableScroll}>
|
| 319 |
<AnimatePresence mode="popLayout">
|
| 320 |
{aiTraces.map((trace, idx) => (
|
| 321 |
<motion.div
|
|
|
|
| 414 |
<nav className={styles.tabNav}>
|
| 415 |
<button
|
| 416 |
className={`${styles.tabBtn} ${activeTab === 'security' ? styles.active : ''}`}
|
| 417 |
+
onClick={() => { setActiveTab('security'); setLocalSearch(''); setSearchTerm(''); setPage(1); }}
|
| 418 |
>
|
| 419 |
<ShieldCheck size={18} />
|
| 420 |
SECURITY AUDIT LOG
|
| 421 |
</button>
|
| 422 |
<button
|
| 423 |
className={`${styles.tabBtn} ${activeTab === 'ai' ? styles.active : ''}`}
|
| 424 |
+
onClick={() => { setActiveTab('ai'); setLocalSearch(''); setSearchTerm(''); setPage(1); }}
|
| 425 |
>
|
| 426 |
<Activity size={18} />
|
| 427 |
NEURAL TRACE FORENSICS
|
frontend/apps/internal/src/components/TicketDetails.tsx
CHANGED
|
@@ -625,6 +625,7 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
|
|
| 625 |
const resp = await api.post('nexus/query', {
|
| 626 |
query: nextPrompt,
|
| 627 |
ticket_id: ticket?.id,
|
|
|
|
| 628 |
chat_history: sanitizedHistory,
|
| 629 |
is_hidden: true
|
| 630 |
});
|
|
|
|
| 625 |
const resp = await api.post('nexus/query', {
|
| 626 |
query: nextPrompt,
|
| 627 |
ticket_id: ticket?.id,
|
| 628 |
+
workspace_id: ticket?.workspace_id,
|
| 629 |
chat_history: sanitizedHistory,
|
| 630 |
is_hidden: true
|
| 631 |
});
|
tasks/system.py
CHANGED
|
@@ -163,8 +163,22 @@ async def enqueue_task(task_or_pool: Any, *args, **kwargs):
|
|
| 163 |
# Capture workspace_id for filtering — keep it in task_kwargs so the task receives it
|
| 164 |
if "workspace_id" in task_kwargs:
|
| 165 |
task_kwargs['metadata_json']["workspace_id"] = str(task_kwargs["workspace_id"])
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
# PRE-RECORD: Create the job entry in DB immediately so it's visible while queued
|
| 170 |
from agents.utils import get_deterministic_uuid, sanitize_for_db
|
|
|
|
| 163 |
# Capture workspace_id for filtering — keep it in task_kwargs so the task receives it
|
| 164 |
if "workspace_id" in task_kwargs:
|
| 165 |
task_kwargs['metadata_json']["workspace_id"] = str(task_kwargs["workspace_id"])
|
| 166 |
+
|
| 167 |
+
# SMARTER AUTO-DETECTION: Extract workspace_id from positional args for known task patterns
|
| 168 |
+
if "workspace_id" not in task_kwargs['metadata_json']:
|
| 169 |
+
# Pattern A: workspace_id is the first argument (e.g. insights, stories, pulse)
|
| 170 |
+
if task_name in ["generate_workspace_insights", "refresh_active_workspace_insights", "generate_workspace_story_task", "nexus_pulse_check", "monitor_sla_thresholds"]:
|
| 171 |
+
task_kwargs['metadata_json']["workspace_id"] = str(entity_id)
|
| 172 |
+
# Pattern B: workspace_id is the second argument (e.g. send_triple_notification, notify_mentions, record_workflow_step)
|
| 173 |
+
elif task_name in ["send_triple_notification", "notify_mentions", "record_workflow_step_task", "recover_nexus_history"] and len(final_args) >= 2:
|
| 174 |
+
task_kwargs['metadata_json']["workspace_id"] = str(final_args[1])
|
| 175 |
+
# Pattern D: Deep extraction for nexus_stream_task (index 4)
|
| 176 |
+
elif task_name == "nexus_stream_task" and len(final_args) >= 5:
|
| 177 |
+
task_kwargs['metadata_json']["workspace_id"] = str(final_args[4])
|
| 178 |
+
# Pattern C: Fallback to entity_id if it looks like a UUID and we have no other lead
|
| 179 |
+
elif entity_id != "none" and task_name not in ["send_triple_notification"]:
|
| 180 |
+
# notification entity_id is user_id, don't use as workspace_id
|
| 181 |
+
task_kwargs['metadata_json']["workspace_id"] = str(entity_id)
|
| 182 |
|
| 183 |
# PRE-RECORD: Create the job entry in DB immediately so it's visible while queued
|
| 184 |
from agents.utils import get_deterministic_uuid, sanitize_for_db
|