Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
37c3bcb
1
Parent(s): 09fa229
backend stabilization
Browse files- agents/workflow.py +28 -0
- alembic/versions/6ae467692b79_add_content_hash_to_tickets_and_kb.py +36 -0
- api/v1/kb.py +100 -31
- api/v1/tickets.py +31 -1
- core/tasks.py +27 -0
- frontend/apps/internal/src/components/KnowledgeBase.module.css +95 -1
- frontend/apps/internal/src/components/KnowledgeBase.tsx +42 -1
- models/kb_article.py +1 -0
- models/ticket.py +1 -0
agents/workflow.py
CHANGED
|
@@ -111,6 +111,34 @@ async def run_ai_workflow(ctx: Any, ticket_id: Any, workspace_id: Any = None, **
|
|
| 111 |
ticket_desc = ticket.description
|
| 112 |
ticket_cat = ticket.category
|
| 113 |
ticket_prio = ticket.priority
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
app = await get_workflow_app()
|
| 116 |
|
|
|
|
| 111 |
ticket_desc = ticket.description
|
| 112 |
ticket_cat = ticket.category
|
| 113 |
ticket_prio = ticket.priority
|
| 114 |
+
|
| 115 |
+
# --- PHASE 0: Hash & Fast-Path Deduplication (GAP-DEDUP) ---
|
| 116 |
+
if not ticket.content_hash:
|
| 117 |
+
import hashlib
|
| 118 |
+
payload_str = f"{ticket_title.strip()}|{ticket_desc.strip()}"
|
| 119 |
+
ticket.content_hash = hashlib.sha256(payload_str.encode('utf-8')).hexdigest()
|
| 120 |
+
db.add(ticket)
|
| 121 |
+
await db.commit()
|
| 122 |
+
|
| 123 |
+
# Check for existing UNRESOLVED duplicate in this workspace
|
| 124 |
+
dup_stmt = select(Ticket.id).where(
|
| 125 |
+
Ticket.workspace_id == ws_id,
|
| 126 |
+
Ticket.content_hash == ticket.content_hash,
|
| 127 |
+
Ticket.id != t_id,
|
| 128 |
+
Ticket.status.in_([TicketStatus.OPEN, TicketStatus.ACKNOWLEDGED, TicketStatus.IN_PROGRESS]),
|
| 129 |
+
Ticket.deleted_at.is_(None)
|
| 130 |
+
).limit(1)
|
| 131 |
+
dup_res = await db.execute(dup_stmt)
|
| 132 |
+
fast_dup = dup_res.scalar()
|
| 133 |
+
|
| 134 |
+
if fast_dup and not kwargs.get("force_skip_duplication"):
|
| 135 |
+
logger.warning(f"Workflow Fast-Dedup: Ticket {t_id} is identical to {fast_dup} (AUTO-CLOSING)")
|
| 136 |
+
ticket.status = TicketStatus.CLOSED
|
| 137 |
+
ticket.duplicate_of_id = fast_dup
|
| 138 |
+
ticket.resolved_at = datetime.utcnow()
|
| 139 |
+
ticket.resolution_text = f"Automated Workflow: Marked as fast-duplicate of #{str(fast_dup)[:8]}."
|
| 140 |
+
await db.commit()
|
| 141 |
+
return {"is_duplicate": True, "duplicate_of_id": fast_dup}
|
| 142 |
|
| 143 |
app = await get_workflow_app()
|
| 144 |
|
alembic/versions/6ae467692b79_add_content_hash_to_tickets_and_kb.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""add_content_hash_to_tickets_and_kb
|
| 2 |
+
|
| 3 |
+
Revision ID: 6ae467692b79
|
| 4 |
+
Revises: 9f3a6a7bdb00
|
| 5 |
+
Create Date: 2026-04-25 16:10:43.372313
|
| 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 = '6ae467692b79'
|
| 16 |
+
down_revision: Union[str, None] = '9f3a6a7bdb00'
|
| 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('kb_articles', sa.Column('content_hash', sa.String(length=64), nullable=True))
|
| 24 |
+
op.create_index(op.f('ix_kb_articles_content_hash'), 'kb_articles', ['content_hash'], unique=False)
|
| 25 |
+
op.add_column('tickets', sa.Column('content_hash', sa.String(length=64), nullable=True))
|
| 26 |
+
op.create_index(op.f('ix_tickets_content_hash'), 'tickets', ['content_hash'], unique=False)
|
| 27 |
+
# ### end Alembic commands ###
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def downgrade() -> None:
|
| 31 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 32 |
+
op.drop_index(op.f('ix_tickets_content_hash'), table_name='tickets')
|
| 33 |
+
op.drop_column('tickets', 'content_hash')
|
| 34 |
+
op.drop_index(op.f('ix_kb_articles_content_hash'), table_name='kb_articles')
|
| 35 |
+
op.drop_column('kb_articles', 'content_hash')
|
| 36 |
+
# ### end Alembic commands ###
|
api/v1/kb.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import asyncio
|
|
|
|
| 2 |
import time
|
| 3 |
from datetime import datetime
|
| 4 |
from typing import Any, List, Optional
|
|
@@ -960,41 +961,109 @@ async def ingest_kb_files(
|
|
| 960 |
raise HTTPException(status_code=400, detail="No files provided for ingestion.")
|
| 961 |
|
| 962 |
queued_count = 0
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 993 |
|
| 994 |
return {
|
| 995 |
"status": "success",
|
| 996 |
"queued": queued_count,
|
| 997 |
-
"
|
|
|
|
|
|
|
| 998 |
}
|
| 999 |
|
| 1000 |
|
|
|
|
| 1 |
import asyncio
|
| 2 |
+
import hashlib
|
| 3 |
import time
|
| 4 |
from datetime import datetime
|
| 5 |
from typing import Any, List, Optional
|
|
|
|
| 961 |
raise HTTPException(status_code=400, detail="No files provided for ingestion.")
|
| 962 |
|
| 963 |
queued_count = 0
|
| 964 |
+
created_drafts = []
|
| 965 |
+
|
| 966 |
+
from core.tasks import enqueue_task
|
| 967 |
+
from core.cache import invalidate_cache
|
| 968 |
+
|
| 969 |
+
async with async_session_factory() as db:
|
| 970 |
+
for file in files:
|
| 971 |
+
filename_lower = file.filename.lower()
|
| 972 |
+
# Support basic text-based formats for immediate parsing
|
| 973 |
+
if not filename_lower.endswith(('.txt', '.md', '.pdf', '.docx')):
|
| 974 |
+
logger.warning(f"Ingest skip: {file.filename} (Unsupported extension)")
|
| 975 |
+
continue
|
| 976 |
+
|
| 977 |
+
contents = await file.read()
|
| 978 |
+
# 1MB Hard limit for background ingestion
|
| 979 |
+
max_size = 1024 * 1024
|
| 980 |
+
if len(contents) > max_size:
|
| 981 |
+
logger.warning(f"Ingest skip: {file.filename} (Too large: {len(contents)} bytes)")
|
| 982 |
+
continue
|
| 983 |
+
|
| 984 |
+
try:
|
| 985 |
+
# OPTIMIZATION: Immediate Draft for small text/md files (< 20KB)
|
| 986 |
+
if len(contents) < 20 * 1024 and filename_lower.endswith(('.txt', '.md')):
|
| 987 |
+
text = contents.decode('utf-8', errors='ignore')
|
| 988 |
+
|
| 989 |
+
# Extract title from first line or filename
|
| 990 |
+
lines = [l.strip() for l in text.split('\n') if l.strip()]
|
| 991 |
+
title = lines[0].lstrip('# ').strip() if lines else file.filename
|
| 992 |
+
if len(title) > 100: title = title[:97] + "..."
|
| 993 |
+
|
| 994 |
+
# Deduplication via Content Hash (GAP FIX)
|
| 995 |
+
payload_str = f"{title.strip()}|{text.strip()}"
|
| 996 |
+
c_hash = hashlib.sha256(payload_str.encode('utf-8')).hexdigest()
|
| 997 |
+
|
| 998 |
+
dup_stmt = select(KBArticle).where(
|
| 999 |
+
KBArticle.workspace_id == current_user.workspace_id,
|
| 1000 |
+
KBArticle.content_hash == c_hash,
|
| 1001 |
+
KBArticle.deleted_at.is_(None)
|
| 1002 |
+
)
|
| 1003 |
+
dup_res = await db.execute(dup_stmt)
|
| 1004 |
+
existing_dup = dup_res.scalar_one_or_none()
|
| 1005 |
+
|
| 1006 |
+
if existing_dup:
|
| 1007 |
+
logger.info(f"Ingest DUPLICATE (Hash): Skipping {file.filename}, already exists as {existing_dup.id}")
|
| 1008 |
+
created_drafts.append({
|
| 1009 |
+
"id": str(existing_dup.id),
|
| 1010 |
+
"title": existing_dup.title,
|
| 1011 |
+
"status": "DRAFT",
|
| 1012 |
+
"immediate": True,
|
| 1013 |
+
"duplicate": True
|
| 1014 |
+
})
|
| 1015 |
+
continue
|
| 1016 |
+
|
| 1017 |
+
new_article = KBArticle(
|
| 1018 |
+
workspace_id=current_user.workspace_id,
|
| 1019 |
+
author_id=current_user.id,
|
| 1020 |
+
title=title,
|
| 1021 |
+
content=text,
|
| 1022 |
+
category="Imported",
|
| 1023 |
+
is_published=False, # Always Draft
|
| 1024 |
+
content_hash=c_hash
|
| 1025 |
+
)
|
| 1026 |
+
db.add(new_article)
|
| 1027 |
+
await db.flush() # Get ID
|
| 1028 |
+
|
| 1029 |
+
# Trigger indexing immediately (Heavy worker handles embedding/chunking)
|
| 1030 |
+
await enqueue_task(arq_pool, "index_kb_article", new_article.id)
|
| 1031 |
+
|
| 1032 |
+
created_drafts.append({
|
| 1033 |
+
"id": str(new_article.id),
|
| 1034 |
+
"title": new_article.title,
|
| 1035 |
+
"status": "DRAFT",
|
| 1036 |
+
"immediate": True
|
| 1037 |
+
})
|
| 1038 |
+
logger.info(f"Ingest IMMEDIATE: {file.filename} -> {new_article.id}")
|
| 1039 |
+
else:
|
| 1040 |
+
# HEAVY PATH: Enqueue for AI transformation (LLM structures the doc)
|
| 1041 |
+
text = contents.decode('utf-8', errors='ignore')
|
| 1042 |
+
await enqueue_task(
|
| 1043 |
+
arq_pool,
|
| 1044 |
+
"process_kb_import_task",
|
| 1045 |
+
current_user.workspace_id,
|
| 1046 |
+
current_user.id,
|
| 1047 |
+
text,
|
| 1048 |
+
file.filename
|
| 1049 |
+
)
|
| 1050 |
+
queued_count += 1
|
| 1051 |
+
logger.info(f"Ingest enqueued: {file.filename} (Workspace: {current_user.workspace_id})")
|
| 1052 |
+
except Exception as e:
|
| 1053 |
+
logger.error(f"Ingest processing error for {file.filename}: {e}")
|
| 1054 |
+
continue
|
| 1055 |
+
|
| 1056 |
+
await db.commit()
|
| 1057 |
+
|
| 1058 |
+
# Invalidate KB list cache for this workspace to show new drafts
|
| 1059 |
+
await invalidate_cache(f"kb:list:{current_user.workspace_id}*")
|
| 1060 |
|
| 1061 |
return {
|
| 1062 |
"status": "success",
|
| 1063 |
"queued": queued_count,
|
| 1064 |
+
"immediate_count": len(created_drafts),
|
| 1065 |
+
"created_drafts": created_drafts,
|
| 1066 |
+
"message": f"Successfully processed {len(created_drafts) + queued_count} files. {len(created_drafts)} drafts created immediately."
|
| 1067 |
}
|
| 1068 |
|
| 1069 |
|
api/v1/tickets.py
CHANGED
|
@@ -4,6 +4,7 @@ Ticket endpoints: CRUD, status transitions, and assignments.
|
|
| 4 |
|
| 5 |
from datetime import datetime, timedelta
|
| 6 |
import asyncio
|
|
|
|
| 7 |
import time
|
| 8 |
import uuid
|
| 9 |
from uuid import UUID
|
|
@@ -165,6 +166,34 @@ async def create_ticket(
|
|
| 165 |
if not result.scalar_one_or_none():
|
| 166 |
raise HTTPException(status_code=400, detail="Project not found")
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
# 1. Calculate SLA: Use EscalationRules if present, else 2 days
|
| 169 |
ticket_priority = payload.priority # Preserve None for AUTO
|
| 170 |
sla_deadline = payload.sla_deadline
|
|
@@ -200,7 +229,8 @@ async def create_ticket(
|
|
| 200 |
category=payload.category,
|
| 201 |
created_by=current_user.id,
|
| 202 |
status=TicketStatus.OPEN,
|
| 203 |
-
sla_deadline=sla_deadline
|
|
|
|
| 204 |
)
|
| 205 |
db.add(new_ticket)
|
| 206 |
|
|
|
|
| 4 |
|
| 5 |
from datetime import datetime, timedelta
|
| 6 |
import asyncio
|
| 7 |
+
import hashlib
|
| 8 |
import time
|
| 9 |
import uuid
|
| 10 |
from uuid import UUID
|
|
|
|
| 166 |
if not result.scalar_one_or_none():
|
| 167 |
raise HTTPException(status_code=400, detail="Project not found")
|
| 168 |
|
| 169 |
+
# 0. Deduplication via SHA-256 Hash (GAP-DEDUP)
|
| 170 |
+
payload_str = f"{payload.title.strip()}|{payload.description.strip()}"
|
| 171 |
+
c_hash = hashlib.sha256(payload_str.encode('utf-8')).hexdigest()
|
| 172 |
+
|
| 173 |
+
dup_stmt = (
|
| 174 |
+
select(Ticket)
|
| 175 |
+
.options(
|
| 176 |
+
joinedload(Ticket.creator),
|
| 177 |
+
joinedload(Ticket.assignee),
|
| 178 |
+
joinedload(Ticket.resolver),
|
| 179 |
+
joinedload(Ticket.feedback)
|
| 180 |
+
)
|
| 181 |
+
.where(
|
| 182 |
+
Ticket.workspace_id == current_user.workspace_id,
|
| 183 |
+
Ticket.content_hash == c_hash,
|
| 184 |
+
Ticket.status.in_([TicketStatus.OPEN, TicketStatus.ACKNOWLEDGED, TicketStatus.IN_PROGRESS]),
|
| 185 |
+
Ticket.deleted_at.is_(None)
|
| 186 |
+
)
|
| 187 |
+
.limit(1)
|
| 188 |
+
)
|
| 189 |
+
dup_res = await db.execute(dup_stmt)
|
| 190 |
+
existing_dup = dup_res.scalar_one_or_none()
|
| 191 |
+
|
| 192 |
+
if existing_dup:
|
| 193 |
+
logger.info(f"Ticket DUPLICATE detected (Hash): {existing_dup.id} in workspace {current_user.workspace_id}")
|
| 194 |
+
# Return existing but ensure ID is in results for frontend tracking if needed
|
| 195 |
+
return await sanitize_ticket_response(existing_dup, current_user, db)
|
| 196 |
+
|
| 197 |
# 1. Calculate SLA: Use EscalationRules if present, else 2 days
|
| 198 |
ticket_priority = payload.priority # Preserve None for AUTO
|
| 199 |
sla_deadline = payload.sla_deadline
|
|
|
|
| 229 |
category=payload.category,
|
| 230 |
created_by=current_user.id,
|
| 231 |
status=TicketStatus.OPEN,
|
| 232 |
+
sla_deadline=sla_deadline,
|
| 233 |
+
content_hash=c_hash
|
| 234 |
)
|
| 235 |
db.add(new_ticket)
|
| 236 |
|
core/tasks.py
CHANGED
|
@@ -580,6 +580,33 @@ async def index_kb_article(ctx, article_id: UUID, **kwargs):
|
|
| 580 |
logger.error(f"Unified KB Indexing failed: Article {article_id} not found.")
|
| 581 |
return
|
| 582 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
# --- 2. Multi-Model Initialization ---
|
| 584 |
text_model = get_text_embeddings()
|
| 585 |
llm = get_llm()
|
|
|
|
| 580 |
logger.error(f"Unified KB Indexing failed: Article {article_id} not found.")
|
| 581 |
return
|
| 582 |
|
| 583 |
+
# --- PHASE 0: Hash & Fast-Path Deduplication (GAP-DEDUP) ---
|
| 584 |
+
if not article.content_hash:
|
| 585 |
+
import hashlib
|
| 586 |
+
payload_str = f"{article.title.strip()}|{article.content.strip()}"
|
| 587 |
+
article.content_hash = hashlib.sha256(payload_str.encode('utf-8')).hexdigest()
|
| 588 |
+
db.add(article)
|
| 589 |
+
await db.commit()
|
| 590 |
+
|
| 591 |
+
# Fast-path check for identical content in this workspace
|
| 592 |
+
dup_stmt = select(KBArticle.id).where(
|
| 593 |
+
KBArticle.workspace_id == article.workspace_id,
|
| 594 |
+
KBArticle.content_hash == article.content_hash,
|
| 595 |
+
KBArticle.id != article.id,
|
| 596 |
+
KBArticle.deleted_at.is_(None)
|
| 597 |
+
).limit(1)
|
| 598 |
+
dup_res = await db.execute(dup_stmt)
|
| 599 |
+
fast_dup = dup_res.scalar()
|
| 600 |
+
|
| 601 |
+
if fast_dup and not article.force_original:
|
| 602 |
+
logger.info(f"PHASE 0 [Fast-Dedup] Identical match for {article_id} -> {fast_dup}")
|
| 603 |
+
# Update with lock
|
| 604 |
+
article.duplicate_of_id = fast_dup
|
| 605 |
+
article.is_published = False
|
| 606 |
+
db.add(article)
|
| 607 |
+
await db.commit()
|
| 608 |
+
return # Fast exit
|
| 609 |
+
|
| 610 |
# --- 2. Multi-Model Initialization ---
|
| 611 |
text_model = get_text_embeddings()
|
| 612 |
llm = get_llm()
|
frontend/apps/internal/src/components/KnowledgeBase.module.css
CHANGED
|
@@ -240,6 +240,14 @@
|
|
| 240 |
|
| 241 |
/* Articles Grid */
|
| 242 |
.contentArea {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
flex: 1;
|
| 244 |
display: flex;
|
| 245 |
flex-direction: column;
|
|
@@ -797,7 +805,93 @@
|
|
| 797 |
}
|
| 798 |
}
|
| 799 |
|
| 800 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
margin: 32px 0;
|
| 802 |
background: #F8FAFC;
|
| 803 |
padding: 32px;
|
|
|
|
| 240 |
|
| 241 |
/* Articles Grid */
|
| 242 |
.contentArea {
|
| 243 |
+
flex: 1;
|
| 244 |
+
display: flex;
|
| 245 |
+
flex-direction: row;
|
| 246 |
+
gap: 32px;
|
| 247 |
+
overflow: visible;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
.mainLibrary {
|
| 251 |
flex: 1;
|
| 252 |
display: flex;
|
| 253 |
flex-direction: column;
|
|
|
|
| 805 |
}
|
| 806 |
}
|
| 807 |
|
| 808 |
+
/* Draft Sidebar */
|
| 809 |
+
.draftSidebar {
|
| 810 |
+
width: 280px;
|
| 811 |
+
background: rgba(255, 255, 255, 0.4);
|
| 812 |
+
backdrop-filter: blur(8px);
|
| 813 |
+
border: 1px solid var(--border-subtle);
|
| 814 |
+
border-radius: var(--radius-lg);
|
| 815 |
+
display: flex;
|
| 816 |
+
flex-direction: column;
|
| 817 |
+
max-height: calc(100vh - 350px);
|
| 818 |
+
position: sticky;
|
| 819 |
+
top: 40px;
|
| 820 |
+
overflow: hidden;
|
| 821 |
+
}
|
| 822 |
+
|
| 823 |
+
.sidebarHeader {
|
| 824 |
+
padding: 20px;
|
| 825 |
+
border-bottom: 1px solid var(--border-subtle);
|
| 826 |
+
display: flex;
|
| 827 |
+
align-items: center;
|
| 828 |
+
gap: 10px;
|
| 829 |
+
}
|
| 830 |
+
|
| 831 |
+
.sidebarHeader h3 {
|
| 832 |
+
font-size: 11px;
|
| 833 |
+
font-weight: 900;
|
| 834 |
+
color: var(--text-main);
|
| 835 |
+
letter-spacing: 0.1em;
|
| 836 |
+
margin: 0;
|
| 837 |
+
flex: 1;
|
| 838 |
+
}
|
| 839 |
+
|
| 840 |
+
.clearDrafts {
|
| 841 |
+
background: none;
|
| 842 |
+
border: none;
|
| 843 |
+
font-size: 9px;
|
| 844 |
+
font-weight: 800;
|
| 845 |
+
color: var(--primary);
|
| 846 |
+
cursor: pointer;
|
| 847 |
+
opacity: 0.7;
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
.clearDrafts:hover {
|
| 851 |
+
opacity: 1;
|
| 852 |
+
}
|
| 853 |
+
|
| 854 |
+
.draftList {
|
| 855 |
+
overflow-y: auto;
|
| 856 |
+
padding: 12px;
|
| 857 |
+
display: flex;
|
| 858 |
+
flex-direction: column;
|
| 859 |
+
gap: 12px;
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
+
.draftItem {
|
| 863 |
+
background: white;
|
| 864 |
+
border: 1px solid var(--border-subtle);
|
| 865 |
+
padding: 16px;
|
| 866 |
+
border-radius: 12px;
|
| 867 |
+
cursor: pointer;
|
| 868 |
+
transition: all 0.2s;
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
+
.draftItem:hover {
|
| 872 |
+
border-color: var(--primary);
|
| 873 |
+
transform: translateX(4px);
|
| 874 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
.draftTitle {
|
| 878 |
+
font-size: 13px;
|
| 879 |
+
font-weight: 700;
|
| 880 |
+
color: var(--text-main);
|
| 881 |
+
margin-bottom: 6px;
|
| 882 |
+
white-space: nowrap;
|
| 883 |
+
overflow: hidden;
|
| 884 |
+
text-overflow: ellipsis;
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
.draftMeta {
|
| 888 |
+
display: flex;
|
| 889 |
+
align-items: center;
|
| 890 |
+
gap: 6px;
|
| 891 |
+
font-size: 9px;
|
| 892 |
+
font-weight: 800;
|
| 893 |
+
color: #10B981;
|
| 894 |
+
}
|
| 895 |
margin: 32px 0;
|
| 896 |
background: #F8FAFC;
|
| 897 |
padding: 32px;
|
frontend/apps/internal/src/components/KnowledgeBase.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import ReactMarkdown from 'react-markdown';
|
|
| 3 |
import remarkGfm from 'remark-gfm';
|
| 4 |
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
| 5 |
import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
| 6 |
-
import { Search, Plus, X, Trash2, Edit3, ShieldCheck, Zap, Info, Radio, ChevronLeft, ChevronRight, Eye, Send, Lock, Globe, Sparkles, UploadCloud, History, RotateCcw } from 'lucide-react';
|
| 7 |
import { motion, AnimatePresence } from 'framer-motion';
|
| 8 |
import { api, useAuth, NexusMermaid } from '@nexus/shared';
|
| 9 |
import styles from './KnowledgeBase.module.css';
|
|
@@ -71,6 +71,7 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ workspaceId }) =>
|
|
| 71 |
// Search State
|
| 72 |
const [searchInput, setSearchInput] = useState('');
|
| 73 |
const [activeQuery, setActiveQuery] = useState('');
|
|
|
|
| 74 |
const [selectedCategory, setSelectedCategory] = useState('All');
|
| 75 |
|
| 76 |
// Pagination State
|
|
@@ -298,6 +299,13 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ workspaceId }) =>
|
|
| 298 |
headers: { 'Content-Type': 'multipart/form-data' }
|
| 299 |
});
|
| 300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
alert(resp.data.message || `${files.length} documents queued for neural ingestion.`);
|
| 302 |
|
| 303 |
// Auto-refresh library after a small delay to show processing articles
|
|
@@ -561,6 +569,38 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ workspaceId }) =>
|
|
| 561 |
)}
|
| 562 |
|
| 563 |
<div className={styles.contentArea}>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 564 |
<AnimatePresence mode="wait">
|
| 565 |
{activeTab === 'growth' ? (
|
| 566 |
<motion.div
|
|
@@ -787,6 +827,7 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ workspaceId }) =>
|
|
| 787 |
</div>
|
| 788 |
)}
|
| 789 |
</div>
|
|
|
|
| 790 |
|
| 791 |
{/* STRATEGIC DOSSIER DRAWER */}
|
| 792 |
<AnimatePresence>
|
|
|
|
| 3 |
import remarkGfm from 'remark-gfm';
|
| 4 |
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
| 5 |
import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
| 6 |
+
import { Search, Plus, X, Trash2, Edit3, ShieldCheck, Zap, Info, Radio, ChevronLeft, ChevronRight, Eye, Send, Lock, Globe, Sparkles, UploadCloud, History, RotateCcw, Clock } from 'lucide-react';
|
| 7 |
import { motion, AnimatePresence } from 'framer-motion';
|
| 8 |
import { api, useAuth, NexusMermaid } from '@nexus/shared';
|
| 9 |
import styles from './KnowledgeBase.module.css';
|
|
|
|
| 71 |
// Search State
|
| 72 |
const [searchInput, setSearchInput] = useState('');
|
| 73 |
const [activeQuery, setActiveQuery] = useState('');
|
| 74 |
+
const [createdDrafts, setCreatedDrafts] = useState<any[]>([]);
|
| 75 |
const [selectedCategory, setSelectedCategory] = useState('All');
|
| 76 |
|
| 77 |
// Pagination State
|
|
|
|
| 299 |
headers: { 'Content-Type': 'multipart/form-data' }
|
| 300 |
});
|
| 301 |
|
| 302 |
+
|
| 303 |
+
if (resp.data.created_drafts && resp.data.created_drafts.length > 0) {
|
| 304 |
+
setCreatedDrafts(prev => [...resp.data.created_drafts, ...prev]);
|
| 305 |
+
// Also add them to the main articles list so they appear in the grid
|
| 306 |
+
setArticles(prev => [...resp.data.created_drafts, ...prev]);
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
alert(resp.data.message || `${files.length} documents queued for neural ingestion.`);
|
| 310 |
|
| 311 |
// Auto-refresh library after a small delay to show processing articles
|
|
|
|
| 569 |
)}
|
| 570 |
|
| 571 |
<div className={styles.contentArea}>
|
| 572 |
+
<AnimatePresence>
|
| 573 |
+
{createdDrafts.length > 0 && activeTab === 'library' && (
|
| 574 |
+
<motion.aside
|
| 575 |
+
className={styles.draftSidebar}
|
| 576 |
+
initial={{ opacity: 0, x: -50 }}
|
| 577 |
+
animate={{ opacity: 1, x: 0 }}
|
| 578 |
+
exit={{ opacity: 0, x: -50 }}
|
| 579 |
+
>
|
| 580 |
+
<div className={styles.sidebarHeader}>
|
| 581 |
+
<Clock size={16} />
|
| 582 |
+
<h3>RECENT DRAFTS</h3>
|
| 583 |
+
<button className={styles.clearDrafts} onClick={() => setCreatedDrafts([])}>CLEAR</button>
|
| 584 |
+
</div>
|
| 585 |
+
<div className={styles.draftList}>
|
| 586 |
+
{createdDrafts.map(draft => (
|
| 587 |
+
<div
|
| 588 |
+
key={draft.id}
|
| 589 |
+
className={styles.draftItem}
|
| 590 |
+
onClick={() => openDossier(draft as any)}
|
| 591 |
+
>
|
| 592 |
+
<div className={styles.draftTitle}>{draft.title}</div>
|
| 593 |
+
<div className={styles.draftMeta}>
|
| 594 |
+
<Zap size={10} /> READY FOR REVIEW
|
| 595 |
+
</div>
|
| 596 |
+
</div>
|
| 597 |
+
))}
|
| 598 |
+
</div>
|
| 599 |
+
</motion.aside>
|
| 600 |
+
)}
|
| 601 |
+
</AnimatePresence>
|
| 602 |
+
|
| 603 |
+
<div className={styles.mainLibrary}>
|
| 604 |
<AnimatePresence mode="wait">
|
| 605 |
{activeTab === 'growth' ? (
|
| 606 |
<motion.div
|
|
|
|
| 827 |
</div>
|
| 828 |
)}
|
| 829 |
</div>
|
| 830 |
+
</div>
|
| 831 |
|
| 832 |
{/* STRATEGIC DOSSIER DRAWER */}
|
| 833 |
<AnimatePresence>
|
models/kb_article.py
CHANGED
|
@@ -22,6 +22,7 @@ class KBArticle(Base, PrimaryKeyMixin, TimestampMixin, SoftDeleteMixin):
|
|
| 22 |
summary = Column(Text, nullable=True)
|
| 23 |
duplicate_of_id = Column(UUID(as_uuid=True), ForeignKey("kb_articles.id"), nullable=True, index=True)
|
| 24 |
force_original = Column(Boolean, default=False, index=True)
|
|
|
|
| 25 |
|
| 26 |
# --- Discovery Telemetry ---
|
| 27 |
view_count = Column(Integer, default=0, nullable=False)
|
|
|
|
| 22 |
summary = Column(Text, nullable=True)
|
| 23 |
duplicate_of_id = Column(UUID(as_uuid=True), ForeignKey("kb_articles.id"), nullable=True, index=True)
|
| 24 |
force_original = Column(Boolean, default=False, index=True)
|
| 25 |
+
content_hash = Column(String(64), nullable=True, index=True)
|
| 26 |
|
| 27 |
# --- Discovery Telemetry ---
|
| 28 |
view_count = Column(Integer, default=0, nullable=False)
|
models/ticket.py
CHANGED
|
@@ -63,6 +63,7 @@ class Ticket(Base, PrimaryKeyMixin, TimestampMixin, SoftDeleteMixin):
|
|
| 63 |
ai_metadata = Column(JSONB, default={})
|
| 64 |
is_escalated = Column(DateTime(timezone=False), nullable=True) # Tracks if SLA notification was sent
|
| 65 |
duplicate_of_id = Column(UUID(as_uuid=True), ForeignKey("tickets.id"), nullable=True)
|
|
|
|
| 66 |
|
| 67 |
# --- Search Optimization ---
|
| 68 |
# 1. Computed TSVector for GIN search (Keyword Engine)
|
|
|
|
| 63 |
ai_metadata = Column(JSONB, default={})
|
| 64 |
is_escalated = Column(DateTime(timezone=False), nullable=True) # Tracks if SLA notification was sent
|
| 65 |
duplicate_of_id = Column(UUID(as_uuid=True), ForeignKey("tickets.id"), nullable=True)
|
| 66 |
+
content_hash = Column(String(64), nullable=True, index=True)
|
| 67 |
|
| 68 |
# --- Search Optimization ---
|
| 69 |
# 1. Computed TSVector for GIN search (Keyword Engine)
|