Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
3cd2dfd
1
Parent(s): 30c470c
backend stabilisation
Browse files
api/v1/kb.py
CHANGED
|
@@ -25,11 +25,51 @@ from core.cache import (
|
|
| 25 |
SemanticCacheManager, invalidate_cache, delete_by_pattern,
|
| 26 |
invalidate_workspace_semantic_cache, get_cached_object, set_cached_object
|
| 27 |
)
|
| 28 |
-
from schemas.kb import
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
router = APIRouter()
|
| 31 |
logger = get_logger(__name__)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# AI Lifecycle is now handled by arq worker task: index_kb_article
|
| 34 |
|
| 35 |
@router.post("/", response_model=KBArticleResponse, status_code=status.HTTP_201_CREATED, dependencies=[Depends(require_roles(ALL_SC_ROLES))])
|
|
|
|
| 25 |
SemanticCacheManager, invalidate_cache, delete_by_pattern,
|
| 26 |
invalidate_workspace_semantic_cache, get_cached_object, set_cached_object
|
| 27 |
)
|
| 28 |
+
from schemas.kb import (
|
| 29 |
+
KBArticleCreate, KBArticleResponse, KBArticleUpdate, KBSearchResponse,
|
| 30 |
+
KBBulkActionRequest, KBBulkSyncRequest, KBAutoDraftRequest, KBAutoDraftResponse
|
| 31 |
+
)
|
| 32 |
|
| 33 |
router = APIRouter()
|
| 34 |
logger = get_logger(__name__)
|
| 35 |
|
| 36 |
+
@router.post("/autodraft/", response_model=KBAutoDraftResponse, dependencies=[Depends(require_roles(ALL_SC_ROLES))])
|
| 37 |
+
async def autodraft_kb_article(
|
| 38 |
+
payload: KBAutoDraftRequest,
|
| 39 |
+
current_user: User = Depends(get_current_user),
|
| 40 |
+
db: AsyncSession = Depends(get_db)
|
| 41 |
+
) -> Any:
|
| 42 |
+
"""AI-powered markdown formatter for KB articles."""
|
| 43 |
+
try:
|
| 44 |
+
from core.llm import get_llm
|
| 45 |
+
from langchain_core.messages import SystemMessage, HumanMessage
|
| 46 |
+
|
| 47 |
+
llm = get_llm(timeout=120)
|
| 48 |
+
prompt = [
|
| 49 |
+
SystemMessage(content=(
|
| 50 |
+
"You are a technical documentation expert. Your task is to REFORMAT the provided markdown content "
|
| 51 |
+
"to ensure it follows best practices for technical documentation.\n\n"
|
| 52 |
+
"Rules:\n"
|
| 53 |
+
"1. DO NOT change the technical meaning or remove any information.\n"
|
| 54 |
+
"2. Ensure consistent heading levels (H1 for title, H2 for main sections, H3 for sub-sections).\n"
|
| 55 |
+
"3. Fix inconsistent lists and ensure they are properly indented.\n"
|
| 56 |
+
"4. Ensure code blocks have appropriate language tags if they can be inferred.\n"
|
| 57 |
+
"5. Correct common markdown syntax errors.\n"
|
| 58 |
+
"6. Make the documentation more readable by adding logical breaks if necessary.\n"
|
| 59 |
+
"7. Keep the tone professional and technical.\n"
|
| 60 |
+
"8. Return ONLY the reformatted markdown content."
|
| 61 |
+
)),
|
| 62 |
+
HumanMessage(content=f"Reformat this markdown content:\n\n{payload.content}")
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
resp = await llm.ainvoke(prompt)
|
| 66 |
+
formatted_content = resp.content.strip()
|
| 67 |
+
|
| 68 |
+
return KBAutoDraftResponse(formatted_content=formatted_content)
|
| 69 |
+
except Exception as e:
|
| 70 |
+
logger.error(f"Auto-drafting failed: {e}")
|
| 71 |
+
raise HTTPException(status_code=500, detail=f"Neural formatting failed: {str(e)}")
|
| 72 |
+
|
| 73 |
# AI Lifecycle is now handled by arq worker task: index_kb_article
|
| 74 |
|
| 75 |
@router.post("/", response_model=KBArticleResponse, status_code=status.HTTP_201_CREATED, dependencies=[Depends(require_roles(ALL_SC_ROLES))])
|
frontend/apps/internal/src/App.tsx
CHANGED
|
@@ -132,6 +132,8 @@ function AuthenticatedPortal({ user, authLoading, logout, refreshUser, hasRole }
|
|
| 132 |
const root = document.documentElement;
|
| 133 |
root.style.setProperty('--primary', primary);
|
| 134 |
root.style.setProperty('--accent', primary);
|
|
|
|
|
|
|
| 135 |
root.style.setProperty('--primary-glow', glow);
|
| 136 |
root.style.setProperty('--banner-gradient', gradient);
|
| 137 |
|
|
|
|
| 132 |
const root = document.documentElement;
|
| 133 |
root.style.setProperty('--primary', primary);
|
| 134 |
root.style.setProperty('--accent', primary);
|
| 135 |
+
root.style.setProperty('--accent-dim', glow);
|
| 136 |
+
root.style.setProperty('--accent-bright', primary); // Fallback to primary if bright not calculated
|
| 137 |
root.style.setProperty('--primary-glow', glow);
|
| 138 |
root.style.setProperty('--banner-gradient', gradient);
|
| 139 |
|
frontend/apps/internal/src/components/KnowledgeBase.module.css
CHANGED
|
@@ -752,6 +752,48 @@
|
|
| 752 |
opacity: 1;
|
| 753 |
}
|
| 754 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 755 |
/* Fixed Layout Containers */
|
| 756 |
.dossierBody {
|
| 757 |
flex: 1;
|
|
|
|
| 752 |
opacity: 1;
|
| 753 |
}
|
| 754 |
|
| 755 |
+
.autoDraftBtn {
|
| 756 |
+
background: var(--primary-glow);
|
| 757 |
+
color: var(--primary);
|
| 758 |
+
border: 1px solid var(--primary-subtle, rgba(124, 58, 237, 0.2));
|
| 759 |
+
padding: 4px 10px;
|
| 760 |
+
border-radius: 6px;
|
| 761 |
+
font-size: 9px;
|
| 762 |
+
font-weight: 800;
|
| 763 |
+
cursor: pointer;
|
| 764 |
+
display: flex;
|
| 765 |
+
align-items: center;
|
| 766 |
+
gap: 6px;
|
| 767 |
+
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
| 768 |
+
text-transform: uppercase;
|
| 769 |
+
letter-spacing: 0.02em;
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
.autoDraftBtn:hover:not(:disabled) {
|
| 773 |
+
background: var(--primary);
|
| 774 |
+
color: white;
|
| 775 |
+
transform: translateY(-1px);
|
| 776 |
+
box-shadow: 0 4px 12px rgba(124, 58, 237, 0.2);
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
.autoDraftBtn:disabled {
|
| 780 |
+
opacity: 0.6;
|
| 781 |
+
cursor: not-allowed;
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
.btnPulse {
|
| 785 |
+
animation: btnPulseAnim 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
@keyframes btnPulseAnim {
|
| 789 |
+
0%, 100% {
|
| 790 |
+
opacity: 1;
|
| 791 |
+
}
|
| 792 |
+
50% {
|
| 793 |
+
opacity: 0.5;
|
| 794 |
+
}
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
/* Fixed Layout Containers */
|
| 798 |
.dossierBody {
|
| 799 |
flex: 1;
|
frontend/apps/internal/src/components/KnowledgeBase.tsx
CHANGED
|
@@ -389,6 +389,25 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ workspaceId }) =>
|
|
| 389 |
|
| 390 |
const [isSaving, setIsSaving] = useState(false);
|
| 391 |
const [saveStatus, setSaveStatus] = useState<'idle' | 'success' | 'error'>('idle');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
const handleSaveDossier = async () => {
|
| 394 |
setIsSaving(true);
|
|
@@ -1006,6 +1025,17 @@ export const KnowledgeBase: React.FC<KnowledgeBaseProps> = ({ workspaceId }) =>
|
|
| 1006 |
</button>
|
| 1007 |
</div>
|
| 1008 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1009 |
{canShred && (
|
| 1010 |
<button className={styles.miniRetract} onClick={() => selectedArticle && handleDeleteArticle(selectedArticle.id)}>
|
| 1011 |
<Trash2 size={12} /> SHRED
|
|
|
|
| 389 |
|
| 390 |
const [isSaving, setIsSaving] = useState(false);
|
| 391 |
const [saveStatus, setSaveStatus] = useState<'idle' | 'success' | 'error'>('idle');
|
| 392 |
+
const [isAutoDrafting, setIsAutoDrafting] = useState(false);
|
| 393 |
+
|
| 394 |
+
const handleAutoDraft = async () => {
|
| 395 |
+
if (!editContent.trim()) return;
|
| 396 |
+
|
| 397 |
+
setIsAutoDrafting(true);
|
| 398 |
+
try {
|
| 399 |
+
const resp = await api.post('kb/autodraft/', { content: editContent });
|
| 400 |
+
if (resp.data.formatted_content) {
|
| 401 |
+
setEditContent(resp.data.formatted_content);
|
| 402 |
+
alert('Neural formatting applied successfully.', { type: 'success', title: 'Auto Draft' });
|
| 403 |
+
}
|
| 404 |
+
} catch (err) {
|
| 405 |
+
console.error('Auto draft failed:', err);
|
| 406 |
+
alert('Failed to apply neural formatting.', { type: 'error', title: 'System Error' });
|
| 407 |
+
} finally {
|
| 408 |
+
setIsAutoDrafting(false);
|
| 409 |
+
}
|
| 410 |
+
};
|
| 411 |
|
| 412 |
const handleSaveDossier = async () => {
|
| 413 |
setIsSaving(true);
|
|
|
|
| 1025 |
</button>
|
| 1026 |
</div>
|
| 1027 |
</div>
|
| 1028 |
+
<div className={styles.toolbarGroup}>
|
| 1029 |
+
<button
|
| 1030 |
+
className={`${styles.autoDraftBtn} ${isAutoDrafting ? styles.btnPulse : ''}`}
|
| 1031 |
+
onClick={handleAutoDraft}
|
| 1032 |
+
disabled={isAutoDrafting}
|
| 1033 |
+
title="Apply neural formatting to content"
|
| 1034 |
+
>
|
| 1035 |
+
{isAutoDrafting ? <Radio size={12} className={styles.spin} /> : <Sparkles size={12} />}
|
| 1036 |
+
{isAutoDrafting ? 'FORMATTING...' : 'AUTO DRAFT'}
|
| 1037 |
+
</button>
|
| 1038 |
+
</div>
|
| 1039 |
{canShred && (
|
| 1040 |
<button className={styles.miniRetract} onClick={() => selectedArticle && handleDeleteArticle(selectedArticle.id)}>
|
| 1041 |
<Trash2 size={12} /> SHRED
|
frontend/apps/internal/src/components/OnboardingModal.module.css
CHANGED
|
@@ -245,9 +245,9 @@
|
|
| 245 |
}
|
| 246 |
|
| 247 |
.btnPrimary:hover {
|
| 248 |
-
|
| 249 |
transform: translateY(-2px);
|
| 250 |
-
box-shadow: 0 8px 24px var(--
|
| 251 |
}
|
| 252 |
|
| 253 |
.btnPrimary:disabled {
|
|
|
|
| 245 |
}
|
| 246 |
|
| 247 |
.btnPrimary:hover {
|
| 248 |
+
filter: brightness(1.1);
|
| 249 |
transform: translateY(-2px);
|
| 250 |
+
box-shadow: 0 8px 24px var(--primary-glow);
|
| 251 |
}
|
| 252 |
|
| 253 |
.btnPrimary:disabled {
|
schemas/kb.py
CHANGED
|
@@ -80,3 +80,9 @@ class KnowledgeInsightUpdate(BaseModel):
|
|
| 80 |
status: Optional[InsightStatus] = None
|
| 81 |
suggested_title: Optional[str] = None
|
| 82 |
suggested_content: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
status: Optional[InsightStatus] = None
|
| 81 |
suggested_title: Optional[str] = None
|
| 82 |
suggested_content: Optional[str] = None
|
| 83 |
+
|
| 84 |
+
class KBAutoDraftRequest(BaseModel):
|
| 85 |
+
content: str
|
| 86 |
+
|
| 87 |
+
class KBAutoDraftResponse(BaseModel):
|
| 88 |
+
formatted_content: str
|