Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit Β·
dfcbb7c
1
Parent(s): 951cf3b
backend stabilization
Browse files- api/v1/dashboard.py +36 -11
- api/v1/kb.py +62 -2
- api/v1/reports.py +70 -8
- frontend/apps/customer/package.json +1 -0
- frontend/apps/customer/src/components/KnowledgeBase.tsx +89 -5
- frontend/apps/internal/src/components/KnowledgeBase.module.css +80 -0
- frontend/apps/internal/src/components/KnowledgeBase.tsx +52 -8
- frontend/apps/internal/src/components/TopBar.module.css +46 -10
- frontend/apps/internal/src/components/TopBar.tsx +32 -18
- frontend/package-lock.json +6 -7
- schemas/kb.py +4 -0
- scripts/backfill_kb_summaries.py +58 -0
api/v1/dashboard.py
CHANGED
|
@@ -34,12 +34,26 @@ async def get_dashboard_stats(
|
|
| 34 |
is_super_admin = (current_user.role == UserRole.SC_ADMIN)
|
| 35 |
is_global = False
|
| 36 |
|
| 37 |
-
if
|
| 38 |
-
if workspace_id == "all":
|
| 39 |
is_global = True
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
now = datetime.utcnow()
|
| 44 |
|
| 45 |
# 1. Basic Status Counts (Optimized SQL)
|
|
@@ -192,12 +206,23 @@ async def get_agent_queue(
|
|
| 192 |
|
| 193 |
target_ws = current_user.workspace_id
|
| 194 |
is_super_admin = (current_user.role == UserRole.SC_ADMIN)
|
| 195 |
-
is_global =
|
| 196 |
-
|
| 197 |
-
if is_super_admin and workspace_id
|
| 198 |
-
|
| 199 |
-
elif
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
stmt = (
|
| 203 |
select(Ticket)
|
|
|
|
| 34 |
is_super_admin = (current_user.role == UserRole.SC_ADMIN)
|
| 35 |
is_global = False
|
| 36 |
|
| 37 |
+
if workspace_id:
|
| 38 |
+
if is_super_admin and workspace_id == "all":
|
| 39 |
is_global = True
|
| 40 |
+
else:
|
| 41 |
+
# Multi-workspace Agent/Lead Check: Ensure they are authorized for the requested workspace
|
| 42 |
+
if is_super_admin:
|
| 43 |
+
target_ws = workspace_id
|
| 44 |
+
else:
|
| 45 |
+
from models.user_workspace import UserWorkspace
|
| 46 |
+
ws_check = await db.execute(
|
| 47 |
+
select(UserWorkspace).where(
|
| 48 |
+
UserWorkspace.user_id == current_user.id,
|
| 49 |
+
UserWorkspace.workspace_id == workspace_id
|
| 50 |
+
)
|
| 51 |
+
)
|
| 52 |
+
if ws_check.scalar_one_or_none():
|
| 53 |
+
target_ws = workspace_id
|
| 54 |
+
else:
|
| 55 |
+
# Silently fallback to primary if not authorized, or raise 403
|
| 56 |
+
pass
|
| 57 |
now = datetime.utcnow()
|
| 58 |
|
| 59 |
# 1. Basic Status Counts (Optimized SQL)
|
|
|
|
| 206 |
|
| 207 |
target_ws = current_user.workspace_id
|
| 208 |
is_super_admin = (current_user.role == UserRole.SC_ADMIN)
|
| 209 |
+
is_global = False
|
| 210 |
+
|
| 211 |
+
if is_super_admin and workspace_id == "all":
|
| 212 |
+
is_global = True
|
| 213 |
+
elif workspace_id:
|
| 214 |
+
if is_super_admin:
|
| 215 |
+
target_ws = workspace_id
|
| 216 |
+
else:
|
| 217 |
+
from models.user_workspace import UserWorkspace
|
| 218 |
+
ws_check = await db.execute(
|
| 219 |
+
select(UserWorkspace).where(
|
| 220 |
+
UserWorkspace.user_id == current_user.id,
|
| 221 |
+
UserWorkspace.workspace_id == workspace_id
|
| 222 |
+
)
|
| 223 |
+
)
|
| 224 |
+
if ws_check.scalar_one_or_none():
|
| 225 |
+
target_ws = workspace_id
|
| 226 |
|
| 227 |
stmt = (
|
| 228 |
select(Ticket)
|
api/v1/kb.py
CHANGED
|
@@ -23,7 +23,7 @@ from models.attachment import Attachment
|
|
| 23 |
from core.search import chunk_text
|
| 24 |
from core.vision import extract_visual_context
|
| 25 |
from core.sync import sync_markdown_images
|
| 26 |
-
from core.cache import generate_cache_key, get_cached_search, set_cached_search
|
| 27 |
from schemas.kb import KBArticleCreate, KBArticleResponse, KBArticleUpdate, KBSearchResponse, KBBulkActionRequest, KBBulkSyncRequest
|
| 28 |
|
| 29 |
router = APIRouter()
|
|
@@ -170,6 +170,7 @@ async def execute_multimodal_search(db: AsyncSession, q: str, current_user: User
|
|
| 170 |
semantic_stmt = (
|
| 171 |
select(
|
| 172 |
KBArticle,
|
|
|
|
| 173 |
(1 - KBArticleChunk.embedding.cosine_distance(query_vector)).label("sim_score")
|
| 174 |
)
|
| 175 |
.join(KBArticleChunk, KBArticle.id == KBArticleChunk.article_id)
|
|
@@ -257,14 +258,18 @@ async def execute_multimodal_search(db: AsyncSession, q: str, current_user: User
|
|
| 257 |
def apply_fusion(list_hits, weight, score_attr):
|
| 258 |
for rank, row in enumerate(list_hits):
|
| 259 |
art = row[0]
|
|
|
|
| 260 |
# RRF formula with weights
|
| 261 |
rrf_score = weight * (1.0 / (60 + rank + 1))
|
| 262 |
|
| 263 |
if art.id not in results_map:
|
| 264 |
-
results_map[art.id] = {"obj": art, "score": rrf_score, "types": {score_attr}}
|
| 265 |
else:
|
| 266 |
results_map[art.id]["score"] += rrf_score
|
| 267 |
results_map[art.id]["types"].add(score_attr)
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
apply_fusion(hits, 0.5, "sim_score")
|
| 270 |
apply_fusion(kw_hits, 0.3, "kw_score")
|
|
@@ -287,6 +292,7 @@ async def execute_multimodal_search(db: AsyncSession, q: str, current_user: User
|
|
| 287 |
"obj": art,
|
| 288 |
"score": round(norm_score, 1),
|
| 289 |
"type": m_type,
|
|
|
|
| 290 |
"search_id": str(search_id)
|
| 291 |
}
|
| 292 |
|
|
@@ -322,6 +328,20 @@ async def search_kb_articles(
|
|
| 322 |
logger.info(f"β‘ Search Cache HIT [KB]: {q}")
|
| 323 |
return cached_res
|
| 324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
# 1. Start Original Search Branch IMMEDIATELY (Don't wait for LLM)
|
| 326 |
original_search_task = execute_multimodal_search(db, q, current_user, category, project_id)
|
| 327 |
|
|
@@ -372,11 +392,49 @@ async def search_kb_articles(
|
|
| 372 |
res_dict = KBArticleResponse.model_validate(article_obj).model_dump()
|
| 373 |
res_dict["score"] = score
|
| 374 |
res_dict["match_type"] = data.get("type", "semantic") # Safe access to avoid KeyError
|
|
|
|
| 375 |
final_results.append(res_dict)
|
| 376 |
|
| 377 |
final_results.sort(key=lambda x: float(x.get("score") or 0.0), reverse=True)
|
| 378 |
top_results = final_results[:5]
|
| 379 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
# 5. Suggestion for UI if results are still thin
|
| 381 |
suggestion = expanded_queries[0] if expanded_queries and expanded_queries[0].lower() != q.lower() else None
|
| 382 |
|
|
@@ -385,6 +443,8 @@ async def search_kb_articles(
|
|
| 385 |
|
| 386 |
res_data = {
|
| 387 |
"results": top_results,
|
|
|
|
|
|
|
| 388 |
"suggestion": suggestion if not top_results else None,
|
| 389 |
"expanded_queries": expanded_queries,
|
| 390 |
"search_time_s": round(search_time_s, 3)
|
|
|
|
| 23 |
from core.search import chunk_text
|
| 24 |
from core.vision import extract_visual_context
|
| 25 |
from core.sync import sync_markdown_images
|
| 26 |
+
from core.cache import generate_cache_key, get_cached_search, set_cached_search, SemanticCacheManager
|
| 27 |
from schemas.kb import KBArticleCreate, KBArticleResponse, KBArticleUpdate, KBSearchResponse, KBBulkActionRequest, KBBulkSyncRequest
|
| 28 |
|
| 29 |
router = APIRouter()
|
|
|
|
| 170 |
semantic_stmt = (
|
| 171 |
select(
|
| 172 |
KBArticle,
|
| 173 |
+
KBArticleChunk.content,
|
| 174 |
(1 - KBArticleChunk.embedding.cosine_distance(query_vector)).label("sim_score")
|
| 175 |
)
|
| 176 |
.join(KBArticleChunk, KBArticle.id == KBArticleChunk.article_id)
|
|
|
|
| 258 |
def apply_fusion(list_hits, weight, score_attr):
|
| 259 |
for rank, row in enumerate(list_hits):
|
| 260 |
art = row[0]
|
| 261 |
+
chunk_txt = row[1] if len(row) > 2 else None # Only semantic hits have this
|
| 262 |
# RRF formula with weights
|
| 263 |
rrf_score = weight * (1.0 / (60 + rank + 1))
|
| 264 |
|
| 265 |
if art.id not in results_map:
|
| 266 |
+
results_map[art.id] = {"obj": art, "score": rrf_score, "types": {score_attr}, "chunk": chunk_txt}
|
| 267 |
else:
|
| 268 |
results_map[art.id]["score"] += rrf_score
|
| 269 |
results_map[art.id]["types"].add(score_attr)
|
| 270 |
+
# Keep the best chunk if we hit it again via keyword
|
| 271 |
+
if not results_map[art.id]["chunk"] and chunk_txt:
|
| 272 |
+
results_map[art.id]["chunk"] = chunk_txt
|
| 273 |
|
| 274 |
apply_fusion(hits, 0.5, "sim_score")
|
| 275 |
apply_fusion(kw_hits, 0.3, "kw_score")
|
|
|
|
| 292 |
"obj": art,
|
| 293 |
"score": round(norm_score, 1),
|
| 294 |
"type": m_type,
|
| 295 |
+
"snippet": r["chunk"],
|
| 296 |
"search_id": str(search_id)
|
| 297 |
}
|
| 298 |
|
|
|
|
| 328 |
logger.info(f"β‘ Search Cache HIT [KB]: {q}")
|
| 329 |
return cached_res
|
| 330 |
|
| 331 |
+
# 0.5 Semantic Cache Check for pin-point Answer (if NL query)
|
| 332 |
+
is_question = q.strip().endswith('?') or any(q.lower().startswith(w) for w in ["how", "what", "where", "why", "who", "tell"])
|
| 333 |
+
if is_question:
|
| 334 |
+
sem_answer = await SemanticCacheManager.check_cache(
|
| 335 |
+
str(current_user.workspace_id), q,
|
| 336 |
+
is_agent=(current_user.role in ALL_SC_ROLES),
|
| 337 |
+
user_role=current_user.role.value if hasattr(current_user.role, 'value') else str(current_user.role)
|
| 338 |
+
)
|
| 339 |
+
if sem_answer:
|
| 340 |
+
logger.info(f"π§ Semantic Cache HIT [KB]: {q}")
|
| 341 |
+
# Still need the document results, but we'll return the answer from cache
|
| 342 |
+
# For speed, if we have a semantic answer, we might still want to refresh the docs
|
| 343 |
+
pass # We'll check again after doc retrieval
|
| 344 |
+
|
| 345 |
# 1. Start Original Search Branch IMMEDIATELY (Don't wait for LLM)
|
| 346 |
original_search_task = execute_multimodal_search(db, q, current_user, category, project_id)
|
| 347 |
|
|
|
|
| 392 |
res_dict = KBArticleResponse.model_validate(article_obj).model_dump()
|
| 393 |
res_dict["score"] = score
|
| 394 |
res_dict["match_type"] = data.get("type", "semantic") # Safe access to avoid KeyError
|
| 395 |
+
res_dict["snippet"] = data.get("snippet")
|
| 396 |
final_results.append(res_dict)
|
| 397 |
|
| 398 |
final_results.sort(key=lambda x: float(x.get("score") or 0.0), reverse=True)
|
| 399 |
top_results = final_results[:5]
|
| 400 |
|
| 401 |
+
# 4.5 Synthesis Branch (The "Direct Answer" Engine)
|
| 402 |
+
direct_answer = None
|
| 403 |
+
is_ai_synthetic = False
|
| 404 |
+
|
| 405 |
+
if is_question and top_results:
|
| 406 |
+
# Check semantic cache first (redundant but safe)
|
| 407 |
+
direct_answer = await SemanticCacheManager.check_cache(
|
| 408 |
+
str(current_user.workspace_id), q,
|
| 409 |
+
is_agent=(current_user.role in ALL_SC_ROLES),
|
| 410 |
+
user_role=current_user.role.value if hasattr(current_user.role, 'value') else str(current_user.role)
|
| 411 |
+
)
|
| 412 |
+
|
| 413 |
+
if not direct_answer:
|
| 414 |
+
# Construct context from top snippets
|
| 415 |
+
context_txt = "\n\n".join([f"DOC {i+1} [{r['title']}]: {r['snippet'] or r['content'][:200]}" for i, r in enumerate(top_results)])
|
| 416 |
+
try:
|
| 417 |
+
llm = get_llm()
|
| 418 |
+
prompt = [
|
| 419 |
+
SystemMessage(content="You are a technical support expert. Provide a CONCISE 2-3 sentence direct answer based ONLY on the provided documentation context. If the answer isn't clear, say you don't know."),
|
| 420 |
+
HumanMessage(content=f"Context:\n{context_txt}\n\nQuestion: {q}")
|
| 421 |
+
]
|
| 422 |
+
synth_resp = await llm.ainvoke(prompt)
|
| 423 |
+
direct_answer = synth_resp.content
|
| 424 |
+
is_ai_synthetic = True
|
| 425 |
+
|
| 426 |
+
# Persist to Semantic Cache
|
| 427 |
+
import asyncio
|
| 428 |
+
asyncio.create_task(SemanticCacheManager.set_cache(
|
| 429 |
+
str(current_user.workspace_id), str(current_user.id), q, direct_answer,
|
| 430 |
+
is_agent=(current_user.role in ALL_SC_ROLES),
|
| 431 |
+
user_role=current_user.role.value if hasattr(current_user.role, 'value') else str(current_user.role)
|
| 432 |
+
))
|
| 433 |
+
except Exception as e:
|
| 434 |
+
logger.error(f"Synthesis failed: {e}")
|
| 435 |
+
else:
|
| 436 |
+
is_ai_synthetic = True
|
| 437 |
+
|
| 438 |
# 5. Suggestion for UI if results are still thin
|
| 439 |
suggestion = expanded_queries[0] if expanded_queries and expanded_queries[0].lower() != q.lower() else None
|
| 440 |
|
|
|
|
| 443 |
|
| 444 |
res_data = {
|
| 445 |
"results": top_results,
|
| 446 |
+
"answer": direct_answer,
|
| 447 |
+
"is_ai_synthetic": is_ai_synthetic,
|
| 448 |
"suggestion": suggestion if not top_results else None,
|
| 449 |
"expanded_queries": expanded_queries,
|
| 450 |
"search_time_s": round(search_time_s, 3)
|
api/v1/reports.py
CHANGED
|
@@ -25,10 +25,21 @@ async def get_volume_trends(
|
|
| 25 |
) -> Any:
|
| 26 |
"""Get ticket volume trends over time."""
|
| 27 |
from models.workspace import Workspace
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
# Strictly enforce current user's workspace
|
| 31 |
target_ws = current_user.workspace_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
since = datetime.utcnow() - timedelta(days=days)
|
| 34 |
stmt = (
|
|
@@ -50,9 +61,21 @@ async def get_csat_report(
|
|
| 50 |
current_user: User = Depends(get_current_user),
|
| 51 |
db: AsyncSession = Depends(get_db)
|
| 52 |
) -> Any:
|
| 53 |
-
|
| 54 |
-
# Strictly enforce current user's workspace
|
| 55 |
target_ws = current_user.workspace_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
stmt = (
|
| 58 |
select(func.avg(Feedback.rating), func.count(Feedback.id))
|
|
@@ -72,8 +95,21 @@ async def get_sla_compliance(
|
|
| 72 |
current_user: User = Depends(get_current_user),
|
| 73 |
db: AsyncSession = Depends(get_db)
|
| 74 |
) -> Any:
|
| 75 |
-
# Strictly enforce current user's workspace
|
| 76 |
target_ws = current_user.workspace_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# Real logic: Join tickets with their priority-level escalation rules
|
| 79 |
from models.escalation_rule import EscalationRule
|
|
@@ -129,8 +165,21 @@ async def get_ai_service_insights(
|
|
| 129 |
# 1. Get current SLA metrics
|
| 130 |
metrics = await get_sla_compliance(workspace_id, current_user, db)
|
| 131 |
|
| 132 |
-
# Strictly enforce current user's workspace
|
| 133 |
target_ws = current_user.workspace_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
# 2. Get recent tickets for context (last 48 hours only for SPEED)
|
| 136 |
since_48h = datetime.utcnow() - timedelta(hours=48)
|
|
@@ -187,8 +236,21 @@ async def get_daily_stats(
|
|
| 187 |
db: AsyncSession = Depends(get_db)
|
| 188 |
) -> Any:
|
| 189 |
"""Unified endpoint for daily trends and category distribution (last 30 days)."""
|
| 190 |
-
# Strictly enforce current user's workspace
|
| 191 |
target_ws = current_user.workspace_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
now = datetime.utcnow()
|
| 194 |
since_30d = now - timedelta(days=30)
|
|
|
|
| 25 |
) -> Any:
|
| 26 |
"""Get ticket volume trends over time."""
|
| 27 |
from models.workspace import Workspace
|
| 28 |
+
# Strictly enforce current user's workspace, allowing override for staff if they are authorized
|
|
|
|
|
|
|
| 29 |
target_ws = current_user.workspace_id
|
| 30 |
+
if workspace_id:
|
| 31 |
+
if current_user.role == UserRole.SC_ADMIN:
|
| 32 |
+
target_ws = workspace_id
|
| 33 |
+
else:
|
| 34 |
+
from models.user_workspace import UserWorkspace
|
| 35 |
+
ws_check = await db.execute(
|
| 36 |
+
select(UserWorkspace).where(
|
| 37 |
+
UserWorkspace.user_id == current_user.id,
|
| 38 |
+
UserWorkspace.workspace_id == workspace_id
|
| 39 |
+
)
|
| 40 |
+
)
|
| 41 |
+
if ws_check.scalar_one_or_none():
|
| 42 |
+
target_ws = workspace_id
|
| 43 |
|
| 44 |
since = datetime.utcnow() - timedelta(days=days)
|
| 45 |
stmt = (
|
|
|
|
| 61 |
current_user: User = Depends(get_current_user),
|
| 62 |
db: AsyncSession = Depends(get_db)
|
| 63 |
) -> Any:
|
| 64 |
+
# Strictly enforce current user's workspace, allowing override for authorized staff
|
|
|
|
| 65 |
target_ws = current_user.workspace_id
|
| 66 |
+
if workspace_id:
|
| 67 |
+
if current_user.role == UserRole.SC_ADMIN:
|
| 68 |
+
target_ws = workspace_id
|
| 69 |
+
else:
|
| 70 |
+
from models.user_workspace import UserWorkspace
|
| 71 |
+
ws_check = await db.execute(
|
| 72 |
+
select(UserWorkspace).where(
|
| 73 |
+
UserWorkspace.user_id == current_user.id,
|
| 74 |
+
UserWorkspace.workspace_id == workspace_id
|
| 75 |
+
)
|
| 76 |
+
)
|
| 77 |
+
if ws_check.scalar_one_or_none():
|
| 78 |
+
target_ws = workspace_id
|
| 79 |
|
| 80 |
stmt = (
|
| 81 |
select(func.avg(Feedback.rating), func.count(Feedback.id))
|
|
|
|
| 95 |
current_user: User = Depends(get_current_user),
|
| 96 |
db: AsyncSession = Depends(get_db)
|
| 97 |
) -> Any:
|
| 98 |
+
# Strictly enforce current user's workspace, allowing override for authorized staff
|
| 99 |
target_ws = current_user.workspace_id
|
| 100 |
+
if workspace_id:
|
| 101 |
+
if current_user.role == UserRole.SC_ADMIN:
|
| 102 |
+
target_ws = workspace_id
|
| 103 |
+
else:
|
| 104 |
+
from models.user_workspace import UserWorkspace
|
| 105 |
+
ws_check = await db.execute(
|
| 106 |
+
select(UserWorkspace).where(
|
| 107 |
+
UserWorkspace.user_id == current_user.id,
|
| 108 |
+
UserWorkspace.workspace_id == workspace_id
|
| 109 |
+
)
|
| 110 |
+
)
|
| 111 |
+
if ws_check.scalar_one_or_none():
|
| 112 |
+
target_ws = workspace_id
|
| 113 |
|
| 114 |
# Real logic: Join tickets with their priority-level escalation rules
|
| 115 |
from models.escalation_rule import EscalationRule
|
|
|
|
| 165 |
# 1. Get current SLA metrics
|
| 166 |
metrics = await get_sla_compliance(workspace_id, current_user, db)
|
| 167 |
|
| 168 |
+
# Strictly enforce current user's workspace, allowing override for Global Admin
|
| 169 |
target_ws = current_user.workspace_id
|
| 170 |
+
if workspace_id:
|
| 171 |
+
if current_user.role == UserRole.SC_ADMIN:
|
| 172 |
+
target_ws = workspace_id
|
| 173 |
+
else:
|
| 174 |
+
from models.user_workspace import UserWorkspace
|
| 175 |
+
ws_check = await db.execute(
|
| 176 |
+
select(UserWorkspace).where(
|
| 177 |
+
UserWorkspace.user_id == current_user.id,
|
| 178 |
+
UserWorkspace.workspace_id == workspace_id
|
| 179 |
+
)
|
| 180 |
+
)
|
| 181 |
+
if ws_check.scalar_one_or_none():
|
| 182 |
+
target_ws = workspace_id
|
| 183 |
|
| 184 |
# 2. Get recent tickets for context (last 48 hours only for SPEED)
|
| 185 |
since_48h = datetime.utcnow() - timedelta(hours=48)
|
|
|
|
| 236 |
db: AsyncSession = Depends(get_db)
|
| 237 |
) -> Any:
|
| 238 |
"""Unified endpoint for daily trends and category distribution (last 30 days)."""
|
| 239 |
+
# Strictly enforce current user's workspace, allowing override for Global Admin
|
| 240 |
target_ws = current_user.workspace_id
|
| 241 |
+
if workspace_id:
|
| 242 |
+
if current_user.role == UserRole.SC_ADMIN:
|
| 243 |
+
target_ws = workspace_id
|
| 244 |
+
else:
|
| 245 |
+
from models.user_workspace import UserWorkspace
|
| 246 |
+
ws_check = await db.execute(
|
| 247 |
+
select(UserWorkspace).where(
|
| 248 |
+
UserWorkspace.user_id == current_user.id,
|
| 249 |
+
UserWorkspace.workspace_id == workspace_id
|
| 250 |
+
)
|
| 251 |
+
)
|
| 252 |
+
if ws_check.scalar_one_or_none():
|
| 253 |
+
target_ws = workspace_id
|
| 254 |
|
| 255 |
now = datetime.utcnow()
|
| 256 |
since_30d = now - timedelta(days=30)
|
frontend/apps/customer/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
| 11 |
},
|
| 12 |
"dependencies": {
|
| 13 |
"@nexus/shared": "*",
|
|
|
|
| 14 |
"mermaid": "^11.13.0",
|
| 15 |
"react": "^19.2.4",
|
| 16 |
"react-dom": "^19.2.4",
|
|
|
|
| 11 |
},
|
| 12 |
"dependencies": {
|
| 13 |
"@nexus/shared": "*",
|
| 14 |
+
"lucide-react": "^1.7.0",
|
| 15 |
"mermaid": "^11.13.0",
|
| 16 |
"react": "^19.2.4",
|
| 17 |
"react-dom": "^19.2.4",
|
frontend/apps/customer/src/components/KnowledgeBase.tsx
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
import React, { useState, useEffect } from 'react';
|
| 2 |
import { api } from '@nexus/shared';
|
| 3 |
import { Skeleton } from './Skeleton';
|
|
|
|
| 4 |
|
| 5 |
const COLORS = {
|
| 6 |
brand: "#1E40AF",
|
| 7 |
brandLight: "#EFF6FF",
|
|
|
|
| 8 |
success: "#16A34A",
|
| 9 |
gray50: "#F9FAFB",
|
| 10 |
gray100: "#F3F4FB",
|
|
@@ -36,6 +38,10 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 36 |
const [page, setPage] = useState(1);
|
| 37 |
const [selectedArticle, setSelectedArticle] = useState<any | null>(null);
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
useEffect(() => {
|
| 40 |
fetchCategories();
|
| 41 |
}, []);
|
|
@@ -48,6 +54,16 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 48 |
return () => clearTimeout(delayDebounceFn);
|
| 49 |
}, [search, activeCategory, sortBy]);
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
const fetchCategories = async () => {
|
| 52 |
try {
|
| 53 |
const res = await api.get('kb/categories/');
|
|
@@ -65,6 +81,8 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 65 |
res = await api.get('kb/search/', { params: { q: search, category: activeCategory } });
|
| 66 |
setArticles(res.data.results || []);
|
| 67 |
setSuggestions(res.data.expanded_queries || []);
|
|
|
|
|
|
|
| 68 |
} else {
|
| 69 |
res = await api.get('kb/', { params: { category: activeCategory } });
|
| 70 |
let data = res.data || [];
|
|
@@ -75,6 +93,8 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 75 |
});
|
| 76 |
setArticles(data);
|
| 77 |
setSuggestions([]);
|
|
|
|
|
|
|
| 78 |
}
|
| 79 |
setPage(1);
|
| 80 |
} catch (err) {
|
|
@@ -137,7 +157,7 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 137 |
fontSize: 14, cursor: "pointer", marginBottom: 32, display: "flex", alignItems: "center", gap: 8
|
| 138 |
}}
|
| 139 |
>
|
| 140 |
-
|
| 141 |
</button>
|
| 142 |
|
| 143 |
<div style={{ marginBottom: 40 }}>
|
|
@@ -155,6 +175,35 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 155 |
<div style={{ width: 60, height: 4, background: COLORS.brand, borderRadius: 2 }} />
|
| 156 |
</div>
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
<div style={{
|
| 159 |
fontSize: 18, color: COLORS.gray800, lineHeight: 1.8,
|
| 160 |
fontFamily: "'Inter', sans-serif", borderTop: `1px solid ${COLORS.gray100}`, paddingTop: 40,
|
|
@@ -206,9 +255,10 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 206 |
borderRadius: 10, cursor: "pointer", fontSize: 13, fontWeight: 700
|
| 207 |
}}
|
| 208 |
>
|
|
|
|
| 209 |
Search
|
| 210 |
</button>
|
| 211 |
-
<
|
| 212 |
</div>
|
| 213 |
|
| 214 |
<div style={{ display: "flex", gap: 12, alignItems: "center" }}>
|
|
@@ -259,6 +309,40 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 259 |
))}
|
| 260 |
</div>
|
| 261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
{/* Article Feed */}
|
| 263 |
<div style={{ maxWidth: 1100, margin: "0 auto" }}>
|
| 264 |
{loading ? (
|
|
@@ -314,7 +398,7 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 314 |
display: "-webkit-box", WebkitLineClamp: 3, WebkitBoxOrient: "vertical", overflow: "hidden",
|
| 315 |
wordBreak: "break-word", overflowWrap: "anywhere"
|
| 316 |
}}>
|
| 317 |
-
{article.summary || article.content.slice(0, 180)}...
|
| 318 |
</p>
|
| 319 |
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", borderTop: `1px solid ${COLORS.gray50}`, paddingTop: 24, marginTop: "auto" }}>
|
| 320 |
<span style={{ fontSize: 12, color: COLORS.gray400, fontWeight: 500 }}>Published {new Date(article.created_at).toLocaleDateString()}</span>
|
|
@@ -332,7 +416,7 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 332 |
onClick={() => setPage(p => p - 1)}
|
| 333 |
style={{ padding: "10px 24px", borderRadius: 12, border: `1px solid ${COLORS.gray200}`, background: "#fff", fontWeight: 700, fontSize: 14, color: page === 1 ? COLORS.gray300 : COLORS.gray900, cursor: page === 1 ? "default" : "pointer" }}
|
| 334 |
>
|
| 335 |
-
|
| 336 |
</button>
|
| 337 |
<div style={{ fontSize: 14, fontWeight: 600, color: COLORS.gray600 }}>Page {page} of {totalPages}</div>
|
| 338 |
<button
|
|
@@ -340,7 +424,7 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ onNewTicket }) =>
|
|
| 340 |
onClick={() => setPage(p => p + 1)}
|
| 341 |
style={{ padding: "10px 24px", borderRadius: 12, border: `1px solid ${COLORS.gray200}`, background: "#fff", fontWeight: 700, fontSize: 14, color: page === totalPages ? COLORS.gray300 : COLORS.gray900, cursor: page === totalPages ? "default" : "pointer" }}
|
| 342 |
>
|
| 343 |
-
|
| 344 |
</button>
|
| 345 |
</div>
|
| 346 |
)}
|
|
|
|
| 1 |
import React, { useState, useEffect } from 'react';
|
| 2 |
import { api } from '@nexus/shared';
|
| 3 |
import { Skeleton } from './Skeleton';
|
| 4 |
+
import { Search, ChevronLeft, ChevronRight, Sparkles } from 'lucide-react';
|
| 5 |
|
| 6 |
const COLORS = {
|
| 7 |
brand: "#1E40AF",
|
| 8 |
brandLight: "#EFF6FF",
|
| 9 |
+
brandDeep: "#1E3A8A",
|
| 10 |
success: "#16A34A",
|
| 11 |
gray50: "#F9FAFB",
|
| 12 |
gray100: "#F3F4FB",
|
|
|
|
| 38 |
const [page, setPage] = useState(1);
|
| 39 |
const [selectedArticle, setSelectedArticle] = useState<any | null>(null);
|
| 40 |
|
| 41 |
+
// Pinpoint Engine State
|
| 42 |
+
const [aiAnswer, setAiAnswer] = useState<string | null>(null);
|
| 43 |
+
const [isAiSynthetic, setIsAiSynthetic] = useState(false);
|
| 44 |
+
|
| 45 |
useEffect(() => {
|
| 46 |
fetchCategories();
|
| 47 |
}, []);
|
|
|
|
| 54 |
return () => clearTimeout(delayDebounceFn);
|
| 55 |
}, [search, activeCategory, sortBy]);
|
| 56 |
|
| 57 |
+
// Reactive Search Reset
|
| 58 |
+
useEffect(() => {
|
| 59 |
+
if (searchInput.trim() === "") {
|
| 60 |
+
setSearch("");
|
| 61 |
+
setAiAnswer(null);
|
| 62 |
+
setSuggestions([]);
|
| 63 |
+
setIsAiSynthetic(false);
|
| 64 |
+
}
|
| 65 |
+
}, [searchInput]);
|
| 66 |
+
|
| 67 |
const fetchCategories = async () => {
|
| 68 |
try {
|
| 69 |
const res = await api.get('kb/categories/');
|
|
|
|
| 81 |
res = await api.get('kb/search/', { params: { q: search, category: activeCategory } });
|
| 82 |
setArticles(res.data.results || []);
|
| 83 |
setSuggestions(res.data.expanded_queries || []);
|
| 84 |
+
setAiAnswer(res.data.answer || null);
|
| 85 |
+
setIsAiSynthetic(res.data.is_ai_synthetic || false);
|
| 86 |
} else {
|
| 87 |
res = await api.get('kb/', { params: { category: activeCategory } });
|
| 88 |
let data = res.data || [];
|
|
|
|
| 93 |
});
|
| 94 |
setArticles(data);
|
| 95 |
setSuggestions([]);
|
| 96 |
+
setAiAnswer(null);
|
| 97 |
+
setIsAiSynthetic(false);
|
| 98 |
}
|
| 99 |
setPage(1);
|
| 100 |
} catch (err) {
|
|
|
|
| 157 |
fontSize: 14, cursor: "pointer", marginBottom: 32, display: "flex", alignItems: "center", gap: 8
|
| 158 |
}}
|
| 159 |
>
|
| 160 |
+
<ChevronLeft size={16} /> Back to Library
|
| 161 |
</button>
|
| 162 |
|
| 163 |
<div style={{ marginBottom: 40 }}>
|
|
|
|
| 175 |
<div style={{ width: 60, height: 4, background: COLORS.brand, borderRadius: 2 }} />
|
| 176 |
</div>
|
| 177 |
|
| 178 |
+
{/* AI Insight Section (Article Detail) */}
|
| 179 |
+
{selectedArticle.summary && (
|
| 180 |
+
<div style={{
|
| 181 |
+
background: "linear-gradient(135deg, #F0F7FF 0%, #F5F3FF 100%)",
|
| 182 |
+
border: `1px solid ${COLORS.brand}15`,
|
| 183 |
+
borderRadius: 16,
|
| 184 |
+
padding: "24px 32px",
|
| 185 |
+
marginBottom: 48,
|
| 186 |
+
position: "relative",
|
| 187 |
+
overflow: "hidden",
|
| 188 |
+
boxShadow: "0 4px 20px rgba(30, 64, 175, 0.04)"
|
| 189 |
+
}}>
|
| 190 |
+
<div style={{
|
| 191 |
+
position: "absolute", left: 0, top: 0, width: 4, height: "100%", background: COLORS.brand
|
| 192 |
+
}} />
|
| 193 |
+
<div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 16 }}>
|
| 194 |
+
<Sparkles size={16} color={COLORS.brand} />
|
| 195 |
+
<span style={{ fontSize: 11, fontWeight: 900, color: COLORS.brand, letterSpacing: "0.1em", textTransform: "uppercase" }}>
|
| 196 |
+
AI GENERATED SUMMARY
|
| 197 |
+
</span>
|
| 198 |
+
</div>
|
| 199 |
+
<p style={{
|
| 200 |
+
fontSize: 16, lineHeight: 1.7, color: COLORS.gray800, fontWeight: 500, fontStyle: "italic", margin: 0
|
| 201 |
+
}}>
|
| 202 |
+
{selectedArticle.summary}
|
| 203 |
+
</p>
|
| 204 |
+
</div>
|
| 205 |
+
)}
|
| 206 |
+
|
| 207 |
<div style={{
|
| 208 |
fontSize: 18, color: COLORS.gray800, lineHeight: 1.8,
|
| 209 |
fontFamily: "'Inter', sans-serif", borderTop: `1px solid ${COLORS.gray100}`, paddingTop: 40,
|
|
|
|
| 255 |
borderRadius: 10, cursor: "pointer", fontSize: 13, fontWeight: 700
|
| 256 |
}}
|
| 257 |
>
|
| 258 |
+
<Search size={14} style={{ display: 'inline', marginRight: 6 }} />
|
| 259 |
Search
|
| 260 |
</button>
|
| 261 |
+
<Search size={20} color={COLORS.gray400} style={{ position: "absolute", left: 20, top: "50%", transform: "translateY(-50%)" }} />
|
| 262 |
</div>
|
| 263 |
|
| 264 |
<div style={{ display: "flex", gap: 12, alignItems: "center" }}>
|
|
|
|
| 309 |
))}
|
| 310 |
</div>
|
| 311 |
|
| 312 |
+
{/* AI Spotlight Section (Search Results) */}
|
| 313 |
+
{aiAnswer && (
|
| 314 |
+
<div style={{
|
| 315 |
+
maxWidth: 1100, margin: "0 auto 48px",
|
| 316 |
+
background: "white",
|
| 317 |
+
border: `1px solid ${COLORS.gray200}`,
|
| 318 |
+
borderRadius: 20,
|
| 319 |
+
padding: 40,
|
| 320 |
+
position: "relative",
|
| 321 |
+
boxShadow: "0 4px 20px rgba(0,0,0,0.02)"
|
| 322 |
+
}}>
|
| 323 |
+
<div style={{ position: "absolute", top: 0, left: 0, width: "100%", height: 3, background: COLORS.brand, borderRadius: "20px 20px 0 0" }} />
|
| 324 |
+
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }}>
|
| 325 |
+
<div style={{ display: "flex", alignItems: "center", gap: 10, background: COLORS.brandLight, padding: "6px 14px", borderRadius: 8 }}>
|
| 326 |
+
<Sparkles size={16} color={COLORS.brand} />
|
| 327 |
+
<span style={{ fontSize: 11, fontWeight: 900, color: COLORS.brand, letterSpacing: "0.1em", textTransform: "uppercase" }}>
|
| 328 |
+
AI DIRECT ANSWER
|
| 329 |
+
</span>
|
| 330 |
+
</div>
|
| 331 |
+
{isAiSynthetic && (
|
| 332 |
+
<span style={{ fontSize: 10, fontWeight: 800, color: "#16A34A", background: "#F0FDF4", padding: "4px 8px", borderRadius: 4 }}>
|
| 333 |
+
REAL-TIME SYNTHESIS
|
| 334 |
+
</span>
|
| 335 |
+
)}
|
| 336 |
+
</div>
|
| 337 |
+
<p style={{ fontSize: 18, lineHeight: 1.8, color: COLORS.gray900, fontWeight: 600, fontStyle: "italic", margin: 0 }}>
|
| 338 |
+
{aiAnswer}
|
| 339 |
+
</p>
|
| 340 |
+
<div style={{ marginTop: 24, paddingTop: 20, borderTop: `1px solid ${COLORS.gray100}`, fontSize: 11, fontWeight: 700, color: COLORS.gray400, textTransform: "uppercase", letterSpacing: "0.1em" }}>
|
| 341 |
+
Reference guides found below
|
| 342 |
+
</div>
|
| 343 |
+
</div>
|
| 344 |
+
)}
|
| 345 |
+
|
| 346 |
{/* Article Feed */}
|
| 347 |
<div style={{ maxWidth: 1100, margin: "0 auto" }}>
|
| 348 |
{loading ? (
|
|
|
|
| 398 |
display: "-webkit-box", WebkitLineClamp: 3, WebkitBoxOrient: "vertical", overflow: "hidden",
|
| 399 |
wordBreak: "break-word", overflowWrap: "anywhere"
|
| 400 |
}}>
|
| 401 |
+
{article.snippet || article.summary || article.content.replace(/[#*`]/g, '').slice(0, 180)}...
|
| 402 |
</p>
|
| 403 |
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", borderTop: `1px solid ${COLORS.gray50}`, paddingTop: 24, marginTop: "auto" }}>
|
| 404 |
<span style={{ fontSize: 12, color: COLORS.gray400, fontWeight: 500 }}>Published {new Date(article.created_at).toLocaleDateString()}</span>
|
|
|
|
| 416 |
onClick={() => setPage(p => p - 1)}
|
| 417 |
style={{ padding: "10px 24px", borderRadius: 12, border: `1px solid ${COLORS.gray200}`, background: "#fff", fontWeight: 700, fontSize: 14, color: page === 1 ? COLORS.gray300 : COLORS.gray900, cursor: page === 1 ? "default" : "pointer" }}
|
| 418 |
>
|
| 419 |
+
<ChevronLeft size={16} />
|
| 420 |
</button>
|
| 421 |
<div style={{ fontSize: 14, fontWeight: 600, color: COLORS.gray600 }}>Page {page} of {totalPages}</div>
|
| 422 |
<button
|
|
|
|
| 424 |
onClick={() => setPage(p => p + 1)}
|
| 425 |
style={{ padding: "10px 24px", borderRadius: 12, border: `1px solid ${COLORS.gray200}`, background: "#fff", fontWeight: 700, fontSize: 14, color: page === totalPages ? COLORS.gray300 : COLORS.gray900, cursor: page === totalPages ? "default" : "pointer" }}
|
| 426 |
>
|
| 427 |
+
<ChevronRight size={16} />
|
| 428 |
</button>
|
| 429 |
</div>
|
| 430 |
)}
|
frontend/apps/internal/src/components/KnowledgeBase.module.css
CHANGED
|
@@ -785,4 +785,84 @@
|
|
| 785 |
background: #F1F5F9;
|
| 786 |
padding: 2px 6px;
|
| 787 |
border-radius: 4px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
}
|
|
|
|
| 785 |
background: #F1F5F9;
|
| 786 |
padding: 2px 6px;
|
| 787 |
border-radius: 4px;
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
/* AI Answer Spotlight */
|
| 791 |
+
.resultsContainer {
|
| 792 |
+
display: flex;
|
| 793 |
+
flex-direction: column;
|
| 794 |
+
gap: 32px;
|
| 795 |
+
width: 100%;
|
| 796 |
+
}
|
| 797 |
+
|
| 798 |
+
.aiSpotlight {
|
| 799 |
+
background: white;
|
| 800 |
+
border: 1px solid var(--border-subtle);
|
| 801 |
+
border-radius: var(--radius-lg);
|
| 802 |
+
padding: 40px;
|
| 803 |
+
position: relative;
|
| 804 |
+
overflow: hidden;
|
| 805 |
+
box-shadow: 0 4px 20px rgba(0,0,0,0.03);
|
| 806 |
+
margin-bottom: 24px;
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
.aiSpotlight::before {
|
| 810 |
+
content: '';
|
| 811 |
+
position: absolute;
|
| 812 |
+
top: 0;
|
| 813 |
+
left: 0;
|
| 814 |
+
width: 100%;
|
| 815 |
+
height: 4px;
|
| 816 |
+
background: var(--banner-gradient);
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
.spotlightHeader {
|
| 820 |
+
display: flex;
|
| 821 |
+
justify-content: space-between;
|
| 822 |
+
align-items: center;
|
| 823 |
+
margin-bottom: 24px;
|
| 824 |
+
}
|
| 825 |
+
|
| 826 |
+
.spotlightBadge {
|
| 827 |
+
display: flex;
|
| 828 |
+
align-items: center;
|
| 829 |
+
gap: 8px;
|
| 830 |
+
font-size: 11px;
|
| 831 |
+
font-weight: 800;
|
| 832 |
+
color: var(--primary);
|
| 833 |
+
background: var(--bg-hover);
|
| 834 |
+
padding: 6px 14px;
|
| 835 |
+
border-radius: 8px;
|
| 836 |
+
letter-spacing: 0.1em;
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
+
.syntheticLag {
|
| 840 |
+
font-size: 9px;
|
| 841 |
+
font-weight: 900;
|
| 842 |
+
color: #10B981;
|
| 843 |
+
background: #ECFDF5;
|
| 844 |
+
padding: 4px 8px;
|
| 845 |
+
border-radius: 4px;
|
| 846 |
+
letter-spacing: 0.05em;
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
.answerText {
|
| 850 |
+
font-size: 18px;
|
| 851 |
+
line-height: 1.8;
|
| 852 |
+
color: var(--text-main);
|
| 853 |
+
font-weight: 600;
|
| 854 |
+
font-style: italic;
|
| 855 |
+
margin: 0;
|
| 856 |
+
max-width: 900px;
|
| 857 |
+
}
|
| 858 |
+
|
| 859 |
+
.spotlightFooter {
|
| 860 |
+
margin-top: 24px;
|
| 861 |
+
padding-top: 20px;
|
| 862 |
+
border-top: 1px solid var(--border-subtle);
|
| 863 |
+
font-size: 11px;
|
| 864 |
+
font-weight: 700;
|
| 865 |
+
color: var(--text-muted);
|
| 866 |
+
text-transform: uppercase;
|
| 867 |
+
letter-spacing: 0.1em;
|
| 868 |
}
|
frontend/apps/internal/src/components/KnowledgeBase.tsx
CHANGED
|
@@ -47,6 +47,7 @@ interface Article {
|
|
| 47 |
summary?: string;
|
| 48 |
score?: number;
|
| 49 |
match_type?: string;
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
export const KnowledgeBase: React.FC = () => {
|
|
@@ -81,6 +82,8 @@ export const KnowledgeBase: React.FC = () => {
|
|
| 81 |
// AI Search Enhanced State
|
| 82 |
const [suggestions, setSuggestions] = useState<string[]>([]);
|
| 83 |
const [aiSuggestion, setAiSuggestion] = useState<string | null>(null);
|
|
|
|
|
|
|
| 84 |
|
| 85 |
// AI Growth Center State
|
| 86 |
const [activeTab, setActiveTab] = useState<'library' | 'growth'>('library');
|
|
@@ -110,11 +113,15 @@ export const KnowledgeBase: React.FC = () => {
|
|
| 110 |
setArticles(resp.data.results || []);
|
| 111 |
setSuggestions(resp.data.expanded_queries || []);
|
| 112 |
setAiSuggestion(resp.data.suggestion || null);
|
|
|
|
|
|
|
| 113 |
} else {
|
| 114 |
const resp = await api.get('kb/', { params });
|
| 115 |
setArticles(resp.data || []);
|
| 116 |
setSuggestions([]);
|
| 117 |
setAiSuggestion(null);
|
|
|
|
|
|
|
| 118 |
}
|
| 119 |
setCurrentPage(1); // Reset to first page on search/filter
|
| 120 |
} catch (err) {
|
|
@@ -142,6 +149,19 @@ export const KnowledgeBase: React.FC = () => {
|
|
| 142 |
fetchArticles('', 'All');
|
| 143 |
}, [fetchCategories, fetchArticles]);
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
useEffect(() => {
|
| 146 |
if (activeTab === 'growth') {
|
| 147 |
fetchInsights();
|
|
@@ -429,12 +449,35 @@ export const KnowledgeBase: React.FC = () => {
|
|
| 429 |
)}
|
| 430 |
</motion.div>
|
| 431 |
) : (
|
| 432 |
-
<
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
{paginatedArticles.map((article, i) => (
|
| 439 |
<motion.div
|
| 440 |
key={article.id}
|
|
@@ -456,7 +499,7 @@ export const KnowledgeBase: React.FC = () => {
|
|
| 456 |
<span className={styles.catBadge}>{article.category}</span>
|
| 457 |
<h3>{article.title}</h3>
|
| 458 |
<p className={styles.snippet}>
|
| 459 |
-
{article.content.replace(/[#*`]/g, '').slice(0, 140)}...
|
| 460 |
</p>
|
| 461 |
</div>
|
| 462 |
|
|
@@ -468,7 +511,8 @@ export const KnowledgeBase: React.FC = () => {
|
|
| 468 |
</div>
|
| 469 |
</motion.div>
|
| 470 |
))}
|
| 471 |
-
|
|
|
|
| 472 |
)}
|
| 473 |
</AnimatePresence>
|
| 474 |
|
|
|
|
| 47 |
summary?: string;
|
| 48 |
score?: number;
|
| 49 |
match_type?: string;
|
| 50 |
+
snippet?: string;
|
| 51 |
}
|
| 52 |
|
| 53 |
export const KnowledgeBase: React.FC = () => {
|
|
|
|
| 82 |
// AI Search Enhanced State
|
| 83 |
const [suggestions, setSuggestions] = useState<string[]>([]);
|
| 84 |
const [aiSuggestion, setAiSuggestion] = useState<string | null>(null);
|
| 85 |
+
const [aiAnswer, setAiAnswer] = useState<string | null>(null);
|
| 86 |
+
const [isAiSynthetic, setIsAiSynthetic] = useState(false);
|
| 87 |
|
| 88 |
// AI Growth Center State
|
| 89 |
const [activeTab, setActiveTab] = useState<'library' | 'growth'>('library');
|
|
|
|
| 113 |
setArticles(resp.data.results || []);
|
| 114 |
setSuggestions(resp.data.expanded_queries || []);
|
| 115 |
setAiSuggestion(resp.data.suggestion || null);
|
| 116 |
+
setAiAnswer(resp.data.answer || null);
|
| 117 |
+
setIsAiSynthetic(resp.data.is_ai_synthetic || false);
|
| 118 |
} else {
|
| 119 |
const resp = await api.get('kb/', { params });
|
| 120 |
setArticles(resp.data || []);
|
| 121 |
setSuggestions([]);
|
| 122 |
setAiSuggestion(null);
|
| 123 |
+
setAiAnswer(null);
|
| 124 |
+
setIsAiSynthetic(false);
|
| 125 |
}
|
| 126 |
setCurrentPage(1); // Reset to first page on search/filter
|
| 127 |
} catch (err) {
|
|
|
|
| 149 |
fetchArticles('', 'All');
|
| 150 |
}, [fetchCategories, fetchArticles]);
|
| 151 |
|
| 152 |
+
// Reactive Search Reset
|
| 153 |
+
useEffect(() => {
|
| 154 |
+
if (searchInput.trim() === '') {
|
| 155 |
+
setActiveQuery('');
|
| 156 |
+
setAiAnswer(null);
|
| 157 |
+
setSuggestions([]);
|
| 158 |
+
setAiSuggestion(null);
|
| 159 |
+
setIsAiSynthetic(false);
|
| 160 |
+
// Optional: fetchArticles('', selectedCategory);
|
| 161 |
+
// But fetchArticles is already called by the next useEffect if we change activeQuery
|
| 162 |
+
}
|
| 163 |
+
}, [searchInput]);
|
| 164 |
+
|
| 165 |
useEffect(() => {
|
| 166 |
if (activeTab === 'growth') {
|
| 167 |
fetchInsights();
|
|
|
|
| 449 |
)}
|
| 450 |
</motion.div>
|
| 451 |
) : (
|
| 452 |
+
<div className={styles.resultsContainer}>
|
| 453 |
+
<AnimatePresence>
|
| 454 |
+
{aiAnswer && (
|
| 455 |
+
<motion.div
|
| 456 |
+
className={styles.aiSpotlight}
|
| 457 |
+
initial={{ opacity: 0, y: 20 }}
|
| 458 |
+
animate={{ opacity: 1, y: 0 }}
|
| 459 |
+
exit={{ opacity: 0, scale: 0.95 }}
|
| 460 |
+
>
|
| 461 |
+
<div className={styles.spotlightHeader}>
|
| 462 |
+
<div className={styles.spotlightBadge}>
|
| 463 |
+
<Sparkles size={14} /> AI DIRECT ANSWER
|
| 464 |
+
</div>
|
| 465 |
+
{isAiSynthetic && <span className={styles.syntheticLag}>GENERATED IN REAL-TIME</span>}
|
| 466 |
+
</div>
|
| 467 |
+
<p className={styles.answerText}>{aiAnswer}</p>
|
| 468 |
+
<div className={styles.spotlightFooter}>
|
| 469 |
+
Based on the top documentation matches below.
|
| 470 |
+
</div>
|
| 471 |
+
</motion.div>
|
| 472 |
+
)}
|
| 473 |
+
</AnimatePresence>
|
| 474 |
+
|
| 475 |
+
<motion.div
|
| 476 |
+
key="grid"
|
| 477 |
+
className={styles.articlesGrid}
|
| 478 |
+
initial={{ opacity: 0 }}
|
| 479 |
+
animate={{ opacity: 1 }}
|
| 480 |
+
>
|
| 481 |
{paginatedArticles.map((article, i) => (
|
| 482 |
<motion.div
|
| 483 |
key={article.id}
|
|
|
|
| 499 |
<span className={styles.catBadge}>{article.category}</span>
|
| 500 |
<h3>{article.title}</h3>
|
| 501 |
<p className={styles.snippet}>
|
| 502 |
+
{article.snippet || article.content.replace(/[#*`]/g, '').slice(0, 140)}...
|
| 503 |
</p>
|
| 504 |
</div>
|
| 505 |
|
|
|
|
| 511 |
</div>
|
| 512 |
</motion.div>
|
| 513 |
))}
|
| 514 |
+
</motion.div>
|
| 515 |
+
</div>
|
| 516 |
)}
|
| 517 |
</AnimatePresence>
|
| 518 |
|
frontend/apps/internal/src/components/TopBar.module.css
CHANGED
|
@@ -106,31 +106,59 @@
|
|
| 106 |
.resultMeta {
|
| 107 |
display: flex;
|
| 108 |
justify-content: space-between;
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
}
|
| 111 |
|
| 112 |
.resultId {
|
| 113 |
font-size: 10px;
|
| 114 |
font-weight: 800;
|
| 115 |
-
color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
.resultStatus {
|
| 119 |
font-size: 9px;
|
| 120 |
font-weight: 900;
|
| 121 |
text-transform: uppercase;
|
| 122 |
-
padding: 2px
|
| 123 |
-
border-radius:
|
| 124 |
}
|
| 125 |
|
| 126 |
-
.resultStatus[data-status="OPEN"] { color:
|
| 127 |
-
.resultStatus[data-status="IN_PROGRESS"] { color:
|
| 128 |
-
.resultStatus[data-status="RESOLVED"] { color:
|
| 129 |
|
| 130 |
.resultTitle {
|
| 131 |
font-size: 13px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
font-weight: 600;
|
| 133 |
-
color: var(--text1);
|
| 134 |
}
|
| 135 |
|
| 136 |
.searchLoader {
|
|
@@ -158,18 +186,26 @@
|
|
| 158 |
padding: 10px;
|
| 159 |
background: rgba(255, 255, 255, 0.9);
|
| 160 |
backdrop-filter: blur(8px);
|
| 161 |
-
border: 1px solid
|
| 162 |
border-radius: 10px;
|
| 163 |
font-size: 10px;
|
| 164 |
font-weight: 800;
|
| 165 |
text-align: center;
|
| 166 |
-
color:
|
| 167 |
text-transform: uppercase;
|
| 168 |
letter-spacing: 0.05em;
|
| 169 |
z-index: 1000;
|
| 170 |
animation: slideDown 0.2s ease-out;
|
| 171 |
}
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
/* Live Indicator */
|
| 174 |
.statusIndicator {
|
| 175 |
display: flex;
|
|
|
|
| 106 |
.resultMeta {
|
| 107 |
display: flex;
|
| 108 |
justify-content: space-between;
|
| 109 |
+
align-items: center;
|
| 110 |
+
margin-bottom: 8px;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.resultMetaLeft {
|
| 114 |
+
display: flex;
|
| 115 |
+
align-items: center;
|
| 116 |
+
gap: 8px;
|
| 117 |
}
|
| 118 |
|
| 119 |
.resultId {
|
| 120 |
font-size: 10px;
|
| 121 |
font-weight: 800;
|
| 122 |
+
color: #64748b;
|
| 123 |
+
background: #f1f5f9;
|
| 124 |
+
padding: 2px 6px;
|
| 125 |
+
border-radius: 4px;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.resultScore {
|
| 129 |
+
font-size: 10px;
|
| 130 |
+
font-weight: 800;
|
| 131 |
+
color: #3b82f6;
|
| 132 |
+
background: rgba(59, 130, 246, 0.1);
|
| 133 |
+
padding: 2px 6px;
|
| 134 |
+
border-radius: 4px;
|
| 135 |
}
|
| 136 |
|
| 137 |
.resultStatus {
|
| 138 |
font-size: 9px;
|
| 139 |
font-weight: 900;
|
| 140 |
text-transform: uppercase;
|
| 141 |
+
padding: 2px 8px;
|
| 142 |
+
border-radius: 5px;
|
| 143 |
}
|
| 144 |
|
| 145 |
+
.resultStatus[data-status="OPEN"] { color: #10b981; background: rgba(16, 185, 129, 0.1); }
|
| 146 |
+
.resultStatus[data-status="IN_PROGRESS"] { color: #6366f1; background: rgba(99, 102, 241, 0.1); }
|
| 147 |
+
.resultStatus[data-status="RESOLVED"] { color: #94a3b8; background: #f8fafc; }
|
| 148 |
|
| 149 |
.resultTitle {
|
| 150 |
font-size: 13px;
|
| 151 |
+
font-weight: 700;
|
| 152 |
+
color: #1e293b;
|
| 153 |
+
margin-bottom: 6px;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
.resultFooter {
|
| 157 |
+
display: flex;
|
| 158 |
+
justify-content: flex-end;
|
| 159 |
+
font-size: 10px;
|
| 160 |
+
color: #94a3b8;
|
| 161 |
font-weight: 600;
|
|
|
|
| 162 |
}
|
| 163 |
|
| 164 |
.searchLoader {
|
|
|
|
| 186 |
padding: 10px;
|
| 187 |
background: rgba(255, 255, 255, 0.9);
|
| 188 |
backdrop-filter: blur(8px);
|
| 189 |
+
border: 1px solid #e2e8f0;
|
| 190 |
border-radius: 10px;
|
| 191 |
font-size: 10px;
|
| 192 |
font-weight: 800;
|
| 193 |
text-align: center;
|
| 194 |
+
color: #64748b;
|
| 195 |
text-transform: uppercase;
|
| 196 |
letter-spacing: 0.05em;
|
| 197 |
z-index: 1000;
|
| 198 |
animation: slideDown 0.2s ease-out;
|
| 199 |
}
|
| 200 |
|
| 201 |
+
.noResults {
|
| 202 |
+
padding: 32px 20px;
|
| 203 |
+
text-align: center;
|
| 204 |
+
color: #94a3b8;
|
| 205 |
+
font-size: 12px;
|
| 206 |
+
font-weight: 600;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
/* Live Indicator */
|
| 210 |
.statusIndicator {
|
| 211 |
display: flex;
|
frontend/apps/internal/src/components/TopBar.tsx
CHANGED
|
@@ -13,6 +13,7 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, onTicketSelect
|
|
| 13 |
const [searchQuery, setSearchQuery] = useState('');
|
| 14 |
const [results, setResults] = useState<any[]>([]);
|
| 15 |
const [isSearching, setIsSearching] = useState(false);
|
|
|
|
| 16 |
const [showLogoutConfirm, setShowLogoutConfirm] = useState(false);
|
| 17 |
const [showNotifications, setShowNotifications] = useState(false);
|
| 18 |
const searchRef = React.useRef<HTMLFormElement>(null);
|
|
@@ -75,6 +76,7 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, onTicketSelect
|
|
| 75 |
if (e) e.preventDefault();
|
| 76 |
if (!searchQuery.trim()) {
|
| 77 |
setResults([]);
|
|
|
|
| 78 |
return;
|
| 79 |
}
|
| 80 |
|
|
@@ -82,6 +84,7 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, onTicketSelect
|
|
| 82 |
try {
|
| 83 |
const resp = await api.get(`tickets/search/?q=${encodeURIComponent(searchQuery)}`);
|
| 84 |
setResults(resp.data.results || []);
|
|
|
|
| 85 |
} catch (err) {
|
| 86 |
console.error('Ticket search failed:', err);
|
| 87 |
} finally {
|
|
@@ -138,31 +141,42 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, onTicketSelect
|
|
| 138 |
onChange={(e) => setSearchQuery(e.target.value)}
|
| 139 |
/>
|
| 140 |
|
| 141 |
-
{
|
| 142 |
<div className={styles.resultsDropdown}>
|
| 143 |
-
{results.
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
</div>
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
| 160 |
</div>
|
| 161 |
)}
|
| 162 |
{isSearching && (
|
| 163 |
<div className={styles.searchLoader}>Scanning network...</div>
|
| 164 |
)}
|
| 165 |
-
{results.length === 0 && searchQuery && !isSearching && (
|
| 166 |
<div className={styles.searchHint}>Press Enter to search</div>
|
| 167 |
)}
|
| 168 |
</form>
|
|
|
|
| 13 |
const [searchQuery, setSearchQuery] = useState('');
|
| 14 |
const [results, setResults] = useState<any[]>([]);
|
| 15 |
const [isSearching, setIsSearching] = useState(false);
|
| 16 |
+
const [hasSearched, setHasSearched] = useState(false);
|
| 17 |
const [showLogoutConfirm, setShowLogoutConfirm] = useState(false);
|
| 18 |
const [showNotifications, setShowNotifications] = useState(false);
|
| 19 |
const searchRef = React.useRef<HTMLFormElement>(null);
|
|
|
|
| 76 |
if (e) e.preventDefault();
|
| 77 |
if (!searchQuery.trim()) {
|
| 78 |
setResults([]);
|
| 79 |
+
setHasSearched(false);
|
| 80 |
return;
|
| 81 |
}
|
| 82 |
|
|
|
|
| 84 |
try {
|
| 85 |
const resp = await api.get(`tickets/search/?q=${encodeURIComponent(searchQuery)}`);
|
| 86 |
setResults(resp.data.results || []);
|
| 87 |
+
setHasSearched(true);
|
| 88 |
} catch (err) {
|
| 89 |
console.error('Ticket search failed:', err);
|
| 90 |
} finally {
|
|
|
|
| 141 |
onChange={(e) => setSearchQuery(e.target.value)}
|
| 142 |
/>
|
| 143 |
|
| 144 |
+
{hasSearched && (
|
| 145 |
<div className={styles.resultsDropdown}>
|
| 146 |
+
{results.length > 0 ? (
|
| 147 |
+
results.map(r => (
|
| 148 |
+
<div
|
| 149 |
+
key={r.id}
|
| 150 |
+
className={styles.resultItem}
|
| 151 |
+
onClick={() => {
|
| 152 |
+
onTicketSelect?.(r);
|
| 153 |
+
setResults([]);
|
| 154 |
+
setSearchQuery('');
|
| 155 |
+
setHasSearched(false);
|
| 156 |
+
}}
|
| 157 |
+
>
|
| 158 |
+
<div className={styles.resultMeta}>
|
| 159 |
+
<div className={styles.resultMetaLeft}>
|
| 160 |
+
<span className={styles.resultScore}>{r.score}% Match</span>
|
| 161 |
+
<span className={styles.resultId}>#{r.id?.slice(0, 8).toUpperCase()}</span>
|
| 162 |
+
</div>
|
| 163 |
+
<span className={styles.resultStatus} data-status={r.status?.toUpperCase()}>{r.status}</span>
|
| 164 |
+
</div>
|
| 165 |
+
<div className={styles.resultTitle}>{r.title}</div>
|
| 166 |
+
<div className={styles.resultFooter}>
|
| 167 |
+
Created {new Date(r.created_at).toLocaleDateString()}
|
| 168 |
+
</div>
|
| 169 |
</div>
|
| 170 |
+
))
|
| 171 |
+
) : (
|
| 172 |
+
<div className={styles.noResults}>No tickets found matching your query.</div>
|
| 173 |
+
)}
|
| 174 |
</div>
|
| 175 |
)}
|
| 176 |
{isSearching && (
|
| 177 |
<div className={styles.searchLoader}>Scanning network...</div>
|
| 178 |
)}
|
| 179 |
+
{results.length === 0 && searchQuery && !isSearching && !hasSearched && (
|
| 180 |
<div className={styles.searchHint}>Press Enter to search</div>
|
| 181 |
)}
|
| 182 |
</form>
|
frontend/package-lock.json
CHANGED
|
@@ -20,6 +20,7 @@
|
|
| 20 |
"version": "0.0.0",
|
| 21 |
"dependencies": {
|
| 22 |
"@nexus/shared": "*",
|
|
|
|
| 23 |
"mermaid": "^11.13.0",
|
| 24 |
"react": "^19.2.4",
|
| 25 |
"react-dom": "^19.2.4",
|
|
@@ -48,7 +49,9 @@
|
|
| 48 |
"version": "0.0.0",
|
| 49 |
"dependencies": {
|
| 50 |
"@nexus/shared": "*",
|
|
|
|
| 51 |
"lucide-react": "^1.7.0",
|
|
|
|
| 52 |
"react": "^19.2.4",
|
| 53 |
"react-dom": "^19.2.4",
|
| 54 |
"react-markdown": "^10.1.0",
|
|
@@ -380,9 +383,9 @@
|
|
| 380 |
"license": "Apache-2.0"
|
| 381 |
},
|
| 382 |
"node_modules/@emnapi/wasi-threads": {
|
| 383 |
-
"version": "1.2.
|
| 384 |
-
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.
|
| 385 |
-
"integrity": "sha512-
|
| 386 |
"dev": true,
|
| 387 |
"license": "MIT",
|
| 388 |
"optional": true,
|
|
@@ -3208,7 +3211,6 @@
|
|
| 3208 |
"version": "12.38.0",
|
| 3209 |
"resolved": "https://registry.npmjs.org/framer-motion/-/framer-motion-12.38.0.tgz",
|
| 3210 |
"integrity": "sha512-rFYkY/pigbcswl1XQSb7q424kSTQ8q6eAC+YUsSKooHQYuLdzdHjrt6uxUC+PRAO++q5IS7+TamgIw1AphxR+g==",
|
| 3211 |
-
"dev": true,
|
| 3212 |
"license": "MIT",
|
| 3213 |
"dependencies": {
|
| 3214 |
"motion-dom": "^12.38.0",
|
|
@@ -5121,7 +5123,6 @@
|
|
| 5121 |
"version": "12.38.0",
|
| 5122 |
"resolved": "https://registry.npmjs.org/motion-dom/-/motion-dom-12.38.0.tgz",
|
| 5123 |
"integrity": "sha512-pdkHLD8QYRp8VfiNLb8xIBJis1byQ9gPT3Jnh2jqfFtAsWUA3dEepDlsWe/xMpO8McV+VdpKVcp+E+TGJEtOoA==",
|
| 5124 |
-
"dev": true,
|
| 5125 |
"license": "MIT",
|
| 5126 |
"dependencies": {
|
| 5127 |
"motion-utils": "^12.36.0"
|
|
@@ -5131,7 +5132,6 @@
|
|
| 5131 |
"version": "12.36.0",
|
| 5132 |
"resolved": "https://registry.npmjs.org/motion-utils/-/motion-utils-12.36.0.tgz",
|
| 5133 |
"integrity": "sha512-eHWisygbiwVvf6PZ1vhaHCLamvkSbPIeAYxWUuL3a2PD/TROgE7FvfHWTIH4vMl798QLfMw15nRqIaRDXTlYRg==",
|
| 5134 |
-
"dev": true,
|
| 5135 |
"license": "MIT"
|
| 5136 |
},
|
| 5137 |
"node_modules/ms": {
|
|
@@ -5943,7 +5943,6 @@
|
|
| 5943 |
"version": "2.8.1",
|
| 5944 |
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
| 5945 |
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
| 5946 |
-
"dev": true,
|
| 5947 |
"license": "0BSD"
|
| 5948 |
},
|
| 5949 |
"node_modules/type-check": {
|
|
|
|
| 20 |
"version": "0.0.0",
|
| 21 |
"dependencies": {
|
| 22 |
"@nexus/shared": "*",
|
| 23 |
+
"lucide-react": "^1.7.0",
|
| 24 |
"mermaid": "^11.13.0",
|
| 25 |
"react": "^19.2.4",
|
| 26 |
"react-dom": "^19.2.4",
|
|
|
|
| 49 |
"version": "0.0.0",
|
| 50 |
"dependencies": {
|
| 51 |
"@nexus/shared": "*",
|
| 52 |
+
"framer-motion": "^12.4.7",
|
| 53 |
"lucide-react": "^1.7.0",
|
| 54 |
+
"mermaid": "^11.4.1",
|
| 55 |
"react": "^19.2.4",
|
| 56 |
"react-dom": "^19.2.4",
|
| 57 |
"react-markdown": "^10.1.0",
|
|
|
|
| 383 |
"license": "Apache-2.0"
|
| 384 |
},
|
| 385 |
"node_modules/@emnapi/wasi-threads": {
|
| 386 |
+
"version": "1.2.1",
|
| 387 |
+
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
|
| 388 |
+
"integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==",
|
| 389 |
"dev": true,
|
| 390 |
"license": "MIT",
|
| 391 |
"optional": true,
|
|
|
|
| 3211 |
"version": "12.38.0",
|
| 3212 |
"resolved": "https://registry.npmjs.org/framer-motion/-/framer-motion-12.38.0.tgz",
|
| 3213 |
"integrity": "sha512-rFYkY/pigbcswl1XQSb7q424kSTQ8q6eAC+YUsSKooHQYuLdzdHjrt6uxUC+PRAO++q5IS7+TamgIw1AphxR+g==",
|
|
|
|
| 3214 |
"license": "MIT",
|
| 3215 |
"dependencies": {
|
| 3216 |
"motion-dom": "^12.38.0",
|
|
|
|
| 5123 |
"version": "12.38.0",
|
| 5124 |
"resolved": "https://registry.npmjs.org/motion-dom/-/motion-dom-12.38.0.tgz",
|
| 5125 |
"integrity": "sha512-pdkHLD8QYRp8VfiNLb8xIBJis1byQ9gPT3Jnh2jqfFtAsWUA3dEepDlsWe/xMpO8McV+VdpKVcp+E+TGJEtOoA==",
|
|
|
|
| 5126 |
"license": "MIT",
|
| 5127 |
"dependencies": {
|
| 5128 |
"motion-utils": "^12.36.0"
|
|
|
|
| 5132 |
"version": "12.36.0",
|
| 5133 |
"resolved": "https://registry.npmjs.org/motion-utils/-/motion-utils-12.36.0.tgz",
|
| 5134 |
"integrity": "sha512-eHWisygbiwVvf6PZ1vhaHCLamvkSbPIeAYxWUuL3a2PD/TROgE7FvfHWTIH4vMl798QLfMw15nRqIaRDXTlYRg==",
|
|
|
|
| 5135 |
"license": "MIT"
|
| 5136 |
},
|
| 5137 |
"node_modules/ms": {
|
|
|
|
| 5943 |
"version": "2.8.1",
|
| 5944 |
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
| 5945 |
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
|
|
|
| 5946 |
"license": "0BSD"
|
| 5947 |
},
|
| 5948 |
"node_modules/type-check": {
|
schemas/kb.py
CHANGED
|
@@ -32,11 +32,15 @@ class KBArticleResponse(KBArticleBase):
|
|
| 32 |
created_at: datetime
|
| 33 |
updated_at: datetime
|
| 34 |
score: Optional[float] = None
|
|
|
|
|
|
|
| 35 |
|
| 36 |
model_config = ConfigDict(from_attributes=True)
|
| 37 |
|
| 38 |
class KBSearchResponse(BaseModel):
|
| 39 |
results: List[KBArticleResponse]
|
|
|
|
|
|
|
| 40 |
suggestion: Optional[str] = None
|
| 41 |
expanded_queries: Optional[List[str]] = None
|
| 42 |
search_time_s: Optional[float] = None
|
|
|
|
| 32 |
created_at: datetime
|
| 33 |
updated_at: datetime
|
| 34 |
score: Optional[float] = None
|
| 35 |
+
match_type: Optional[str] = None
|
| 36 |
+
snippet: Optional[str] = None
|
| 37 |
|
| 38 |
model_config = ConfigDict(from_attributes=True)
|
| 39 |
|
| 40 |
class KBSearchResponse(BaseModel):
|
| 41 |
results: List[KBArticleResponse]
|
| 42 |
+
answer: Optional[str] = None
|
| 43 |
+
is_ai_synthetic: bool = False
|
| 44 |
suggestion: Optional[str] = None
|
| 45 |
expanded_queries: Optional[List[str]] = None
|
| 46 |
search_time_s: Optional[float] = None
|
scripts/backfill_kb_summaries.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from uuid import UUID
|
| 3 |
+
from sqlalchemy import select
|
| 4 |
+
from core.database import async_session_factory
|
| 5 |
+
from core.deps import get_arq_pool
|
| 6 |
+
from models.kb_article import KBArticle
|
| 7 |
+
from core.logging import get_logger
|
| 8 |
+
|
| 9 |
+
logger = get_logger(__name__)
|
| 10 |
+
|
| 11 |
+
async def backfill_summaries():
|
| 12 |
+
"""
|
| 13 |
+
Identifies KB articles missing AI summaries and enqueues them for re-indexing.
|
| 14 |
+
"""
|
| 15 |
+
async with async_session_factory() as db:
|
| 16 |
+
# 1. Find articles with NULL summary
|
| 17 |
+
stmt = select(KBArticle.id).where(
|
| 18 |
+
KBArticle.summary.is_(None),
|
| 19 |
+
KBArticle.deleted_at.is_(None)
|
| 20 |
+
)
|
| 21 |
+
result = await db.execute(stmt)
|
| 22 |
+
article_ids = result.scalars().all()
|
| 23 |
+
|
| 24 |
+
if not article_ids:
|
| 25 |
+
print("β
All Knowledge Base articles already have summaries.")
|
| 26 |
+
return
|
| 27 |
+
|
| 28 |
+
print(f"π Found {len(article_ids)} articles missing summaries. Enqueueing for AI processing...")
|
| 29 |
+
|
| 30 |
+
# 2. Get ARQ pool
|
| 31 |
+
# Mimic get_arq_pool dependency logic
|
| 32 |
+
import redis.asyncio as redis
|
| 33 |
+
from core.config import get_settings
|
| 34 |
+
settings = get_settings()
|
| 35 |
+
|
| 36 |
+
redis_pool = redis.from_url(settings.REDIS_URL, decode_responses=False)
|
| 37 |
+
|
| 38 |
+
# We'll use a local mock or a real one if available.
|
| 39 |
+
# But wait, I can just use the arq_pool if I can get it.
|
| 40 |
+
# For a script, I'll connect to Redis directly.
|
| 41 |
+
from arq import create_pool
|
| 42 |
+
from arq.connections import RedisSettings
|
| 43 |
+
|
| 44 |
+
# Extract host/port from REDIS_URL
|
| 45 |
+
# redis://localhost:6379/0
|
| 46 |
+
redis_settings = RedisSettings.from_dsn(settings.REDIS_URL)
|
| 47 |
+
arq_pool = await create_pool(redis_settings)
|
| 48 |
+
|
| 49 |
+
# 3. Enqueue Jobs
|
| 50 |
+
for a_id in article_ids:
|
| 51 |
+
await arq_pool.enqueue_job("index_kb_article", a_id)
|
| 52 |
+
print(f" -> Enqueued: {a_id}")
|
| 53 |
+
|
| 54 |
+
await arq_pool.close()
|
| 55 |
+
print(f"π Successfully enqueued {len(article_ids)} background tasks.")
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
asyncio.run(backfill_summaries())
|