Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
403ca47
1
Parent(s): 5d4d72b
backend stabilization
Browse files- alembic/versions/433d71e0ce5a_add_job_tracking_and_customization_to_.py +32 -0
- api/v1/nexus.py +106 -10
- frontend/packages/shared/src/components/NexusHub.tsx +197 -129
- frontend/packages/shared/src/contexts/NexusContext.tsx +19 -3
- models/workspace_story.py +3 -0
- scratch/fix_nexushub_braces_final.py +13 -0
- scratch/fix_nexushub_download.py +17 -0
- scratch/fix_nexushub_syntax.py +29 -0
- scratch/repair_nexushub_jsx.py +81 -0
- scratch/update_nexus_api.py +124 -0
- scratch/update_nexushub_ui.py +42 -0
- tasks/stories.py +9 -1
alembic/versions/433d71e0ce5a_add_job_tracking_and_customization_to_.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""add job tracking and customization to stories
|
| 2 |
+
|
| 3 |
+
Revision ID: 433d71e0ce5a
|
| 4 |
+
Revises: cf65189f5699
|
| 5 |
+
Create Date: 2026-05-02 00:12:02.977509
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from typing import Sequence, Union
|
| 9 |
+
|
| 10 |
+
from alembic import op
|
| 11 |
+
import sqlalchemy as sa
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# revision identifiers, used by Alembic.
|
| 15 |
+
revision: str = '433d71e0ce5a'
|
| 16 |
+
down_revision: Union[str, None] = 'cf65189f5699'
|
| 17 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 18 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def upgrade() -> None:
|
| 22 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 23 |
+
op.add_column('workspace_stories', sa.Column('arq_job_id', sa.String(), nullable=True))
|
| 24 |
+
op.add_column('workspace_stories', sa.Column('custom_instructions', sa.String(), nullable=True))
|
| 25 |
+
# ### end Alembic commands ###
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def downgrade() -> None:
|
| 29 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 30 |
+
op.drop_column('workspace_stories', 'custom_instructions')
|
| 31 |
+
op.drop_column('workspace_stories', 'arq_job_id')
|
| 32 |
+
# ### end Alembic commands ###
|
api/v1/nexus.py
CHANGED
|
@@ -832,7 +832,10 @@ async def list_workspace_stories(
|
|
| 832 |
"""
|
| 833 |
stmt = (
|
| 834 |
select(WorkspaceStory)
|
| 835 |
-
.where(
|
|
|
|
|
|
|
|
|
|
| 836 |
.order_by(WorkspaceStory.created_at.desc())
|
| 837 |
)
|
| 838 |
res = await db.execute(stmt)
|
|
@@ -842,15 +845,19 @@ async def list_workspace_stories(
|
|
| 842 |
"title": s.title,
|
| 843 |
"status": s.status,
|
| 844 |
"file_type": s.file_type,
|
| 845 |
-
"file_path": s.
|
| 846 |
"created_at": s.created_at,
|
| 847 |
"narrative_preview": (s.metadata_json or {}).get("narrative_preview", "")
|
| 848 |
} for s in res.scalars().all()
|
| 849 |
]
|
| 850 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 851 |
@router.post("/stories/generate/")
|
| 852 |
async def generate_workspace_story(
|
| 853 |
-
|
| 854 |
current_user: User = Depends(get_current_user),
|
| 855 |
db: AsyncSession = Depends(get_db),
|
| 856 |
arq_pool = Depends(get_arq_pool)
|
|
@@ -887,21 +894,110 @@ async def generate_workspace_story(
|
|
| 887 |
workspace_id=current_user.workspace_id,
|
| 888 |
user_id=current_user.id,
|
| 889 |
title=f"Workspace Story - {datetime.utcnow().strftime('%Y-%m-%d %H:%M')}",
|
| 890 |
-
file_type=file_type,
|
| 891 |
-
status=StoryStatus.PENDING
|
|
|
|
| 892 |
)
|
| 893 |
db.add(story)
|
| 894 |
await db.commit()
|
| 895 |
await db.refresh(story)
|
| 896 |
|
| 897 |
# 4. Enqueue background task (Explicitly route to HEAVY queue)
|
| 898 |
-
await arq_pool.enqueue_job(
|
| 899 |
-
"generate_workspace_story_task",
|
| 900 |
-
story_id=story.id,
|
| 901 |
-
user_id=current_user.id,
|
| 902 |
-
workspace_id=current_user.workspace_id,
|
| 903 |
role=str(current_user.role.value) if hasattr(current_user.role, 'value') else str(current_user.role),
|
| 904 |
_queue_name="arq:heavy"
|
| 905 |
)
|
|
|
|
|
|
|
|
|
|
| 906 |
|
| 907 |
return {"status": "success", "story_id": story.id}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 832 |
"""
|
| 833 |
stmt = (
|
| 834 |
select(WorkspaceStory)
|
| 835 |
+
.where(
|
| 836 |
+
WorkspaceStory.workspace_id == current_user.workspace_id,
|
| 837 |
+
WorkspaceStory.user_id == current_user.id
|
| 838 |
+
)
|
| 839 |
.order_by(WorkspaceStory.created_at.desc())
|
| 840 |
)
|
| 841 |
res = await db.execute(stmt)
|
|
|
|
| 845 |
"title": s.title,
|
| 846 |
"status": s.status,
|
| 847 |
"file_type": s.file_type,
|
| 848 |
+
"file_path": f"/api/v1/nexus/stories/{s.id}/download/", # Direct API Link
|
| 849 |
"created_at": s.created_at,
|
| 850 |
"narrative_preview": (s.metadata_json or {}).get("narrative_preview", "")
|
| 851 |
} for s in res.scalars().all()
|
| 852 |
]
|
| 853 |
|
| 854 |
+
class NexusStoryGenerateRequest(BaseModel):
|
| 855 |
+
file_type: str = "pdf" # "pdf" or "pptx"
|
| 856 |
+
custom_instructions: Optional[str] = None
|
| 857 |
+
|
| 858 |
@router.post("/stories/generate/")
|
| 859 |
async def generate_workspace_story(
|
| 860 |
+
req: NexusStoryGenerateRequest,
|
| 861 |
current_user: User = Depends(get_current_user),
|
| 862 |
db: AsyncSession = Depends(get_db),
|
| 863 |
arq_pool = Depends(get_arq_pool)
|
|
|
|
| 894 |
workspace_id=current_user.workspace_id,
|
| 895 |
user_id=current_user.id,
|
| 896 |
title=f"Workspace Story - {datetime.utcnow().strftime('%Y-%m-%d %H:%M')}",
|
| 897 |
+
file_type=req.file_type,
|
| 898 |
+
status=StoryStatus.PENDING,
|
| 899 |
+
custom_instructions=req.custom_instructions
|
| 900 |
)
|
| 901 |
db.add(story)
|
| 902 |
await db.commit()
|
| 903 |
await db.refresh(story)
|
| 904 |
|
| 905 |
# 4. Enqueue background task (Explicitly route to HEAVY queue)
|
| 906 |
+
job = await arq_pool.enqueue_job(
|
| 907 |
+
"generate_workspace_story_task",
|
| 908 |
+
story_id=story.id,
|
| 909 |
+
user_id=current_user.id,
|
| 910 |
+
workspace_id=current_user.workspace_id,
|
| 911 |
role=str(current_user.role.value) if hasattr(current_user.role, 'value') else str(current_user.role),
|
| 912 |
_queue_name="arq:heavy"
|
| 913 |
)
|
| 914 |
+
|
| 915 |
+
story.arq_job_id = job.job_id
|
| 916 |
+
await db.commit()
|
| 917 |
|
| 918 |
return {"status": "success", "story_id": story.id}
|
| 919 |
+
|
| 920 |
+
|
| 921 |
+
@router.delete("/stories/{story_id}/")
|
| 922 |
+
async def delete_workspace_story(
|
| 923 |
+
story_id: UUID,
|
| 924 |
+
db: AsyncSession = Depends(get_db),
|
| 925 |
+
current_user: User = Depends(get_current_user),
|
| 926 |
+
arq_pool = Depends(get_arq_pool)
|
| 927 |
+
) -> Any:
|
| 928 |
+
"""
|
| 929 |
+
Delete a story and attempt to cancel the background job if it's still running.
|
| 930 |
+
"""
|
| 931 |
+
stmt = select(WorkspaceStory).where(
|
| 932 |
+
WorkspaceStory.id == story_id,
|
| 933 |
+
WorkspaceStory.workspace_id == current_user.workspace_id
|
| 934 |
+
)
|
| 935 |
+
res = await db.execute(stmt)
|
| 936 |
+
story = res.scalar_one_or_none()
|
| 937 |
+
|
| 938 |
+
if not story:
|
| 939 |
+
raise HTTPException(status_code=404, detail="Story not found")
|
| 940 |
+
|
| 941 |
+
# Attempt to abort Arq job if not finished
|
| 942 |
+
if story.status in [StoryStatus.PENDING, StoryStatus.PROCESSING] and story.arq_job_id:
|
| 943 |
+
try:
|
| 944 |
+
from arq.jobs import Job
|
| 945 |
+
job = Job(story.arq_job_id, arq_pool, _queue_name="arq:heavy")
|
| 946 |
+
await job.abort()
|
| 947 |
+
print(f"Aborted Arq job {story.arq_job_id} for story {story_id}")
|
| 948 |
+
except Exception as e:
|
| 949 |
+
print(f"Failed to abort Arq job: {e}")
|
| 950 |
+
|
| 951 |
+
await db.delete(story)
|
| 952 |
+
await db.commit()
|
| 953 |
+
|
| 954 |
+
return {"status": "success", "message": "Story deleted and task cancelled if active."}
|
| 955 |
+
|
| 956 |
+
|
| 957 |
+
@router.get("/stories/{story_id}/download/")
|
| 958 |
+
async def download_workspace_story(
|
| 959 |
+
story_id: UUID,
|
| 960 |
+
db: AsyncSession = Depends(get_db),
|
| 961 |
+
current_user: User = Depends(get_current_user_flexible)
|
| 962 |
+
) -> Any:
|
| 963 |
+
"""
|
| 964 |
+
Download the generated narrative file.
|
| 965 |
+
Supports Header and Query Param tokens for direct browser downloads.
|
| 966 |
+
"""
|
| 967 |
+
from fastapi.responses import FileResponse, RedirectResponse
|
| 968 |
+
from core.storage import get_storage_provider
|
| 969 |
+
import os
|
| 970 |
+
|
| 971 |
+
stmt = select(WorkspaceStory).where(
|
| 972 |
+
WorkspaceStory.id == story_id,
|
| 973 |
+
WorkspaceStory.workspace_id == current_user.workspace_id
|
| 974 |
+
)
|
| 975 |
+
res = await db.execute(stmt)
|
| 976 |
+
story = res.scalar_one_or_none()
|
| 977 |
+
|
| 978 |
+
if not story:
|
| 979 |
+
raise HTTPException(status_code=404, detail="Story not found")
|
| 980 |
+
|
| 981 |
+
if story.status != StoryStatus.COMPLETED:
|
| 982 |
+
raise HTTPException(status_code=400, detail="Story is not ready for download yet.")
|
| 983 |
+
|
| 984 |
+
storage = get_storage_provider()
|
| 985 |
+
|
| 986 |
+
# If S3, redirect to presigned URL
|
| 987 |
+
if hasattr(storage, 'bucket') and storage.bucket: # Simple check for S3 backend
|
| 988 |
+
url = await storage.get_url(story.file_path)
|
| 989 |
+
return RedirectResponse(url=url)
|
| 990 |
+
|
| 991 |
+
# Local Storage handling
|
| 992 |
+
local_path = storage.get_local_path(story.file_path)
|
| 993 |
+
if not os.path.exists(local_path):
|
| 994 |
+
raise HTTPException(status_code=404, detail="Physical story file missing on server.")
|
| 995 |
+
|
| 996 |
+
# Determine media type
|
| 997 |
+
media_type = "application/pdf" if story.file_type == "pdf" else "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
| 998 |
+
|
| 999 |
+
return FileResponse(
|
| 1000 |
+
path=local_path,
|
| 1001 |
+
filename=f"{story.title.replace(' ', '_')}.{story.file_type}",
|
| 1002 |
+
media_type=media_type
|
| 1003 |
+
)
|
frontend/packages/shared/src/components/NexusHub.tsx
CHANGED
|
@@ -20,7 +20,9 @@ import {
|
|
| 20 |
Trash2,
|
| 21 |
BookOpen,
|
| 22 |
FileText,
|
| 23 |
-
Presentation
|
|
|
|
|
|
|
| 24 |
} from 'lucide-react';
|
| 25 |
import { useNotification } from '@nexus/shared';
|
| 26 |
|
|
@@ -82,10 +84,12 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 82 |
stories,
|
| 83 |
fetchStories,
|
| 84 |
generateStory,
|
|
|
|
| 85 |
isGeneratingStory
|
| 86 |
} = useNexus();
|
| 87 |
|
| 88 |
const { user } = useAuth();
|
|
|
|
| 89 |
const isExternal = user?.role === 'customer_admin' || user?.role === 'customer_user';
|
| 90 |
|
| 91 |
const canGenerateStory = user?.role === 'customer_admin' ||
|
|
@@ -239,7 +243,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 239 |
fontFamily: 'Inter, system-ui, sans-serif',
|
| 240 |
overflow: 'hidden',
|
| 241 |
position: 'relative'
|
| 242 |
-
}
|
| 243 |
<style>{`
|
| 244 |
@keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
|
| 245 |
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
@@ -286,11 +290,11 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 286 |
overflow: 'hidden',
|
| 287 |
position: 'relative',
|
| 288 |
boxShadow: showSessions ? '20px 0 50px rgba(0,0,0,0.05)' : 'none'
|
| 289 |
-
}
|
| 290 |
{internalMode === "chat" && (
|
| 291 |
-
<div style={{ padding: '32px 24px 16px 24px', minWidth: 320 }
|
| 292 |
<button
|
| 293 |
-
onClick={() => { setThreadId(null); setInputText(""); setShowSessions(false); }
|
| 294 |
style={{
|
| 295 |
width: '100%',
|
| 296 |
padding: '14px',
|
|
@@ -308,7 +312,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 308 |
boxShadow: '0 8px 24px rgba(124, 58, 237, 0.2)',
|
| 309 |
textTransform: 'uppercase',
|
| 310 |
letterSpacing: '0.05em'
|
| 311 |
-
}
|
| 312 |
>
|
| 313 |
<MessageSquare size={18} /> New Session
|
| 314 |
</button>
|
|
@@ -316,7 +320,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 316 |
)}
|
| 317 |
|
| 318 |
{internalMode === "library" && (
|
| 319 |
-
<div style={{ padding: '32px 24px 16px 24px', minWidth: 320 }
|
| 320 |
<button
|
| 321 |
onClick={() => setIsAddingQuery(true)}
|
| 322 |
style={{
|
|
@@ -336,7 +340,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 336 |
boxShadow: '0 8px 24px rgba(124, 58, 237, 0.2)',
|
| 337 |
textTransform: 'uppercase',
|
| 338 |
letterSpacing: '0.05em'
|
| 339 |
-
}
|
| 340 |
>
|
| 341 |
<Zap size={18} /> Add Command
|
| 342 |
</button>
|
|
@@ -344,16 +348,53 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 344 |
)}
|
| 345 |
|
| 346 |
{internalMode === "stories" && (
|
| 347 |
-
<div style={{ padding: '32px 24px 16px 24px', minWidth: 320, display: 'flex', flexDirection: 'column', gap: 12 }
|
| 348 |
{!canGenerateStory ? (
|
| 349 |
-
<div style={{ padding: '16px', borderRadius: 12, background: `${COLORS.brand}05`, border: `1px solid ${COLORS.brand}15`, textAlign: 'center' }
|
| 350 |
-
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.brand, marginBottom: 4 }
|
| 351 |
-
<div style={{ fontSize: 11, color: COLORS.gray500, lineHeight: 1.4 }
|
| 352 |
</div>
|
| 353 |
) : (
|
| 354 |
-
<div style={{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
<button
|
| 356 |
-
onClick={() =>
|
|
|
|
|
|
|
|
|
|
| 357 |
disabled={isGeneratingStory}
|
| 358 |
style={{
|
| 359 |
flex: 1,
|
|
@@ -372,13 +413,16 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 372 |
boxShadow: isGeneratingStory ? 'none' : '0 8px 24px rgba(124, 58, 237, 0.2)',
|
| 373 |
textTransform: 'uppercase',
|
| 374 |
transition: 'all 0.2s'
|
| 375 |
-
}
|
| 376 |
>
|
| 377 |
{isGeneratingStory ? <div className="spinner-mini" /> : <FileText size={16} />}
|
| 378 |
{isGeneratingStory ? 'QUEUING...' : 'PDF Story'}
|
| 379 |
</button>
|
| 380 |
<button
|
| 381 |
-
onClick={() =>
|
|
|
|
|
|
|
|
|
|
| 382 |
disabled={isGeneratingStory}
|
| 383 |
style={{
|
| 384 |
flex: 1,
|
|
@@ -397,7 +441,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 397 |
textTransform: 'uppercase',
|
| 398 |
opacity: isGeneratingStory ? 0.5 : 1,
|
| 399 |
transition: 'all 0.2s'
|
| 400 |
-
}
|
| 401 |
>
|
| 402 |
<Presentation size={16} /> PPT Story
|
| 403 |
</button>
|
|
@@ -410,12 +454,12 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 410 |
ref={sessionListRef}
|
| 411 |
|
| 412 |
onScroll={handleSessionScroll}
|
| 413 |
-
style={{ flex: 1, overflowY: 'auto', padding: '16px 8px', minWidth: 320 }
|
| 414 |
>
|
| 415 |
{internalMode === "library" && (
|
| 416 |
|
| 417 |
<>
|
| 418 |
-
<div style={{ padding: '8px 16px', fontSize: 11, fontWeight: 800, color: COLORS.gray400, textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 8, marginTop: 16 }
|
| 419 |
|
| 420 |
{isAddingQuery && (
|
| 421 |
<div style={{
|
|
@@ -425,26 +469,26 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 425 |
borderRadius: 16,
|
| 426 |
border: `1.5px solid ${COLORS.brand}40`,
|
| 427 |
animation: 'fadeIn 0.3s ease'
|
| 428 |
-
}
|
| 429 |
<form onSubmit={handleSaveNewQuery}>
|
| 430 |
<input
|
| 431 |
autoFocus
|
| 432 |
placeholder="Command Title..."
|
| 433 |
value={newQueryTitle}
|
| 434 |
onChange={e => setNewQueryTitle(e.target.value)}
|
| 435 |
-
style={{ width: '100%', padding: '8px 0', border: 'none', borderBottom: `1px solid ${COLORS.gray100}`, background: 'none', color: COLORS.gray900, fontSize: 13, fontWeight: 700, outline: 'none', marginBottom: 12 }
|
| 436 |
/>
|
| 437 |
<textarea
|
| 438 |
placeholder="Enter the full command text..."
|
| 439 |
value={newQueryText}
|
| 440 |
onChange={e => setNewQueryText(e.target.value)}
|
| 441 |
-
style={{ width: '100%', padding: '8px 0', border: 'none', background: 'none', color: COLORS.gray600, fontSize: 12, fontWeight: 500, outline: 'none', minHeight: 60, resize: 'none', marginBottom: 12 }
|
| 442 |
/>
|
| 443 |
-
<div style={{ display: 'flex', gap: 8 }
|
| 444 |
<button
|
| 445 |
type="submit"
|
| 446 |
disabled={!newQueryTitle.trim() || !newQueryText.trim()}
|
| 447 |
-
style={{ flex: 1, padding: '8px', borderRadius: 10, background: COLORS.brand, color: 'white', border: 'none', fontSize: 11, fontWeight: 800, cursor: 'pointer', opacity: (!newQueryTitle.trim() || !newQueryText.trim()) ? 0.4 : 1 }
|
| 448 |
className="btn-primary"
|
| 449 |
>
|
| 450 |
SAVE
|
|
@@ -452,7 +496,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 452 |
<button
|
| 453 |
type="button"
|
| 454 |
onClick={() => setIsAddingQuery(false)}
|
| 455 |
-
style={{ padding: '8px 12px', borderRadius: 10, background: 'none', border: `1px solid ${COLORS.gray200}`, color: COLORS.gray500, fontSize: 11, fontWeight: 800, cursor: 'pointer' }
|
| 456 |
className="btn-secondary"
|
| 457 |
>
|
| 458 |
CANCEL
|
|
@@ -474,26 +518,26 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 474 |
borderRadius: 16,
|
| 475 |
border: `1.5px solid ${COLORS.brand}40`,
|
| 476 |
animation: 'fadeIn 0.3s ease'
|
| 477 |
-
}
|
| 478 |
<form onSubmit={handleUpdateQuery}>
|
| 479 |
<input
|
| 480 |
autoFocus
|
| 481 |
placeholder="Command Title..."
|
| 482 |
value={editQueryTitle}
|
| 483 |
onChange={e => setEditQueryTitle(e.target.value)}
|
| 484 |
-
style={{ width: '100%', padding: '8px 0', border: 'none', borderBottom: `1px solid ${COLORS.gray100}`, background: 'none', color: COLORS.gray900, fontSize: 13, fontWeight: 700, outline: 'none', marginBottom: 12 }
|
| 485 |
/>
|
| 486 |
<textarea
|
| 487 |
placeholder="Enter the full command text..."
|
| 488 |
value={editQueryText}
|
| 489 |
onChange={e => setEditQueryText(e.target.value)}
|
| 490 |
-
style={{ width: '100%', padding: '8px 0', border: 'none', background: 'none', color: COLORS.gray600, fontSize: 12, fontWeight: 500, outline: 'none', minHeight: 60, resize: 'none', marginBottom: 12 }
|
| 491 |
/>
|
| 492 |
-
<div style={{ display: 'flex', gap: 8 }
|
| 493 |
<button
|
| 494 |
type="submit"
|
| 495 |
disabled={!editQueryTitle.trim() || !editQueryText.trim()}
|
| 496 |
-
style={{ flex: 1, padding: '8px', borderRadius: 10, background: COLORS.brand, color: 'white', border: 'none', fontSize: 11, fontWeight: 800, cursor: 'pointer', opacity: (!editQueryTitle.trim() || !editQueryText.trim()) ? 0.4 : 1 }
|
| 497 |
className="btn-primary"
|
| 498 |
>
|
| 499 |
UPDATE
|
|
@@ -501,7 +545,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 501 |
<button
|
| 502 |
type="button"
|
| 503 |
onClick={() => setEditingQueryId(null)}
|
| 504 |
-
style={{ padding: '8px 12px', borderRadius: 10, background: 'none', border: `1px solid ${COLORS.gray200}`, color: COLORS.gray500, fontSize: 11, fontWeight: 800, cursor: 'pointer' }
|
| 505 |
className="btn-secondary"
|
| 506 |
>
|
| 507 |
CANCEL
|
|
@@ -519,7 +563,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 519 |
query(q.query_text);
|
| 520 |
setInternalMode("chat");
|
| 521 |
setShowSessions(false);
|
| 522 |
-
}
|
| 523 |
style={{
|
| 524 |
padding: '12px 16px',
|
| 525 |
borderRadius: 12,
|
|
@@ -531,19 +575,19 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 531 |
transition: 'all 0.2s',
|
| 532 |
background: 'transparent',
|
| 533 |
border: '1px solid transparent'
|
| 534 |
-
}
|
| 535 |
-
onMouseEnter={e => { e.currentTarget.style.background = `${COLORS.brand}08`; e.currentTarget.style.borderColor = `${COLORS.brand}20` }
|
| 536 |
-
onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.borderColor = 'transparent' }
|
| 537 |
>
|
| 538 |
<div style={{
|
| 539 |
width: 28, height: 28, borderRadius: 8, background: q.is_system ? `${COLORS.brand}15` : COLORS.gray50,
|
| 540 |
display: 'flex', alignItems: 'center', justifyContent: 'center', color: q.is_system ? COLORS.brand : COLORS.gray400
|
| 541 |
-
}
|
| 542 |
<Icon size={14} />
|
| 543 |
</div>
|
| 544 |
-
<div style={{ flex: 1, minWidth: 0 }
|
| 545 |
-
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray700, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }
|
| 546 |
-
{q.is_system && <div style={{ fontSize: 9, fontWeight: 800, color: COLORS.brand, opacity: 0.7, textTransform: 'uppercase' }
|
| 547 |
</div>
|
| 548 |
|
| 549 |
{!q.is_system && (
|
|
@@ -554,14 +598,14 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 554 |
setEditingQueryId(q.id);
|
| 555 |
setEditQueryTitle(q.title);
|
| 556 |
setEditQueryText(q.query_text);
|
| 557 |
-
}
|
| 558 |
-
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: COLORS.gray300 }
|
| 559 |
>
|
| 560 |
<Edit3 size={14} />
|
| 561 |
</button>
|
| 562 |
<button
|
| 563 |
onClick={(e) => handleDeleteQuery(e, q.id)}
|
| 564 |
-
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: COLORS.gray300 }
|
| 565 |
>
|
| 566 |
<Trash2 size={14} />
|
| 567 |
</button>
|
|
@@ -577,7 +621,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 577 |
{internalMode === "chat" && (
|
| 578 |
|
| 579 |
<>
|
| 580 |
-
<div style={{ padding: '24px 16px 8px 16px', fontSize: 11, fontWeight: 800, color: COLORS.gray400, textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 8 }
|
| 581 |
|
| 582 |
{sessions.map((s: NexusThread) => (
|
| 583 |
<div
|
|
@@ -596,12 +640,12 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 596 |
transition: 'all 0.2s',
|
| 597 |
position: 'relative',
|
| 598 |
border: threadId === s.id ? `1px solid ${COLORS.brand}30` : '1px solid transparent'
|
| 599 |
-
}
|
| 600 |
-
onMouseEnter={e => { if (threadId !== s.id) e.currentTarget.style.background = COLORS.gray50 }
|
| 601 |
-
onMouseLeave={e => { if (threadId !== s.id) e.currentTarget.style.background = 'transparent' }
|
| 602 |
>
|
| 603 |
-
<div style={{ flex: 1, minWidth: 0, display: 'flex', alignItems: 'center', gap: 10 }
|
| 604 |
-
<span style={{ opacity: threadId === s.id ? 1 : 0.5 }
|
| 605 |
{threadId === s.id ? <Zap size={16} color={COLORS.brand} /> : <MessageSquare size={16} />}
|
| 606 |
</span>
|
| 607 |
{editingThread === s.id ? (
|
|
@@ -621,19 +665,19 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 621 |
outline: `2px solid var(--primary)`,
|
| 622 |
borderRadius: 4,
|
| 623 |
padding: '2px 4px'
|
| 624 |
-
}
|
| 625 |
/>
|
| 626 |
) : (
|
| 627 |
-
<div style={{ flex: 1, minWidth: 0 }
|
| 628 |
-
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray900, marginBottom: 2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }
|
| 629 |
-
<div style={{ fontSize: 10, color: COLORS.gray400, fontWeight: 600 }
|
| 630 |
</div>
|
| 631 |
)}
|
| 632 |
</div>
|
| 633 |
-
<div style={{ display: 'flex', gap: 4, marginLeft: 8 }
|
| 634 |
<button
|
| 635 |
-
onClick={(e) => { e.stopPropagation(); toggleBookmark(s.id, !s.is_bookmarked); }
|
| 636 |
-
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: s.is_bookmarked ? COLORS.brand : COLORS.gray300 }
|
| 637 |
title={s.is_bookmarked ? "Unbookmark" : "Bookmark"}
|
| 638 |
>
|
| 639 |
<Bookmark size={14} fill={s.is_bookmarked ? COLORS.brand : 'none'} />
|
|
@@ -641,13 +685,13 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 641 |
<button
|
| 642 |
onClick={(e) => startRename(e, s)}
|
| 643 |
className="rename-btn"
|
| 644 |
-
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: COLORS.gray300, opacity: 0, transition: 'opacity 0.2s' }
|
| 645 |
>
|
| 646 |
<Edit3 size={14} />
|
| 647 |
</button>
|
| 648 |
<button
|
| 649 |
onClick={(e) => handleDeleteThread(e, s.id)}
|
| 650 |
-
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: COLORS.gray300 }
|
| 651 |
>
|
| 652 |
<Trash2 size={14} />
|
| 653 |
</button>
|
|
@@ -656,19 +700,19 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 656 |
))}
|
| 657 |
|
| 658 |
{paginationLoading && (
|
| 659 |
-
<div style={{ padding: '20px', textAlign: 'center', animation: 'pulse-soft 2s infinite' }
|
| 660 |
-
<div style={{ width: 6, height: 6, borderRadius: '50%', background: COLORS.brand, margin: '0 auto' }
|
| 661 |
</div>
|
| 662 |
)}
|
| 663 |
|
| 664 |
{!paginationLoading && !hasMore && sessions.length > 0 && (
|
| 665 |
-
<div style={{ padding: '24px 16px', textAlign: 'center', opacity: 0.3, fontSize: 10, fontWeight: 800, textTransform: 'uppercase', letterSpacing: '0.1em' }
|
| 666 |
End of history
|
| 667 |
</div>
|
| 668 |
)}
|
| 669 |
|
| 670 |
{sessions.length === 0 && (
|
| 671 |
-
<div style={{ padding: '20px', textAlign: 'center', color: COLORS.gray400, fontSize: 13 }
|
| 672 |
No previous signals.
|
| 673 |
</div>
|
| 674 |
)}
|
|
@@ -676,53 +720,77 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 676 |
)}
|
| 677 |
|
| 678 |
{internalMode === "library" && (
|
| 679 |
-
<div style={{ padding: '24px 16px', textAlign: 'center', color: COLORS.gray400, fontSize: 12, lineHeight: 1.5 }
|
| 680 |
-
<BookOpen size={24} style={{ marginBottom: 12, opacity: 0.5 }
|
| 681 |
<div>Select a tactical operation from the library above to initialize a command session.</div>
|
| 682 |
</div>
|
| 683 |
)}
|
| 684 |
|
| 685 |
{internalMode === "stories" && (
|
| 686 |
-
<div style={{ padding: '16px', minWidth: 320 }
|
| 687 |
{error && internalMode === "stories" && (
|
| 688 |
<div style={{
|
| 689 |
padding: '12px 16px', borderRadius: 12, background: '#F43F5E10',
|
| 690 |
border: '1px solid #F43F5E20', marginBottom: 16,
|
| 691 |
display: 'flex', alignItems: 'center', gap: 10,
|
| 692 |
animation: 'shake 0.4s cubic-bezier(.36,.07,.19,.97) both'
|
| 693 |
-
}
|
| 694 |
-
<div style={{ color: '#F43F5E' }
|
| 695 |
-
<div style={{ fontSize: 11, fontWeight: 600, color: '#F43F5E' }
|
| 696 |
</div>
|
| 697 |
)}
|
| 698 |
|
| 699 |
-
<div style={{ fontSize: 11, fontWeight: 800, color: COLORS.gray400, textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 16, paddingLeft: 8 }
|
| 700 |
{stories.map(s => (
|
| 701 |
<div key={s.id} style={{
|
| 702 |
padding: '16px', borderRadius: 16, background: 'var(--bg-dark)',
|
| 703 |
border: '1px solid var(--border-subtle)', marginBottom: 12,
|
| 704 |
display: 'flex', flexDirection: 'column', gap: 10
|
| 705 |
-
}
|
| 706 |
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
|
| 707 |
-
<div style={{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 708 |
<div style={{
|
| 709 |
fontSize: 9, fontWeight: 800, padding: '2px 6px', borderRadius: 6,
|
| 710 |
background: s.status === 'completed' ? '#10B98120' : s.status === 'processing' ? '#7C3AED20' : '#F43F5E20',
|
| 711 |
color: s.status === 'completed' ? '#10B981' : s.status === 'processing' ? '#7C3AED' : '#F43F5E',
|
| 712 |
textTransform: 'uppercase'
|
| 713 |
-
}
|
| 714 |
{s.status}
|
| 715 |
</div>
|
| 716 |
</div>
|
| 717 |
{s.narrative_preview && (
|
| 718 |
-
<div style={{ fontSize: 11, color: COLORS.gray400, fontStyle: 'italic', lineClamp: 2, display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical' as any, overflow: 'hidden' }
|
| 719 |
"{s.narrative_preview}..."
|
| 720 |
</div>
|
| 721 |
)}
|
| 722 |
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 4 }}>
|
| 723 |
-
<div style={{ fontSize: 10, color: COLORS.gray300 }
|
| 724 |
{s.status === 'completed' && (
|
| 725 |
-
<a href={s.file_path} target="_blank" rel="noreferrer" style={{ fontSize: 11, fontWeight: 700, color: COLORS.brand, textDecoration: 'none', display: 'flex', alignItems: 'center', gap: 4 }}>
|
| 726 |
DOWNLOAD {s.file_type.toUpperCase()} <ArrowUpRight size={12} />
|
| 727 |
</a>
|
| 728 |
)}
|
|
@@ -730,9 +798,9 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 730 |
</div>
|
| 731 |
))}
|
| 732 |
{stories.length === 0 && (
|
| 733 |
-
<div style={{ padding: '40px 20px', textAlign: 'center', color: COLORS.gray400 }
|
| 734 |
-
<Presentation size={32} style={{ marginBottom: 16, opacity: 0.2, marginInline: 'auto' }
|
| 735 |
-
<div style={{ fontSize: 13, fontWeight: 600 }
|
| 736 |
<div style={{ fontSize: 11, marginTop: 4 }}>Initialize a new story above to build a cohesive workspace narrative.</div>
|
| 737 |
</div>
|
| 738 |
)}
|
|
@@ -742,15 +810,15 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 742 |
</div>
|
| 743 |
|
| 744 |
{internalMode === "chat" && (
|
| 745 |
-
<div style={{ padding: '16px', borderTop: `1px solid ${COLORS.gray100}`, minWidth: 320 }
|
| 746 |
-
<div style={{ fontSize: 10, color: COLORS.gray400, textAlign: 'center', fontWeight: 700 }
|
| 747 |
</div>
|
| 748 |
)}
|
| 749 |
|
| 750 |
</div>
|
| 751 |
|
| 752 |
{/* Main Chat Area */}
|
| 753 |
-
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', background: 'var(--bg-dark)', position: 'relative' }
|
| 754 |
{/* Fixed Left Tool Rail */}
|
| 755 |
<div style={{
|
| 756 |
position: 'absolute',
|
|
@@ -768,7 +836,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 768 |
gap: 16,
|
| 769 |
zIndex: 45,
|
| 770 |
boxShadow: '4px 0 24px rgba(0,0,0,0.02)'
|
| 771 |
-
}
|
| 772 |
{/* Main Sidebar Toggle (Workspace Icon) */}
|
| 773 |
<button
|
| 774 |
onClick={() => {
|
|
@@ -778,7 +846,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 778 |
setInternalMode("chat");
|
| 779 |
setShowSessions(true);
|
| 780 |
}
|
| 781 |
-
}
|
| 782 |
style={{
|
| 783 |
width: 52,
|
| 784 |
height: 52,
|
|
@@ -793,7 +861,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 793 |
fontSize: 22,
|
| 794 |
color: (internalMode === "chat" && showSessions) ? 'white' : COLORS.gray600,
|
| 795 |
transition: 'all 0.4s cubic-bezier(0.19, 1, 0.22, 1)',
|
| 796 |
-
}
|
| 797 |
title="Signals"
|
| 798 |
>
|
| 799 |
|
|
@@ -808,7 +876,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 808 |
setInternalMode("library");
|
| 809 |
setShowSessions(true);
|
| 810 |
}
|
| 811 |
-
}
|
| 812 |
style={{
|
| 813 |
width: 52,
|
| 814 |
height: 52,
|
|
@@ -823,7 +891,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 823 |
fontSize: 22,
|
| 824 |
color: (internalMode === "library" && showSessions) ? 'white' : COLORS.gray600,
|
| 825 |
transition: 'all 0.4s cubic-bezier(0.19, 1, 0.22, 1)',
|
| 826 |
-
}
|
| 827 |
title="Library"
|
| 828 |
>
|
| 829 |
|
|
@@ -838,7 +906,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 838 |
setInternalMode("stories");
|
| 839 |
setShowSessions(true);
|
| 840 |
}
|
| 841 |
-
}
|
| 842 |
style={{
|
| 843 |
width: 52,
|
| 844 |
height: 52,
|
|
@@ -853,14 +921,14 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 853 |
fontSize: 22,
|
| 854 |
color: (internalMode === "stories" && showSessions) ? 'white' : COLORS.gray600,
|
| 855 |
transition: 'all 0.4s cubic-bezier(0.19, 1, 0.22, 1)',
|
| 856 |
-
}
|
| 857 |
title="Workspace Stories"
|
| 858 |
>
|
| 859 |
<Presentation size={24} />
|
| 860 |
</button>
|
| 861 |
|
| 862 |
|
| 863 |
-
<div style={{ width: 32, height: 1, background: COLORS.gray100, margin: '8px 0', opacity: 0.5 }
|
| 864 |
</div>
|
| 865 |
|
| 866 |
{/* Messages List */}
|
|
@@ -875,9 +943,9 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 875 |
justifyContent: messages.length === 0 && !loading && !historyLoading ? 'center' : 'flex-start',
|
| 876 |
gap: 32,
|
| 877 |
animation: 'fadeIn 0.6s ease'
|
| 878 |
-
}
|
| 879 |
>
|
| 880 |
-
<div style={{ maxWidth: 840, width: '100%', margin: '0 auto', display: 'flex', flexDirection: 'column', gap: 32, padding: '0 40px' }
|
| 881 |
|
| 882 |
{/* Background Sync Indicator */}
|
| 883 |
{historyLoading && (
|
|
@@ -896,45 +964,45 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 896 |
gap: 10,
|
| 897 |
zIndex: 100,
|
| 898 |
animation: 'fadeIn 0.5s ease'
|
| 899 |
-
}
|
| 900 |
-
<div style={{ width: 6, height: 6, borderRadius: '50%', background: COLORS.brand, animation: 'pulse-soft 1.5s infinite' }
|
| 901 |
-
<span style={{ fontSize: 11, fontWeight: 800, color: COLORS.gray500, textTransform: 'uppercase', letterSpacing: '0.05em' }
|
| 902 |
</div>
|
| 903 |
)}
|
| 904 |
|
| 905 |
{messages.length === 0 && !loading && (
|
| 906 |
-
<div style={{ textAlign: 'center', maxWidth: 640, alignSelf: 'center', paddingBottom: '32px' }
|
| 907 |
-
<div style={{ position: 'relative', width: 96, height: 96, margin: '0 auto 32px' }
|
| 908 |
<div style={{
|
| 909 |
width: 96, height: 96, borderRadius: '50%',
|
| 910 |
background: COLORS.brandGradient,
|
| 911 |
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
| 912 |
fontSize: 32, color: 'white', fontWeight: 900, position: 'relative', zIndex: 2,
|
| 913 |
boxShadow: '0 12px 40px rgba(124, 58, 237, 0.3)'
|
| 914 |
-
}
|
| 915 |
<div style={{
|
| 916 |
position: 'absolute', top: 4, right: 4, width: 24, height: 24,
|
| 917 |
borderRadius: '50%', background: '#10B981', border: '5px solid var(--bg-card)',
|
| 918 |
zIndex: 3, boxShadow: '0 4px 8px rgba(0,0,0,0.1)'
|
| 919 |
-
}
|
| 920 |
<div style={{
|
| 921 |
position: 'absolute', inset: -15, borderRadius: '50%',
|
| 922 |
background: COLORS.brandGradient, opacity: 0.1,
|
| 923 |
animation: 'nexus-pulse 3s infinite'
|
| 924 |
-
}
|
| 925 |
</div>
|
| 926 |
|
| 927 |
-
<h2 style={{ fontSize: 28, fontWeight: 900, color: COLORS.gray900, marginBottom: 12, letterSpacing: '-0.02em' }
|
| 928 |
{internalMode === "library" ? "Command Library" : "How can Nexus help today?"}
|
| 929 |
</h2>
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
-
<p style={{ fontSize: 16, color: COLORS.gray500, marginBottom: 48, fontWeight: 500 }
|
| 934 |
Secure workspace orchestration, technical support, and deep diagnostics.
|
| 935 |
</p>
|
| 936 |
|
| 937 |
-
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, justifyContent: 'center', maxWidth: 800, margin: '0 auto' }
|
| 938 |
{(savedQueries.length > 0 ? savedQueries.slice(0, 4) : (
|
| 939 |
isExternal ? [
|
| 940 |
{ title: "Ticket Summary", icon: "Zap", query_text: "Give me a summary of my active tickets" },
|
|
@@ -957,12 +1025,12 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 957 |
style={{
|
| 958 |
padding: '10px 18px', borderRadius: 12, border: `1.5px solid var(--border-subtle)`, background: 'var(--bg-card)',
|
| 959 |
display: 'flex', alignItems: 'center', gap: 10, cursor: 'pointer', transition: 'all 0.2s cubic-bezier(0.19, 1, 0.22, 1)',
|
| 960 |
-
}
|
| 961 |
-
onMouseEnter={e => { e.currentTarget.style.borderColor = COLORS.brand; e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 8px 20px rgba(0,0,0,0.06)'; }
|
| 962 |
-
onMouseLeave={e => { e.currentTarget.style.borderColor = COLORS.gray200; e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = 'none'; }
|
| 963 |
>
|
| 964 |
-
<span style={{ color: COLORS.brand }
|
| 965 |
-
<span style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray700 }
|
| 966 |
</button>
|
| 967 |
);
|
| 968 |
})}
|
|
@@ -975,45 +1043,45 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 975 |
<div key={i} style={{
|
| 976 |
display: 'flex', flexDirection: 'column', alignSelf: m.role === 'user' ? 'flex-end' : 'flex-start',
|
| 977 |
maxWidth: '90%', gap: 8, animation: 'slideIn 0.3s ease-out'
|
| 978 |
-
}
|
| 979 |
<div style={{
|
| 980 |
fontSize: 10, fontWeight: 800, color: COLORS.gray400, display: 'flex', gap: 8,
|
| 981 |
flexDirection: m.role === 'user' ? 'row-reverse' : 'row', padding: '0 8px', textTransform: 'uppercase'
|
| 982 |
-
}
|
| 983 |
-
<span style={{ color: m.role === 'user' ? COLORS.brand : COLORS.gray500 }
|
| 984 |
-
<span style={{ opacity: 0.4 }
|
| 985 |
<span>{formatTimestamp(m.timestamp)}</span>
|
| 986 |
{m.role === 'user' && (
|
| 987 |
<button
|
| 988 |
onClick={() => {
|
| 989 |
const title = window.prompt("Save this query to your library as:", m.content.slice(0, 30) + "...");
|
| 990 |
if (title) saveQuery(title, m.content);
|
| 991 |
-
}
|
| 992 |
style={{
|
| 993 |
marginLeft: 'auto', background: 'none', border: 'none',
|
| 994 |
color: COLORS.gray400, cursor: 'pointer', padding: 0,
|
| 995 |
display: 'flex', alignItems: 'center', gap: 4
|
| 996 |
-
}
|
| 997 |
>
|
| 998 |
-
<Bookmark size={10} /> <span style={{ fontSize: 9 }
|
| 999 |
</button>
|
| 1000 |
)}
|
| 1001 |
</div>
|
| 1002 |
|
| 1003 |
|
| 1004 |
-
<div style={{ display: 'flex', gap: 16, flexDirection: m.role === 'user' ? 'row-reverse' : 'row', alignItems: 'flex-start' }
|
| 1005 |
<div style={{
|
| 1006 |
width: 36, height: 36, borderRadius: 10, background: m.role === 'user' ? COLORS.gray100 : COLORS.brandGradient,
|
| 1007 |
display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 13, fontWeight: 900,
|
| 1008 |
color: m.role === 'user' ? COLORS.brand : '#fff', flexShrink: 0, marginTop: 4
|
| 1009 |
-
}
|
| 1010 |
{m.role === 'user' ? 'U' : 'NX'}
|
| 1011 |
</div>
|
| 1012 |
<div style={{
|
| 1013 |
padding: '16px 20px', borderRadius: 20, background: m.role === 'user' ? 'var(--primary)' : 'var(--bg-card)',
|
| 1014 |
color: m.role === 'user' ? 'white' : 'var(--text-main)', fontSize: 15, lineHeight: 1.6, fontWeight: 500,
|
| 1015 |
border: m.role === 'assistant' ? `1px solid var(--border-subtle)` : 'none'
|
| 1016 |
-
}
|
| 1017 |
{m.role === 'assistant' && m.content.includes("[ACTION_REQUIRED]") ? (
|
| 1018 |
(() => {
|
| 1019 |
try {
|
|
@@ -1039,17 +1107,17 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 1039 |
))}
|
| 1040 |
|
| 1041 |
{(loading || statusMessage) && (
|
| 1042 |
-
<div style={{ display: 'flex', gap: 16, alignSelf: 'flex-start', alignItems: 'center' }
|
| 1043 |
<div style={{
|
| 1044 |
width: 36, height: 36, borderRadius: 10, background: 'var(--primary-gradient)',
|
| 1045 |
display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0,
|
| 1046 |
animation: 'pulse-soft 2s infinite'
|
| 1047 |
-
}
|
| 1048 |
-
<span style={{ color: 'white', fontSize: 13, fontWeight: 900 }
|
| 1049 |
</div>
|
| 1050 |
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
| 1051 |
-
<div style={{ fontSize: 12, fontWeight: 700, color: 'var(--primary)', display: 'flex', alignItems: 'center', gap: 8 }
|
| 1052 |
-
<div style={{ width: 6, height: 6, borderRadius: '50%', background: 'var(--primary)', opacity: 0.8, animation: 'pulse-soft 1s infinite' }
|
| 1053 |
{statusMessage || "Nexus is thinking..."}
|
| 1054 |
</div>
|
| 1055 |
</div>
|
|
@@ -1059,17 +1127,17 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 1059 |
</div>
|
| 1060 |
|
| 1061 |
{/* Input Area */}
|
| 1062 |
-
<div style={{ padding: '0 40px 32px 112px', background: 'linear-gradient(to top, var(--bg-dark) 80%, transparent)' }
|
| 1063 |
-
<div style={{ maxWidth: 840, margin: '0 auto' }
|
| 1064 |
<form
|
| 1065 |
onSubmit={handleSubmit}
|
| 1066 |
style={{
|
| 1067 |
display: 'flex', gap: 16, background: 'var(--bg-card)', padding: '10px 10px 10px 24px', borderRadius: 20,
|
| 1068 |
border: `2.5px solid var(--border-subtle)`, boxShadow: '0 10px 40px rgba(0,0,0,0.05)',
|
| 1069 |
transition: 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)', alignItems: 'center'
|
| 1070 |
-
}
|
| 1071 |
-
onFocusCapture={e => { e.currentTarget.style.borderColor = COLORS.brand; e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 10px 40px rgba(124, 58, 237, 0.1)'; }
|
| 1072 |
-
onBlurCapture={e => { e.currentTarget.style.borderColor = COLORS.gray200; e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = '0 10px 40px rgba(0,0,0,0.05)'; }
|
| 1073 |
>
|
| 1074 |
<input
|
| 1075 |
placeholder="Message Nexus..."
|
|
@@ -1079,7 +1147,7 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 1079 |
style={{
|
| 1080 |
flex: 1, border: 'none', background: 'none', fontSize: 16,
|
| 1081 |
fontWeight: 600, color: COLORS.gray900, outline: 'none'
|
| 1082 |
-
}
|
| 1083 |
/>
|
| 1084 |
<button
|
| 1085 |
type="submit"
|
|
@@ -1090,12 +1158,12 @@ export const NexusHub: React.FC<NexusHubProps> = ({ mode = "chat" }) => {
|
|
| 1090 |
display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 18,
|
| 1091 |
opacity: (!inputText.trim() || loading) ? 0.3 : 1, transition: 'all 0.2s',
|
| 1092 |
boxShadow: '0 4px 12px rgba(124, 58, 237, 0.2)'
|
| 1093 |
-
}
|
| 1094 |
>
|
| 1095 |
<ArrowUpRight size={18} />
|
| 1096 |
</button>
|
| 1097 |
</form>
|
| 1098 |
-
<div style={{ textAlign: 'center', marginTop: 12, fontSize: 10, color: COLORS.gray400, fontWeight: 800, textTransform: 'uppercase', letterSpacing: '0.1em' }
|
| 1099 |
End-to-End Encrypted Workspace Channel
|
| 1100 |
</div>
|
| 1101 |
</div>
|
|
|
|
| 20 |
Trash2,
|
| 21 |
BookOpen,
|
| 22 |
FileText,
|
| 23 |
+
Presentation,
|
| 24 |
+
Download,
|
| 25 |
+
X
|
| 26 |
} from 'lucide-react';
|
| 27 |
import { useNotification } from '@nexus/shared';
|
| 28 |
|
|
|
|
| 84 |
stories,
|
| 85 |
fetchStories,
|
| 86 |
generateStory,
|
| 87 |
+
deleteStory,
|
| 88 |
isGeneratingStory
|
| 89 |
} = useNexus();
|
| 90 |
|
| 91 |
const { user } = useAuth();
|
| 92 |
+
const [customInstructions, setCustomInstructions] = useState('');
|
| 93 |
const isExternal = user?.role === 'customer_admin' || user?.role === 'customer_user';
|
| 94 |
|
| 95 |
const canGenerateStory = user?.role === 'customer_admin' ||
|
|
|
|
| 243 |
fontFamily: 'Inter, system-ui, sans-serif',
|
| 244 |
overflow: 'hidden',
|
| 245 |
position: 'relative'
|
| 246 |
+
}>
|
| 247 |
<style>{`
|
| 248 |
@keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
|
| 249 |
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
|
|
| 290 |
overflow: 'hidden',
|
| 291 |
position: 'relative',
|
| 292 |
boxShadow: showSessions ? '20px 0 50px rgba(0,0,0,0.05)' : 'none'
|
| 293 |
+
}>
|
| 294 |
{internalMode === "chat" && (
|
| 295 |
+
<div style={{ padding: '32px 24px 16px 24px', minWidth: 320 }>
|
| 296 |
<button
|
| 297 |
+
onClick={() => { setThreadId(null); setInputText(""); setShowSessions(false); }
|
| 298 |
style={{
|
| 299 |
width: '100%',
|
| 300 |
padding: '14px',
|
|
|
|
| 312 |
boxShadow: '0 8px 24px rgba(124, 58, 237, 0.2)',
|
| 313 |
textTransform: 'uppercase',
|
| 314 |
letterSpacing: '0.05em'
|
| 315 |
+
}
|
| 316 |
>
|
| 317 |
<MessageSquare size={18} /> New Session
|
| 318 |
</button>
|
|
|
|
| 320 |
)}
|
| 321 |
|
| 322 |
{internalMode === "library" && (
|
| 323 |
+
<div style={{ padding: '32px 24px 16px 24px', minWidth: 320 }>
|
| 324 |
<button
|
| 325 |
onClick={() => setIsAddingQuery(true)}
|
| 326 |
style={{
|
|
|
|
| 340 |
boxShadow: '0 8px 24px rgba(124, 58, 237, 0.2)',
|
| 341 |
textTransform: 'uppercase',
|
| 342 |
letterSpacing: '0.05em'
|
| 343 |
+
}
|
| 344 |
>
|
| 345 |
<Zap size={18} /> Add Command
|
| 346 |
</button>
|
|
|
|
| 348 |
)}
|
| 349 |
|
| 350 |
{internalMode === "stories" && (
|
| 351 |
+
<div style={{ padding: '32px 24px 16px 24px', minWidth: 320, display: 'flex', flexDirection: 'column', gap: 12 }>
|
| 352 |
{!canGenerateStory ? (
|
| 353 |
+
<div style={{ padding: '16px', borderRadius: 12, background: `${COLORS.brand}05`, border: `1px solid ${COLORS.brand}15`, textAlign: 'center' }>
|
| 354 |
+
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.brand, marginBottom: 4 }>Standard Access</div>
|
| 355 |
+
<div style={{ fontSize: 11, color: COLORS.gray500, lineHeight: 1.4 }>Workspace narratives are restricted to Administrative and Lead personnel.</div>
|
| 356 |
</div>
|
| 357 |
) : (
|
| 358 |
+
<div style={{ marginBottom: 20 }>
|
| 359 |
+
<label style={{
|
| 360 |
+
display: 'block',
|
| 361 |
+
fontSize: 11,
|
| 362 |
+
fontWeight: 700,
|
| 363 |
+
color: COLORS.gray400,
|
| 364 |
+
marginBottom: 8,
|
| 365 |
+
textTransform: 'uppercase',
|
| 366 |
+
letterSpacing: '0.05em'
|
| 367 |
+
}>
|
| 368 |
+
Strategic Focus (Optional)
|
| 369 |
+
</label>
|
| 370 |
+
<textarea
|
| 371 |
+
value={customInstructions}
|
| 372 |
+
onChange={(e) => setCustomInstructions(e.target.value)}
|
| 373 |
+
placeholder="e.g. Focus on pending escalations for the Ansell workspace and highlight resolution bottlenecks..."
|
| 374 |
+
style={{
|
| 375 |
+
width: '100%',
|
| 376 |
+
height: 80,
|
| 377 |
+
padding: '12px',
|
| 378 |
+
borderRadius: 12,
|
| 379 |
+
background: 'var(--bg-dark)',
|
| 380 |
+
border: '1px solid var(--border-subtle)',
|
| 381 |
+
color: 'var(--text-main)',
|
| 382 |
+
fontSize: 13,
|
| 383 |
+
resize: 'none',
|
| 384 |
+
outline: 'none',
|
| 385 |
+
transition: 'border-color 0.2s'
|
| 386 |
+
}
|
| 387 |
+
onFocus={(e) => e.currentTarget.style.borderColor = COLORS.brandPurple}
|
| 388 |
+
onBlur={(e) => e.currentTarget.style.borderColor = 'var(--border-subtle)'}
|
| 389 |
+
/>
|
| 390 |
+
</div>
|
| 391 |
+
|
| 392 |
+
<div style={{ display: 'flex', gap: 12 }>
|
| 393 |
<button
|
| 394 |
+
onClick={() => {
|
| 395 |
+
generateStory("pdf", customInstructions);
|
| 396 |
+
setCustomInstructions('');
|
| 397 |
+
}
|
| 398 |
disabled={isGeneratingStory}
|
| 399 |
style={{
|
| 400 |
flex: 1,
|
|
|
|
| 413 |
boxShadow: isGeneratingStory ? 'none' : '0 8px 24px rgba(124, 58, 237, 0.2)',
|
| 414 |
textTransform: 'uppercase',
|
| 415 |
transition: 'all 0.2s'
|
| 416 |
+
}
|
| 417 |
>
|
| 418 |
{isGeneratingStory ? <div className="spinner-mini" /> : <FileText size={16} />}
|
| 419 |
{isGeneratingStory ? 'QUEUING...' : 'PDF Story'}
|
| 420 |
</button>
|
| 421 |
<button
|
| 422 |
+
onClick={() => {
|
| 423 |
+
generateStory("pptx", customInstructions);
|
| 424 |
+
setCustomInstructions('');
|
| 425 |
+
}
|
| 426 |
disabled={isGeneratingStory}
|
| 427 |
style={{
|
| 428 |
flex: 1,
|
|
|
|
| 441 |
textTransform: 'uppercase',
|
| 442 |
opacity: isGeneratingStory ? 0.5 : 1,
|
| 443 |
transition: 'all 0.2s'
|
| 444 |
+
}
|
| 445 |
>
|
| 446 |
<Presentation size={16} /> PPT Story
|
| 447 |
</button>
|
|
|
|
| 454 |
ref={sessionListRef}
|
| 455 |
|
| 456 |
onScroll={handleSessionScroll}
|
| 457 |
+
style={{ flex: 1, overflowY: 'auto', padding: '16px 8px', minWidth: 320 }
|
| 458 |
>
|
| 459 |
{internalMode === "library" && (
|
| 460 |
|
| 461 |
<>
|
| 462 |
+
<div style={{ padding: '8px 16px', fontSize: 11, fontWeight: 800, color: COLORS.gray400, textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 8, marginTop: 16 }>Library</div>
|
| 463 |
|
| 464 |
{isAddingQuery && (
|
| 465 |
<div style={{
|
|
|
|
| 469 |
borderRadius: 16,
|
| 470 |
border: `1.5px solid ${COLORS.brand}40`,
|
| 471 |
animation: 'fadeIn 0.3s ease'
|
| 472 |
+
}>
|
| 473 |
<form onSubmit={handleSaveNewQuery}>
|
| 474 |
<input
|
| 475 |
autoFocus
|
| 476 |
placeholder="Command Title..."
|
| 477 |
value={newQueryTitle}
|
| 478 |
onChange={e => setNewQueryTitle(e.target.value)}
|
| 479 |
+
style={{ width: '100%', padding: '8px 0', border: 'none', borderBottom: `1px solid ${COLORS.gray100}`, background: 'none', color: COLORS.gray900, fontSize: 13, fontWeight: 700, outline: 'none', marginBottom: 12 }
|
| 480 |
/>
|
| 481 |
<textarea
|
| 482 |
placeholder="Enter the full command text..."
|
| 483 |
value={newQueryText}
|
| 484 |
onChange={e => setNewQueryText(e.target.value)}
|
| 485 |
+
style={{ width: '100%', padding: '8px 0', border: 'none', background: 'none', color: COLORS.gray600, fontSize: 12, fontWeight: 500, outline: 'none', minHeight: 60, resize: 'none', marginBottom: 12 }
|
| 486 |
/>
|
| 487 |
+
<div style={{ display: 'flex', gap: 8 }>
|
| 488 |
<button
|
| 489 |
type="submit"
|
| 490 |
disabled={!newQueryTitle.trim() || !newQueryText.trim()}
|
| 491 |
+
style={{ flex: 1, padding: '8px', borderRadius: 10, background: COLORS.brand, color: 'white', border: 'none', fontSize: 11, fontWeight: 800, cursor: 'pointer', opacity: (!newQueryTitle.trim() || !newQueryText.trim()) ? 0.4 : 1 }
|
| 492 |
className="btn-primary"
|
| 493 |
>
|
| 494 |
SAVE
|
|
|
|
| 496 |
<button
|
| 497 |
type="button"
|
| 498 |
onClick={() => setIsAddingQuery(false)}
|
| 499 |
+
style={{ padding: '8px 12px', borderRadius: 10, background: 'none', border: `1px solid ${COLORS.gray200}`, color: COLORS.gray500, fontSize: 11, fontWeight: 800, cursor: 'pointer' }
|
| 500 |
className="btn-secondary"
|
| 501 |
>
|
| 502 |
CANCEL
|
|
|
|
| 518 |
borderRadius: 16,
|
| 519 |
border: `1.5px solid ${COLORS.brand}40`,
|
| 520 |
animation: 'fadeIn 0.3s ease'
|
| 521 |
+
}>
|
| 522 |
<form onSubmit={handleUpdateQuery}>
|
| 523 |
<input
|
| 524 |
autoFocus
|
| 525 |
placeholder="Command Title..."
|
| 526 |
value={editQueryTitle}
|
| 527 |
onChange={e => setEditQueryTitle(e.target.value)}
|
| 528 |
+
style={{ width: '100%', padding: '8px 0', border: 'none', borderBottom: `1px solid ${COLORS.gray100}`, background: 'none', color: COLORS.gray900, fontSize: 13, fontWeight: 700, outline: 'none', marginBottom: 12 }
|
| 529 |
/>
|
| 530 |
<textarea
|
| 531 |
placeholder="Enter the full command text..."
|
| 532 |
value={editQueryText}
|
| 533 |
onChange={e => setEditQueryText(e.target.value)}
|
| 534 |
+
style={{ width: '100%', padding: '8px 0', border: 'none', background: 'none', color: COLORS.gray600, fontSize: 12, fontWeight: 500, outline: 'none', minHeight: 60, resize: 'none', marginBottom: 12 }
|
| 535 |
/>
|
| 536 |
+
<div style={{ display: 'flex', gap: 8 }>
|
| 537 |
<button
|
| 538 |
type="submit"
|
| 539 |
disabled={!editQueryTitle.trim() || !editQueryText.trim()}
|
| 540 |
+
style={{ flex: 1, padding: '8px', borderRadius: 10, background: COLORS.brand, color: 'white', border: 'none', fontSize: 11, fontWeight: 800, cursor: 'pointer', opacity: (!editQueryTitle.trim() || !editQueryText.trim()) ? 0.4 : 1 }
|
| 541 |
className="btn-primary"
|
| 542 |
>
|
| 543 |
UPDATE
|
|
|
|
| 545 |
<button
|
| 546 |
type="button"
|
| 547 |
onClick={() => setEditingQueryId(null)}
|
| 548 |
+
style={{ padding: '8px 12px', borderRadius: 10, background: 'none', border: `1px solid ${COLORS.gray200}`, color: COLORS.gray500, fontSize: 11, fontWeight: 800, cursor: 'pointer' }
|
| 549 |
className="btn-secondary"
|
| 550 |
>
|
| 551 |
CANCEL
|
|
|
|
| 563 |
query(q.query_text);
|
| 564 |
setInternalMode("chat");
|
| 565 |
setShowSessions(false);
|
| 566 |
+
}
|
| 567 |
style={{
|
| 568 |
padding: '12px 16px',
|
| 569 |
borderRadius: 12,
|
|
|
|
| 575 |
transition: 'all 0.2s',
|
| 576 |
background: 'transparent',
|
| 577 |
border: '1px solid transparent'
|
| 578 |
+
}
|
| 579 |
+
onMouseEnter={e => { e.currentTarget.style.background = `${COLORS.brand}08`; e.currentTarget.style.borderColor = `${COLORS.brand}20` }
|
| 580 |
+
onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.borderColor = 'transparent' }
|
| 581 |
>
|
| 582 |
<div style={{
|
| 583 |
width: 28, height: 28, borderRadius: 8, background: q.is_system ? `${COLORS.brand}15` : COLORS.gray50,
|
| 584 |
display: 'flex', alignItems: 'center', justifyContent: 'center', color: q.is_system ? COLORS.brand : COLORS.gray400
|
| 585 |
+
}>
|
| 586 |
<Icon size={14} />
|
| 587 |
</div>
|
| 588 |
+
<div style={{ flex: 1, minWidth: 0 }>
|
| 589 |
+
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray700, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }>{q.title}</div>
|
| 590 |
+
{q.is_system && <div style={{ fontSize: 9, fontWeight: 800, color: COLORS.brand, opacity: 0.7, textTransform: 'uppercase' }>System Preset</div>}
|
| 591 |
</div>
|
| 592 |
|
| 593 |
{!q.is_system && (
|
|
|
|
| 598 |
setEditingQueryId(q.id);
|
| 599 |
setEditQueryTitle(q.title);
|
| 600 |
setEditQueryText(q.query_text);
|
| 601 |
+
}
|
| 602 |
+
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: COLORS.gray300 }
|
| 603 |
>
|
| 604 |
<Edit3 size={14} />
|
| 605 |
</button>
|
| 606 |
<button
|
| 607 |
onClick={(e) => handleDeleteQuery(e, q.id)}
|
| 608 |
+
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: COLORS.gray300 }
|
| 609 |
>
|
| 610 |
<Trash2 size={14} />
|
| 611 |
</button>
|
|
|
|
| 621 |
{internalMode === "chat" && (
|
| 622 |
|
| 623 |
<>
|
| 624 |
+
<div style={{ padding: '24px 16px 8px 16px', fontSize: 11, fontWeight: 800, color: COLORS.gray400, textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 8 }>Recent Signals</div>
|
| 625 |
|
| 626 |
{sessions.map((s: NexusThread) => (
|
| 627 |
<div
|
|
|
|
| 640 |
transition: 'all 0.2s',
|
| 641 |
position: 'relative',
|
| 642 |
border: threadId === s.id ? `1px solid ${COLORS.brand}30` : '1px solid transparent'
|
| 643 |
+
}
|
| 644 |
+
onMouseEnter={e => { if (threadId !== s.id) e.currentTarget.style.background = COLORS.gray50 }
|
| 645 |
+
onMouseLeave={e => { if (threadId !== s.id) e.currentTarget.style.background = 'transparent' }
|
| 646 |
>
|
| 647 |
+
<div style={{ flex: 1, minWidth: 0, display: 'flex', alignItems: 'center', gap: 10 }>
|
| 648 |
+
<span style={{ opacity: threadId === s.id ? 1 : 0.5 }>
|
| 649 |
{threadId === s.id ? <Zap size={16} color={COLORS.brand} /> : <MessageSquare size={16} />}
|
| 650 |
</span>
|
| 651 |
{editingThread === s.id ? (
|
|
|
|
| 665 |
outline: `2px solid var(--primary)`,
|
| 666 |
borderRadius: 4,
|
| 667 |
padding: '2px 4px'
|
| 668 |
+
}
|
| 669 |
/>
|
| 670 |
) : (
|
| 671 |
+
<div style={{ flex: 1, minWidth: 0 }>
|
| 672 |
+
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray900, marginBottom: 2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }>{s.title}</div>
|
| 673 |
+
<div style={{ fontSize: 10, color: COLORS.gray400, fontWeight: 600 }>{formatTimestamp(s.updated_at)}</div>
|
| 674 |
</div>
|
| 675 |
)}
|
| 676 |
</div>
|
| 677 |
+
<div style={{ display: 'flex', gap: 4, marginLeft: 8 }>
|
| 678 |
<button
|
| 679 |
+
onClick={(e) => { e.stopPropagation(); toggleBookmark(s.id, !s.is_bookmarked); }
|
| 680 |
+
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: s.is_bookmarked ? COLORS.brand : COLORS.gray300 }
|
| 681 |
title={s.is_bookmarked ? "Unbookmark" : "Bookmark"}
|
| 682 |
>
|
| 683 |
<Bookmark size={14} fill={s.is_bookmarked ? COLORS.brand : 'none'} />
|
|
|
|
| 685 |
<button
|
| 686 |
onClick={(e) => startRename(e, s)}
|
| 687 |
className="rename-btn"
|
| 688 |
+
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: COLORS.gray300, opacity: 0, transition: 'opacity 0.2s' }
|
| 689 |
>
|
| 690 |
<Edit3 size={14} />
|
| 691 |
</button>
|
| 692 |
<button
|
| 693 |
onClick={(e) => handleDeleteThread(e, s.id)}
|
| 694 |
+
style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer', color: COLORS.gray300 }
|
| 695 |
>
|
| 696 |
<Trash2 size={14} />
|
| 697 |
</button>
|
|
|
|
| 700 |
))}
|
| 701 |
|
| 702 |
{paginationLoading && (
|
| 703 |
+
<div style={{ padding: '20px', textAlign: 'center', animation: 'pulse-soft 2s infinite' }>
|
| 704 |
+
<div style={{ width: 6, height: 6, borderRadius: '50%', background: COLORS.brand, margin: '0 auto' } />
|
| 705 |
</div>
|
| 706 |
)}
|
| 707 |
|
| 708 |
{!paginationLoading && !hasMore && sessions.length > 0 && (
|
| 709 |
+
<div style={{ padding: '24px 16px', textAlign: 'center', opacity: 0.3, fontSize: 10, fontWeight: 800, textTransform: 'uppercase', letterSpacing: '0.1em' }>
|
| 710 |
End of history
|
| 711 |
</div>
|
| 712 |
)}
|
| 713 |
|
| 714 |
{sessions.length === 0 && (
|
| 715 |
+
<div style={{ padding: '20px', textAlign: 'center', color: COLORS.gray400, fontSize: 13 }>
|
| 716 |
No previous signals.
|
| 717 |
</div>
|
| 718 |
)}
|
|
|
|
| 720 |
)}
|
| 721 |
|
| 722 |
{internalMode === "library" && (
|
| 723 |
+
<div style={{ padding: '24px 16px', textAlign: 'center', color: COLORS.gray400, fontSize: 12, lineHeight: 1.5 }>
|
| 724 |
+
<BookOpen size={24} style={{ marginBottom: 12, opacity: 0.5 } />
|
| 725 |
<div>Select a tactical operation from the library above to initialize a command session.</div>
|
| 726 |
</div>
|
| 727 |
)}
|
| 728 |
|
| 729 |
{internalMode === "stories" && (
|
| 730 |
+
<div style={{ padding: '16px', minWidth: 320 }>
|
| 731 |
{error && internalMode === "stories" && (
|
| 732 |
<div style={{
|
| 733 |
padding: '12px 16px', borderRadius: 12, background: '#F43F5E10',
|
| 734 |
border: '1px solid #F43F5E20', marginBottom: 16,
|
| 735 |
display: 'flex', alignItems: 'center', gap: 10,
|
| 736 |
animation: 'shake 0.4s cubic-bezier(.36,.07,.19,.97) both'
|
| 737 |
+
}>
|
| 738 |
+
<div style={{ color: '#F43F5E' }><Zap size={16} /></div>
|
| 739 |
+
<div style={{ fontSize: 11, fontWeight: 600, color: '#F43F5E' }>{error}</div>
|
| 740 |
</div>
|
| 741 |
)}
|
| 742 |
|
| 743 |
+
<div style={{ fontSize: 11, fontWeight: 800, color: COLORS.gray400, textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 16, paddingLeft: 8 }>Generated Narratives</div>
|
| 744 |
{stories.map(s => (
|
| 745 |
<div key={s.id} style={{
|
| 746 |
padding: '16px', borderRadius: 16, background: 'var(--bg-dark)',
|
| 747 |
border: '1px solid var(--border-subtle)', marginBottom: 12,
|
| 748 |
display: 'flex', flexDirection: 'column', gap: 10
|
| 749 |
+
}>
|
| 750 |
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
|
| 751 |
+
<div style={{ flex: 1 }}>
|
| 752 |
+
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray900 }}>{s.title}</div>
|
| 753 |
+
</div>
|
| 754 |
+
<button
|
| 755 |
+
onClick={(e) => {
|
| 756 |
+
e.stopPropagation();
|
| 757 |
+
if (window.confirm("Delete this story? If it is still generating, the task will be cancelled.")) {
|
| 758 |
+
deleteStory(s.id);
|
| 759 |
+
}
|
| 760 |
+
}}
|
| 761 |
+
style={{
|
| 762 |
+
background: 'none', border: 'none', color: COLORS.gray300, cursor: 'pointer',
|
| 763 |
+
padding: 4, borderRadius: 8, transition: 'all 0.2s'
|
| 764 |
+
}}
|
| 765 |
+
onMouseOver={(e) => {
|
| 766 |
+
e.currentTarget.style.color = '#F43F5E';
|
| 767 |
+
e.currentTarget.style.background = '#F43F5E10';
|
| 768 |
+
}}
|
| 769 |
+
onMouseOut={(e) => {
|
| 770 |
+
e.currentTarget.style.color = COLORS.gray300;
|
| 771 |
+
e.currentTarget.style.background = 'none';
|
| 772 |
+
}}
|
| 773 |
+
>
|
| 774 |
+
<X size={14} />
|
| 775 |
+
</button>
|
| 776 |
<div style={{
|
| 777 |
fontSize: 9, fontWeight: 800, padding: '2px 6px', borderRadius: 6,
|
| 778 |
background: s.status === 'completed' ? '#10B98120' : s.status === 'processing' ? '#7C3AED20' : '#F43F5E20',
|
| 779 |
color: s.status === 'completed' ? '#10B981' : s.status === 'processing' ? '#7C3AED' : '#F43F5E',
|
| 780 |
textTransform: 'uppercase'
|
| 781 |
+
}>
|
| 782 |
{s.status}
|
| 783 |
</div>
|
| 784 |
</div>
|
| 785 |
{s.narrative_preview && (
|
| 786 |
+
<div style={{ fontSize: 11, color: COLORS.gray400, fontStyle: 'italic', lineClamp: 2, display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical' as any, overflow: 'hidden' }>
|
| 787 |
"{s.narrative_preview}..."
|
| 788 |
</div>
|
| 789 |
)}
|
| 790 |
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 4 }}>
|
| 791 |
+
<div style={{ fontSize: 10, color: COLORS.gray300 }>{formatTimestamp(s.created_at)}</div>
|
| 792 |
{s.status === 'completed' && (
|
| 793 |
+
<a href={`${window.location.origin}${s.file_path}?token=${localStorage.getItem('token')}`} target="_blank" rel="noreferrer" style={{ fontSize: 11, fontWeight: 700, color: COLORS.brand, textDecoration: 'none', display: 'flex', alignItems: 'center', gap: 4 }}>
|
| 794 |
DOWNLOAD {s.file_type.toUpperCase()} <ArrowUpRight size={12} />
|
| 795 |
</a>
|
| 796 |
)}
|
|
|
|
| 798 |
</div>
|
| 799 |
))}
|
| 800 |
{stories.length === 0 && (
|
| 801 |
+
<div style={{ padding: '40px 20px', textAlign: 'center', color: COLORS.gray400 }>
|
| 802 |
+
<Presentation size={32} style={{ marginBottom: 16, opacity: 0.2, marginInline: 'auto' } />
|
| 803 |
+
<div style={{ fontSize: 13, fontWeight: 600 }>No stories generated yet.</div>
|
| 804 |
<div style={{ fontSize: 11, marginTop: 4 }}>Initialize a new story above to build a cohesive workspace narrative.</div>
|
| 805 |
</div>
|
| 806 |
)}
|
|
|
|
| 810 |
</div>
|
| 811 |
|
| 812 |
{internalMode === "chat" && (
|
| 813 |
+
<div style={{ padding: '16px', borderTop: `1px solid ${COLORS.gray100}`, minWidth: 320 }>
|
| 814 |
+
<div style={{ fontSize: 10, color: COLORS.gray400, textAlign: 'center', fontWeight: 700 }>{totalSessions} TOTAL SIGNALS</div>
|
| 815 |
</div>
|
| 816 |
)}
|
| 817 |
|
| 818 |
</div>
|
| 819 |
|
| 820 |
{/* Main Chat Area */}
|
| 821 |
+
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', background: 'var(--bg-dark)', position: 'relative' }>
|
| 822 |
{/* Fixed Left Tool Rail */}
|
| 823 |
<div style={{
|
| 824 |
position: 'absolute',
|
|
|
|
| 836 |
gap: 16,
|
| 837 |
zIndex: 45,
|
| 838 |
boxShadow: '4px 0 24px rgba(0,0,0,0.02)'
|
| 839 |
+
}>
|
| 840 |
{/* Main Sidebar Toggle (Workspace Icon) */}
|
| 841 |
<button
|
| 842 |
onClick={() => {
|
|
|
|
| 846 |
setInternalMode("chat");
|
| 847 |
setShowSessions(true);
|
| 848 |
}
|
| 849 |
+
}
|
| 850 |
style={{
|
| 851 |
width: 52,
|
| 852 |
height: 52,
|
|
|
|
| 861 |
fontSize: 22,
|
| 862 |
color: (internalMode === "chat" && showSessions) ? 'white' : COLORS.gray600,
|
| 863 |
transition: 'all 0.4s cubic-bezier(0.19, 1, 0.22, 1)',
|
| 864 |
+
}
|
| 865 |
title="Signals"
|
| 866 |
>
|
| 867 |
|
|
|
|
| 876 |
setInternalMode("library");
|
| 877 |
setShowSessions(true);
|
| 878 |
}
|
| 879 |
+
}
|
| 880 |
style={{
|
| 881 |
width: 52,
|
| 882 |
height: 52,
|
|
|
|
| 891 |
fontSize: 22,
|
| 892 |
color: (internalMode === "library" && showSessions) ? 'white' : COLORS.gray600,
|
| 893 |
transition: 'all 0.4s cubic-bezier(0.19, 1, 0.22, 1)',
|
| 894 |
+
}
|
| 895 |
title="Library"
|
| 896 |
>
|
| 897 |
|
|
|
|
| 906 |
setInternalMode("stories");
|
| 907 |
setShowSessions(true);
|
| 908 |
}
|
| 909 |
+
}
|
| 910 |
style={{
|
| 911 |
width: 52,
|
| 912 |
height: 52,
|
|
|
|
| 921 |
fontSize: 22,
|
| 922 |
color: (internalMode === "stories" && showSessions) ? 'white' : COLORS.gray600,
|
| 923 |
transition: 'all 0.4s cubic-bezier(0.19, 1, 0.22, 1)',
|
| 924 |
+
}
|
| 925 |
title="Workspace Stories"
|
| 926 |
>
|
| 927 |
<Presentation size={24} />
|
| 928 |
</button>
|
| 929 |
|
| 930 |
|
| 931 |
+
<div style={{ width: 32, height: 1, background: COLORS.gray100, margin: '8px 0', opacity: 0.5 } />
|
| 932 |
</div>
|
| 933 |
|
| 934 |
{/* Messages List */}
|
|
|
|
| 943 |
justifyContent: messages.length === 0 && !loading && !historyLoading ? 'center' : 'flex-start',
|
| 944 |
gap: 32,
|
| 945 |
animation: 'fadeIn 0.6s ease'
|
| 946 |
+
}
|
| 947 |
>
|
| 948 |
+
<div style={{ maxWidth: 840, width: '100%', margin: '0 auto', display: 'flex', flexDirection: 'column', gap: 32, padding: '0 40px' }>
|
| 949 |
|
| 950 |
{/* Background Sync Indicator */}
|
| 951 |
{historyLoading && (
|
|
|
|
| 964 |
gap: 10,
|
| 965 |
zIndex: 100,
|
| 966 |
animation: 'fadeIn 0.5s ease'
|
| 967 |
+
}>
|
| 968 |
+
<div style={{ width: 6, height: 6, borderRadius: '50%', background: COLORS.brand, animation: 'pulse-soft 1.5s infinite' } />
|
| 969 |
+
<span style={{ fontSize: 11, fontWeight: 800, color: COLORS.gray500, textTransform: 'uppercase', letterSpacing: '0.05em' }>Syncing Neural Context</span>
|
| 970 |
</div>
|
| 971 |
)}
|
| 972 |
|
| 973 |
{messages.length === 0 && !loading && (
|
| 974 |
+
<div style={{ textAlign: 'center', maxWidth: 640, alignSelf: 'center', paddingBottom: '32px' }>
|
| 975 |
+
<div style={{ position: 'relative', width: 96, height: 96, margin: '0 auto 32px' }>
|
| 976 |
<div style={{
|
| 977 |
width: 96, height: 96, borderRadius: '50%',
|
| 978 |
background: COLORS.brandGradient,
|
| 979 |
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
| 980 |
fontSize: 32, color: 'white', fontWeight: 900, position: 'relative', zIndex: 2,
|
| 981 |
boxShadow: '0 12px 40px rgba(124, 58, 237, 0.3)'
|
| 982 |
+
}>NX</div>
|
| 983 |
<div style={{
|
| 984 |
position: 'absolute', top: 4, right: 4, width: 24, height: 24,
|
| 985 |
borderRadius: '50%', background: '#10B981', border: '5px solid var(--bg-card)',
|
| 986 |
zIndex: 3, boxShadow: '0 4px 8px rgba(0,0,0,0.1)'
|
| 987 |
+
} />
|
| 988 |
<div style={{
|
| 989 |
position: 'absolute', inset: -15, borderRadius: '50%',
|
| 990 |
background: COLORS.brandGradient, opacity: 0.1,
|
| 991 |
animation: 'nexus-pulse 3s infinite'
|
| 992 |
+
} />
|
| 993 |
</div>
|
| 994 |
|
| 995 |
+
<h2 style={{ fontSize: 28, fontWeight: 900, color: COLORS.gray900, marginBottom: 12, letterSpacing: '-0.02em' }>
|
| 996 |
{internalMode === "library" ? "Command Library" : "How can Nexus help today?"}
|
| 997 |
</h2>
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
+
<p style={{ fontSize: 16, color: COLORS.gray500, marginBottom: 48, fontWeight: 500 }>
|
| 1002 |
Secure workspace orchestration, technical support, and deep diagnostics.
|
| 1003 |
</p>
|
| 1004 |
|
| 1005 |
+
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, justifyContent: 'center', maxWidth: 800, margin: '0 auto' }>
|
| 1006 |
{(savedQueries.length > 0 ? savedQueries.slice(0, 4) : (
|
| 1007 |
isExternal ? [
|
| 1008 |
{ title: "Ticket Summary", icon: "Zap", query_text: "Give me a summary of my active tickets" },
|
|
|
|
| 1025 |
style={{
|
| 1026 |
padding: '10px 18px', borderRadius: 12, border: `1.5px solid var(--border-subtle)`, background: 'var(--bg-card)',
|
| 1027 |
display: 'flex', alignItems: 'center', gap: 10, cursor: 'pointer', transition: 'all 0.2s cubic-bezier(0.19, 1, 0.22, 1)',
|
| 1028 |
+
}
|
| 1029 |
+
onMouseEnter={e => { e.currentTarget.style.borderColor = COLORS.brand; e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 8px 20px rgba(0,0,0,0.06)'; }
|
| 1030 |
+
onMouseLeave={e => { e.currentTarget.style.borderColor = COLORS.gray200; e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = 'none'; }
|
| 1031 |
>
|
| 1032 |
+
<span style={{ color: COLORS.brand }>{Icon}</span>
|
| 1033 |
+
<span style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray700 }>{s.title || s.label}</span>
|
| 1034 |
</button>
|
| 1035 |
);
|
| 1036 |
})}
|
|
|
|
| 1043 |
<div key={i} style={{
|
| 1044 |
display: 'flex', flexDirection: 'column', alignSelf: m.role === 'user' ? 'flex-end' : 'flex-start',
|
| 1045 |
maxWidth: '90%', gap: 8, animation: 'slideIn 0.3s ease-out'
|
| 1046 |
+
}>
|
| 1047 |
<div style={{
|
| 1048 |
fontSize: 10, fontWeight: 800, color: COLORS.gray400, display: 'flex', gap: 8,
|
| 1049 |
flexDirection: m.role === 'user' ? 'row-reverse' : 'row', padding: '0 8px', textTransform: 'uppercase'
|
| 1050 |
+
}>
|
| 1051 |
+
<span style={{ color: m.role === 'user' ? COLORS.brand : COLORS.gray500 }>{m.senderName}</span>
|
| 1052 |
+
<span style={{ opacity: 0.4 }>•</span>
|
| 1053 |
<span>{formatTimestamp(m.timestamp)}</span>
|
| 1054 |
{m.role === 'user' && (
|
| 1055 |
<button
|
| 1056 |
onClick={() => {
|
| 1057 |
const title = window.prompt("Save this query to your library as:", m.content.slice(0, 30) + "...");
|
| 1058 |
if (title) saveQuery(title, m.content);
|
| 1059 |
+
}
|
| 1060 |
style={{
|
| 1061 |
marginLeft: 'auto', background: 'none', border: 'none',
|
| 1062 |
color: COLORS.gray400, cursor: 'pointer', padding: 0,
|
| 1063 |
display: 'flex', alignItems: 'center', gap: 4
|
| 1064 |
+
}
|
| 1065 |
>
|
| 1066 |
+
<Bookmark size={10} /> <span style={{ fontSize: 9 }>SAVE</span>
|
| 1067 |
</button>
|
| 1068 |
)}
|
| 1069 |
</div>
|
| 1070 |
|
| 1071 |
|
| 1072 |
+
<div style={{ display: 'flex', gap: 16, flexDirection: m.role === 'user' ? 'row-reverse' : 'row', alignItems: 'flex-start' }>
|
| 1073 |
<div style={{
|
| 1074 |
width: 36, height: 36, borderRadius: 10, background: m.role === 'user' ? COLORS.gray100 : COLORS.brandGradient,
|
| 1075 |
display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 13, fontWeight: 900,
|
| 1076 |
color: m.role === 'user' ? COLORS.brand : '#fff', flexShrink: 0, marginTop: 4
|
| 1077 |
+
}>
|
| 1078 |
{m.role === 'user' ? 'U' : 'NX'}
|
| 1079 |
</div>
|
| 1080 |
<div style={{
|
| 1081 |
padding: '16px 20px', borderRadius: 20, background: m.role === 'user' ? 'var(--primary)' : 'var(--bg-card)',
|
| 1082 |
color: m.role === 'user' ? 'white' : 'var(--text-main)', fontSize: 15, lineHeight: 1.6, fontWeight: 500,
|
| 1083 |
border: m.role === 'assistant' ? `1px solid var(--border-subtle)` : 'none'
|
| 1084 |
+
}>
|
| 1085 |
{m.role === 'assistant' && m.content.includes("[ACTION_REQUIRED]") ? (
|
| 1086 |
(() => {
|
| 1087 |
try {
|
|
|
|
| 1107 |
))}
|
| 1108 |
|
| 1109 |
{(loading || statusMessage) && (
|
| 1110 |
+
<div style={{ display: 'flex', gap: 16, alignSelf: 'flex-start', alignItems: 'center' }>
|
| 1111 |
<div style={{
|
| 1112 |
width: 36, height: 36, borderRadius: 10, background: 'var(--primary-gradient)',
|
| 1113 |
display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0,
|
| 1114 |
animation: 'pulse-soft 2s infinite'
|
| 1115 |
+
}>
|
| 1116 |
+
<span style={{ color: 'white', fontSize: 13, fontWeight: 900 }>NX</span>
|
| 1117 |
</div>
|
| 1118 |
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
| 1119 |
+
<div style={{ fontSize: 12, fontWeight: 700, color: 'var(--primary)', display: 'flex', alignItems: 'center', gap: 8 }>
|
| 1120 |
+
<div style={{ width: 6, height: 6, borderRadius: '50%', background: 'var(--primary)', opacity: 0.8, animation: 'pulse-soft 1s infinite' } />
|
| 1121 |
{statusMessage || "Nexus is thinking..."}
|
| 1122 |
</div>
|
| 1123 |
</div>
|
|
|
|
| 1127 |
</div>
|
| 1128 |
|
| 1129 |
{/* Input Area */}
|
| 1130 |
+
<div style={{ padding: '0 40px 32px 112px', background: 'linear-gradient(to top, var(--bg-dark) 80%, transparent)' }>
|
| 1131 |
+
<div style={{ maxWidth: 840, margin: '0 auto' }>
|
| 1132 |
<form
|
| 1133 |
onSubmit={handleSubmit}
|
| 1134 |
style={{
|
| 1135 |
display: 'flex', gap: 16, background: 'var(--bg-card)', padding: '10px 10px 10px 24px', borderRadius: 20,
|
| 1136 |
border: `2.5px solid var(--border-subtle)`, boxShadow: '0 10px 40px rgba(0,0,0,0.05)',
|
| 1137 |
transition: 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)', alignItems: 'center'
|
| 1138 |
+
}
|
| 1139 |
+
onFocusCapture={e => { e.currentTarget.style.borderColor = COLORS.brand; e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 10px 40px rgba(124, 58, 237, 0.1)'; }
|
| 1140 |
+
onBlurCapture={e => { e.currentTarget.style.borderColor = COLORS.gray200; e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = '0 10px 40px rgba(0,0,0,0.05)'; }
|
| 1141 |
>
|
| 1142 |
<input
|
| 1143 |
placeholder="Message Nexus..."
|
|
|
|
| 1147 |
style={{
|
| 1148 |
flex: 1, border: 'none', background: 'none', fontSize: 16,
|
| 1149 |
fontWeight: 600, color: COLORS.gray900, outline: 'none'
|
| 1150 |
+
}
|
| 1151 |
/>
|
| 1152 |
<button
|
| 1153 |
type="submit"
|
|
|
|
| 1158 |
display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 18,
|
| 1159 |
opacity: (!inputText.trim() || loading) ? 0.3 : 1, transition: 'all 0.2s',
|
| 1160 |
boxShadow: '0 4px 12px rgba(124, 58, 237, 0.2)'
|
| 1161 |
+
}
|
| 1162 |
>
|
| 1163 |
<ArrowUpRight size={18} />
|
| 1164 |
</button>
|
| 1165 |
</form>
|
| 1166 |
+
<div style={{ textAlign: 'center', marginTop: 12, fontSize: 10, color: COLORS.gray400, fontWeight: 800, textTransform: 'uppercase', letterSpacing: '0.1em' }>
|
| 1167 |
End-to-End Encrypted Workspace Channel
|
| 1168 |
</div>
|
| 1169 |
</div>
|
frontend/packages/shared/src/contexts/NexusContext.tsx
CHANGED
|
@@ -58,7 +58,8 @@ interface NexusContextType extends NexusState {
|
|
| 58 |
updateSavedQuery: (id: string, title: string, queryText: string) => Promise<void>;
|
| 59 |
deleteSavedQuery: (id: string) => Promise<void>;
|
| 60 |
fetchStories: () => Promise<void>;
|
| 61 |
-
generateStory: (fileType: string) => Promise<void>;
|
|
|
|
| 62 |
|
| 63 |
setThreadId: (id: string | null) => void;
|
| 64 |
resetState: () => void;
|
|
@@ -591,10 +592,13 @@ export const NexusProvider: React.FC<{ children: ReactNode }> = ({
|
|
| 591 |
}
|
| 592 |
}, []);
|
| 593 |
|
| 594 |
-
const generateStory = useCallback(async (fileType: string) => {
|
| 595 |
try {
|
| 596 |
setState(prev => ({ ...prev, error: null, isGeneratingStory: true }));
|
| 597 |
-
await api.post("nexus/stories/generate/", {
|
|
|
|
|
|
|
|
|
|
| 598 |
await fetchStories();
|
| 599 |
} catch (err: any) {
|
| 600 |
console.error("Failed to generate story:", err);
|
|
@@ -607,6 +611,17 @@ export const NexusProvider: React.FC<{ children: ReactNode }> = ({
|
|
| 607 |
}
|
| 608 |
}, [fetchStories]);
|
| 609 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 610 |
|
| 611 |
const setThreadId = (id: string | null) => {
|
| 612 |
setState((prev) => ({
|
|
@@ -657,6 +672,7 @@ export const NexusProvider: React.FC<{ children: ReactNode }> = ({
|
|
| 657 |
deleteSavedQuery,
|
| 658 |
fetchStories,
|
| 659 |
generateStory,
|
|
|
|
| 660 |
setThreadId,
|
| 661 |
resetState,
|
| 662 |
|
|
|
|
| 58 |
updateSavedQuery: (id: string, title: string, queryText: string) => Promise<void>;
|
| 59 |
deleteSavedQuery: (id: string) => Promise<void>;
|
| 60 |
fetchStories: () => Promise<void>;
|
| 61 |
+
generateStory: (fileType: string, customInstructions?: string) => Promise<void>;
|
| 62 |
+
deleteStory: (id: string) => Promise<void>;
|
| 63 |
|
| 64 |
setThreadId: (id: string | null) => void;
|
| 65 |
resetState: () => void;
|
|
|
|
| 592 |
}
|
| 593 |
}, []);
|
| 594 |
|
| 595 |
+
const generateStory = useCallback(async (fileType: string, customInstructions?: string) => {
|
| 596 |
try {
|
| 597 |
setState(prev => ({ ...prev, error: null, isGeneratingStory: true }));
|
| 598 |
+
await api.post("nexus/stories/generate/", {
|
| 599 |
+
file_type: fileType,
|
| 600 |
+
custom_instructions: customInstructions
|
| 601 |
+
});
|
| 602 |
await fetchStories();
|
| 603 |
} catch (err: any) {
|
| 604 |
console.error("Failed to generate story:", err);
|
|
|
|
| 611 |
}
|
| 612 |
}, [fetchStories]);
|
| 613 |
|
| 614 |
+
const deleteStory = useCallback(async (id: string) => {
|
| 615 |
+
try {
|
| 616 |
+
await api.delete(`nexus/stories/${id}/`);
|
| 617 |
+
await fetchStories();
|
| 618 |
+
} catch (err: any) {
|
| 619 |
+
console.error("Failed to delete story:", err);
|
| 620 |
+
const detail = err.response?.data?.detail || "Failed to delete story.";
|
| 621 |
+
setState((prev) => ({ ...prev, error: detail }));
|
| 622 |
+
}
|
| 623 |
+
}, [fetchStories]);
|
| 624 |
+
|
| 625 |
|
| 626 |
const setThreadId = (id: string | null) => {
|
| 627 |
setState((prev) => ({
|
|
|
|
| 672 |
deleteSavedQuery,
|
| 673 |
fetchStories,
|
| 674 |
generateStory,
|
| 675 |
+
deleteStory,
|
| 676 |
setThreadId,
|
| 677 |
resetState,
|
| 678 |
|
models/workspace_story.py
CHANGED
|
@@ -25,6 +25,9 @@ class WorkspaceStory(Base):
|
|
| 25 |
file_type = Column(String, nullable=False) # "pdf" or "pptx"
|
| 26 |
file_path = Column(String, nullable=True)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
metadata_json = Column(JSON, nullable=True) # Role-aware context used, etc.
|
| 29 |
|
| 30 |
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
| 25 |
file_type = Column(String, nullable=False) # "pdf" or "pptx"
|
| 26 |
file_path = Column(String, nullable=True)
|
| 27 |
|
| 28 |
+
arq_job_id = Column(String, nullable=True)
|
| 29 |
+
custom_instructions = Column(String, nullable=True)
|
| 30 |
+
|
| 31 |
metadata_json = Column(JSON, nullable=True) # Role-aware context used, etc.
|
| 32 |
|
| 33 |
created_at = Column(DateTime, default=datetime.utcnow)
|
scratch/fix_nexushub_braces_final.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
file_path = r'c:\Users\dushy\OneDrive\Documents\_Snowball\Projects\Hackathon\frontend\packages\shared\src\components\NexusHub.tsx'
|
| 4 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 5 |
+
content = f.read()
|
| 6 |
+
|
| 7 |
+
# Fix the missing double braces in the bottom part
|
| 8 |
+
content = content.replace('marginTop: 4 }>', 'marginTop: 4 }}>')
|
| 9 |
+
content = content.replace('gap: 4 }>', 'gap: 4 }}>')
|
| 10 |
+
|
| 11 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 12 |
+
f.write(content)
|
| 13 |
+
print("Successfully fixed remaining double braces in NexusHub.tsx")
|
scratch/fix_nexushub_download.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
file_path = r'c:\Users\dushy\OneDrive\Documents\_Snowball\Projects\Hackathon\frontend\packages\shared\src\components\NexusHub.tsx'
|
| 4 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 5 |
+
content = f.read()
|
| 6 |
+
|
| 7 |
+
# Replace the download link
|
| 8 |
+
target = 'href={s.file_path}'
|
| 9 |
+
replacement = 'href={`${window.location.origin}${s.file_path}?token=${localStorage.getItem(\'token\')}`}'
|
| 10 |
+
|
| 11 |
+
if target in content:
|
| 12 |
+
content = content.replace(target, replacement)
|
| 13 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 14 |
+
f.write(content)
|
| 15 |
+
print("Successfully updated NexusHub.tsx download link")
|
| 16 |
+
else:
|
| 17 |
+
print("Could not find target in NexusHub.tsx")
|
scratch/fix_nexushub_syntax.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
file_path = r'c:\Users\dushy\OneDrive\Documents\_Snowball\Projects\Hackathon\frontend\packages\shared\src\components\NexusHub.tsx'
|
| 4 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 5 |
+
content = f.read()
|
| 6 |
+
|
| 7 |
+
# Fix the double braces
|
| 8 |
+
content = content.replace('(e) => {{', '(e) => {')
|
| 9 |
+
content = content.replace('}})', '})')
|
| 10 |
+
content = content.replace('}} }', '} }')
|
| 11 |
+
# Be very specific about the story deletion block
|
| 12 |
+
content = content.replace('if (window.confirm("Delete this story? If it is still generating, the task will be cancelled.")) {{', 'if (window.confirm("Delete this story? If it is still generating, the task will be cancelled.")) {')
|
| 13 |
+
content = content.replace('deleteStory(s.id);\n }}', 'deleteStory(s.id);\n }')
|
| 14 |
+
content = content.replace('}}\n style', '}\n style')
|
| 15 |
+
|
| 16 |
+
# Check if there are any left
|
| 17 |
+
content = content.replace('onMouseOver={(e) => { \n e.currentTarget.style.color = \'#F43F5E\';\n e.currentTarget.style.background = \'#F43F5E10\';\n }}', 'onMouseOver={(e) => { \n e.currentTarget.style.color = \'#F43F5E\';\n e.currentTarget.style.background = \'#F43F5E10\';\n }}') # Wait, I'll just use regex or similar.
|
| 18 |
+
|
| 19 |
+
# Simpler: just replace the specific strings I saw in view_file
|
| 20 |
+
content = content.replace('(e) => {{', '(e) => {')
|
| 21 |
+
content = content.replace('}}', '}') # CAUTION: this might replace too much.
|
| 22 |
+
# Let's use a more targeted replacement.
|
| 23 |
+
content = content.replace('onClick={(e) => {{', 'onClick={(e) => {')
|
| 24 |
+
content = content.replace('onMouseOver={(e) => {{', 'onMouseOver={(e) => {')
|
| 25 |
+
content = content.replace('onMouseOut={(e) => {{', 'onMouseOut={(e) => {')
|
| 26 |
+
|
| 27 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 28 |
+
f.write(content)
|
| 29 |
+
print("Successfully fixed double braces in NexusHub.tsx")
|
scratch/repair_nexushub_jsx.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
file_path = r'c:\Users\dushy\OneDrive\Documents\_Snowball\Projects\Hackathon\frontend\packages\shared\src\components\NexusHub.tsx'
|
| 4 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 5 |
+
lines = f.readlines()
|
| 6 |
+
|
| 7 |
+
new_lines = []
|
| 8 |
+
for line in lines:
|
| 9 |
+
if 'style={{ flex: 1 }' in line and '}}' not in line:
|
| 10 |
+
new_lines.append(line.replace('style={{ flex: 1 }', 'style={{ flex: 1 }}'))
|
| 11 |
+
elif 'onClick={(e) => {' in line and '}}' not in line:
|
| 12 |
+
# Check if it was double-closed
|
| 13 |
+
new_lines.append(line)
|
| 14 |
+
elif 'style={{' in line and '}}' not in line:
|
| 15 |
+
# Check if it's the beginning of a multiline style
|
| 16 |
+
new_lines.append(line)
|
| 17 |
+
elif '}' in line and '}}' not in line and ('style' in line or 'onClick' in line or 'onMouse' in line):
|
| 18 |
+
# This is where I might have removed too many
|
| 19 |
+
# Let's check for the specific lines I saw
|
| 20 |
+
if '}' in line and '}' not in line[line.find('}')+1:]:
|
| 21 |
+
# If there's only one } at the end, and it's a style property or event, maybe it needs another?
|
| 22 |
+
# Actually, it's safer to just replace the whole block again.
|
| 23 |
+
new_lines.append(line)
|
| 24 |
+
else:
|
| 25 |
+
new_lines.append(line)
|
| 26 |
+
|
| 27 |
+
# Let's just overwrite the block from 750 to 775 with known good code.
|
| 28 |
+
start_idx = -1
|
| 29 |
+
for i, line in enumerate(lines):
|
| 30 |
+
if 'display: \'flex\', justifyContent: \'space-between\', alignItems: \'flex-start\'' in line:
|
| 31 |
+
if i > 740: # Story list section
|
| 32 |
+
start_idx = i
|
| 33 |
+
break
|
| 34 |
+
|
| 35 |
+
if start_idx != -1:
|
| 36 |
+
# Find the end of the button
|
| 37 |
+
end_idx = -1
|
| 38 |
+
for j in range(start_idx, start_idx + 50):
|
| 39 |
+
if '</button>' in lines[j]:
|
| 40 |
+
end_idx = j
|
| 41 |
+
break
|
| 42 |
+
|
| 43 |
+
if end_idx != -1:
|
| 44 |
+
indent = lines[start_idx][:lines[start_idx].find('<')]
|
| 45 |
+
good_block = [
|
| 46 |
+
f'{indent}<div style={{{{ display: \'flex\', justifyContent: \'space-between\', alignItems: \'flex-start\' }}}}>\n',
|
| 47 |
+
f'{indent} <div style={{{{ flex: 1 }}}}>\n',
|
| 48 |
+
f'{indent} <div style={{{{ fontSize: 13, fontWeight: 700, color: COLORS.gray900 }}}}>{{s.title}}</div>\n',
|
| 49 |
+
f'{indent} </div>\n',
|
| 50 |
+
f'{indent} <button\n',
|
| 51 |
+
f'{indent} onClick={{(e) => {{\n',
|
| 52 |
+
f'{indent} e.stopPropagation();\n',
|
| 53 |
+
f'{indent} if (window.confirm("Delete this story? If it is still generating, the task will be cancelled.")) {{\n',
|
| 54 |
+
f'{indent} deleteStory(s.id);\n',
|
| 55 |
+
f'{indent} }}\n',
|
| 56 |
+
f'{indent} }}}}\n',
|
| 57 |
+
f'{indent} style={{{{ \n',
|
| 58 |
+
f'{indent} background: \'none\', border: \'none\', color: COLORS.gray300, cursor: \'pointer\',\n',
|
| 59 |
+
f'{indent} padding: 4, borderRadius: 8, transition: \'all 0.2s\'\n',
|
| 60 |
+
f'{indent} }}}}\n',
|
| 61 |
+
f'{indent} onMouseOver={{(e) => {{\n',
|
| 62 |
+
f'{indent} e.currentTarget.style.color = \'#F43F5E\';\n',
|
| 63 |
+
f'{indent} e.currentTarget.style.background = \'#F43F5E10\';\n',
|
| 64 |
+
f'{indent} }}}}\n',
|
| 65 |
+
f'{indent} onMouseOut={{(e) => {{\n',
|
| 66 |
+
f'{indent} e.currentTarget.style.color = COLORS.gray300;\n',
|
| 67 |
+
f'{indent} e.currentTarget.style.background = \'none\';\n',
|
| 68 |
+
f'{indent} }}}}\n',
|
| 69 |
+
f'{indent} >\n',
|
| 70 |
+
f'{indent} <X size={{14}} />\n',
|
| 71 |
+
f'{indent} </button>\n'
|
| 72 |
+
]
|
| 73 |
+
|
| 74 |
+
final_lines = lines[:start_idx] + good_block + lines[end_idx+1:]
|
| 75 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 76 |
+
f.writelines(final_lines)
|
| 77 |
+
print("Successfully repaired NexusHub.tsx story item block")
|
| 78 |
+
else:
|
| 79 |
+
print("Could not find end of button")
|
| 80 |
+
else:
|
| 81 |
+
print("Could not find start of block")
|
scratch/update_nexus_api.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
file_path = r'c:\Users\dushy\OneDrive\Documents\_Snowball\Projects\Hackathon\api\v1\nexus.py'
|
| 4 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 5 |
+
lines = f.readlines()
|
| 6 |
+
|
| 7 |
+
new_content = """class NexusStoryGenerateRequest(BaseModel):
|
| 8 |
+
file_type: str = "pdf" # "pdf" or "pptx"
|
| 9 |
+
custom_instructions: Optional[str] = None
|
| 10 |
+
|
| 11 |
+
@router.post("/stories/generate/")
|
| 12 |
+
async def generate_workspace_story(
|
| 13 |
+
req: NexusStoryGenerateRequest,
|
| 14 |
+
current_user: User = Depends(get_current_user),
|
| 15 |
+
db: AsyncSession = Depends(get_db),
|
| 16 |
+
arq_pool = Depends(get_arq_pool)
|
| 17 |
+
) -> Any:
|
| 18 |
+
\"\"\"
|
| 19 |
+
Initiate background generation of a role-aware workspace story.
|
| 20 |
+
Enforces a 24-hour frequency limit and restricted role access.
|
| 21 |
+
\"\"\"
|
| 22 |
+
# 1. Role Authorization
|
| 23 |
+
allowed_roles = [UserRole.SC_ADMIN, UserRole.SC_LEAD, UserRole.CUSTOMER_ADMIN]
|
| 24 |
+
if current_user.role not in allowed_roles:
|
| 25 |
+
raise HTTPException(
|
| 26 |
+
status_code=status.HTTP_403_FORBIDDEN,
|
| 27 |
+
detail="Story generation is reserved for Administrative and Lead personnel."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# 2. Frequency Constraint (Once per 24 hours)
|
| 31 |
+
from datetime import timedelta
|
| 32 |
+
limit_time = datetime.utcnow() - timedelta(days=1)
|
| 33 |
+
|
| 34 |
+
stmt = select(WorkspaceStory).where(
|
| 35 |
+
WorkspaceStory.user_id == current_user.id,
|
| 36 |
+
WorkspaceStory.created_at >= limit_time
|
| 37 |
+
)
|
| 38 |
+
res = await db.execute(stmt)
|
| 39 |
+
if res.scalar_one_or_none():
|
| 40 |
+
raise HTTPException(
|
| 41 |
+
status_code=status.HTTP_429_TOO_MANY_REQUESTS,
|
| 42 |
+
detail="Daily limit reached. Workspace narratives can be generated once every 24 hours."
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# 3. Create entry in DB
|
| 46 |
+
story = WorkspaceStory(
|
| 47 |
+
workspace_id=current_user.workspace_id,
|
| 48 |
+
user_id=current_user.id,
|
| 49 |
+
title=f"Workspace Story - {datetime.utcnow().strftime('%Y-%m-%d %H:%M')}",
|
| 50 |
+
file_type=req.file_type,
|
| 51 |
+
status=StoryStatus.PENDING,
|
| 52 |
+
custom_instructions=req.custom_instructions
|
| 53 |
+
)
|
| 54 |
+
db.add(story)
|
| 55 |
+
await db.commit()
|
| 56 |
+
await db.refresh(story)
|
| 57 |
+
|
| 58 |
+
# 4. Enqueue background task (Explicitly route to HEAVY queue)
|
| 59 |
+
job = await arq_pool.enqueue_job(
|
| 60 |
+
"generate_workspace_story_task",
|
| 61 |
+
story_id=story.id,
|
| 62 |
+
user_id=current_user.id,
|
| 63 |
+
workspace_id=current_user.workspace_id,
|
| 64 |
+
role=str(current_user.role.value) if hasattr(current_user.role, 'value') else str(current_user.role),
|
| 65 |
+
_queue_name="arq:heavy"
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
story.arq_job_id = job.job_id
|
| 69 |
+
await db.commit()
|
| 70 |
+
|
| 71 |
+
return {"status": "success", "story_id": story.id}
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
@router.delete("/stories/{story_id}/")
|
| 75 |
+
async def delete_workspace_story(
|
| 76 |
+
story_id: UUID,
|
| 77 |
+
db: AsyncSession = Depends(get_db),
|
| 78 |
+
current_user: User = Depends(get_current_user),
|
| 79 |
+
arq_pool = Depends(get_arq_pool)
|
| 80 |
+
) -> Any:
|
| 81 |
+
\"\"\"
|
| 82 |
+
Delete a story and attempt to cancel the background job if it's still running.
|
| 83 |
+
\"\"\"
|
| 84 |
+
stmt = select(WorkspaceStory).where(
|
| 85 |
+
WorkspaceStory.id == story_id,
|
| 86 |
+
WorkspaceStory.workspace_id == current_user.workspace_id
|
| 87 |
+
)
|
| 88 |
+
res = await db.execute(stmt)
|
| 89 |
+
story = res.scalar_one_or_none()
|
| 90 |
+
|
| 91 |
+
if not story:
|
| 92 |
+
raise HTTPException(status_code=404, detail="Story not found")
|
| 93 |
+
|
| 94 |
+
# Attempt to abort Arq job if not finished
|
| 95 |
+
if story.status in [StoryStatus.PENDING, StoryStatus.PROCESSING] and story.arq_job_id:
|
| 96 |
+
try:
|
| 97 |
+
from arq.jobs import Job
|
| 98 |
+
job = Job(story.arq_job_id, arq_pool, _queue_name="arq:heavy")
|
| 99 |
+
await job.abort()
|
| 100 |
+
print(f"Aborted Arq job {story.arq_job_id} for story {story_id}")
|
| 101 |
+
except Exception as e:
|
| 102 |
+
print(f"Failed to abort Arq job: {e}")
|
| 103 |
+
|
| 104 |
+
await db.delete(story)
|
| 105 |
+
await db.commit()
|
| 106 |
+
|
| 107 |
+
return {"status": "success", "message": "Story deleted and task cancelled if active."}
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
+
# Replace from @router.post("/stories/generate/") to the end
|
| 111 |
+
start_line = -1
|
| 112 |
+
for i, line in enumerate(lines):
|
| 113 |
+
if '@router.post("/stories/generate/")' in line:
|
| 114 |
+
start_line = i
|
| 115 |
+
break
|
| 116 |
+
|
| 117 |
+
if start_line != -1:
|
| 118 |
+
lines = lines[:start_line]
|
| 119 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 120 |
+
f.writelines(lines)
|
| 121 |
+
f.write(new_content)
|
| 122 |
+
print("Successfully updated api/v1/nexus.py")
|
| 123 |
+
else:
|
| 124 |
+
print("Could not find start line")
|
scratch/update_nexushub_ui.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
file_path = r'c:\Users\dushy\OneDrive\Documents\_Snowball\Projects\Hackathon\frontend\packages\shared\src\components\NexusHub.tsx'
|
| 4 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 5 |
+
lines = f.readlines()
|
| 6 |
+
|
| 7 |
+
new_lines = []
|
| 8 |
+
for line in lines:
|
| 9 |
+
if '<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray900 }}>{s.title}</div>' in line:
|
| 10 |
+
indent = line[:line.find('<')]
|
| 11 |
+
new_lines.append(f'{indent}<div style={{{{ flex: 1 }}}}>\n')
|
| 12 |
+
new_lines.append(line)
|
| 13 |
+
new_lines.append(f'{indent}</div>\n')
|
| 14 |
+
new_lines.append(f'{indent}<button\n')
|
| 15 |
+
new_lines.append(f'{indent} onClick={{(e) => {{{{ \n')
|
| 16 |
+
new_lines.append(f'{indent} e.stopPropagation();\n')
|
| 17 |
+
new_lines.append(f'{indent} if (window.confirm("Delete this story? If it is still generating, the task will be cancelled.")) {{{{ \n')
|
| 18 |
+
new_lines.append(f'{indent} deleteStory(s.id);\n')
|
| 19 |
+
new_lines.append(f'{indent} }}}}\n')
|
| 20 |
+
new_lines.append(f'{indent} }}}}\n')
|
| 21 |
+
new_lines.append(f'{indent} style={{{{ \n')
|
| 22 |
+
new_lines.append(f'{indent} background: \'none\', border: \'none\', color: COLORS.gray300, cursor: \'pointer\',\n')
|
| 23 |
+
new_lines.append(f'{indent} padding: 4, borderRadius: 8, transition: \'all 0.2s\'\n')
|
| 24 |
+
new_lines.append(f'{indent} }}}}\n')
|
| 25 |
+
new_lines.append(f'{indent} onMouseOver={{(e) => {{{{ \n')
|
| 26 |
+
new_lines.append(f'{indent} e.currentTarget.style.color = \'#F43F5E\';\n')
|
| 27 |
+
new_lines.append(f'{indent} e.currentTarget.style.background = \'#F43F5E10\';\n')
|
| 28 |
+
new_lines.append(f'{indent} }}}}\n')
|
| 29 |
+
new_lines.append(f'{indent} onMouseOut={{(e) => {{{{ \n')
|
| 30 |
+
new_lines.append(f'{indent} e.currentTarget.style.color = COLORS.gray300;\n')
|
| 31 |
+
new_lines.append(f'{indent} e.currentTarget.style.background = \'none\';\n')
|
| 32 |
+
new_lines.append(f'{indent} }}}}\n')
|
| 33 |
+
new_lines.append(f'{indent}>\n')
|
| 34 |
+
new_lines.append(f'{indent} <X size={{14}} />\n')
|
| 35 |
+
new_lines.append(f'{indent}</button>\n')
|
| 36 |
+
else:
|
| 37 |
+
new_lines.append(line)
|
| 38 |
+
|
| 39 |
+
content = ''.join(new_lines)
|
| 40 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 41 |
+
f.write(content)
|
| 42 |
+
print("Updated NexusHub.tsx successfully")
|
tasks/stories.py
CHANGED
|
@@ -48,12 +48,20 @@ async def generate_workspace_story_task(ctx, story_id: UUID, user_id: UUID, work
|
|
| 48 |
"timestamp": datetime.utcnow().isoformat()
|
| 49 |
}
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# 3. Use LLM to generate the narrative (Cohesive Story)
|
| 52 |
# Custom prompt based on role
|
| 53 |
role_flavor = "executive summary and strategic alignment" if role in ["customer_admin", "3sc_admin"] else "operational efficiency and tactical throughput"
|
|
|
|
|
|
|
|
|
|
| 54 |
prompt = f"""
|
| 55 |
Generate a cohesive workspace story for a {role}.
|
| 56 |
-
Focus on {role_flavor}.
|
| 57 |
Context: {json.dumps(context_data)}
|
| 58 |
|
| 59 |
The story should be a structured narrative with:
|
|
|
|
| 48 |
"timestamp": datetime.utcnow().isoformat()
|
| 49 |
}
|
| 50 |
|
| 51 |
+
story_stmt = select(WorkspaceStory).where(WorkspaceStory.id == story_id)
|
| 52 |
+
story_res = await db.execute(story_stmt)
|
| 53 |
+
story_obj = story_res.scalar_one_or_none()
|
| 54 |
+
custom_spec = story_obj.custom_instructions if story_obj else None
|
| 55 |
+
|
| 56 |
# 3. Use LLM to generate the narrative (Cohesive Story)
|
| 57 |
# Custom prompt based on role
|
| 58 |
role_flavor = "executive summary and strategic alignment" if role in ["customer_admin", "3sc_admin"] else "operational efficiency and tactical throughput"
|
| 59 |
+
|
| 60 |
+
custom_flavor = f"\nUser Specific Instructions: {custom_spec}\n" if custom_spec else ""
|
| 61 |
+
|
| 62 |
prompt = f"""
|
| 63 |
Generate a cohesive workspace story for a {role}.
|
| 64 |
+
Focus on {role_flavor}.{custom_flavor}
|
| 65 |
Context: {json.dumps(context_data)}
|
| 66 |
|
| 67 |
The story should be a structured narrative with:
|