Spaces:
Paused

dushyantsingh0 commited on
Commit
5f57775
·
1 Parent(s): 62bed67

backend stabilization

Browse files
frontend/apps/internal/src/components/KnowledgeBase.module.css CHANGED
@@ -567,4 +567,199 @@
567
  color: #1E293B;
568
  font-weight: 500;
569
  font-style: italic;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
570
  }
 
567
  color: #1E293B;
568
  font-weight: 500;
569
  font-style: italic;
570
+ }
571
+
572
+ /* 6. AI Growth Center Enhancements */
573
+ .headerTabs {
574
+ display: flex;
575
+ gap: 4px;
576
+ background: rgba(255, 255, 255, 0.1);
577
+ padding: 4px;
578
+ border-radius: 12px;
579
+ margin-bottom: 24px;
580
+ width: fit-content;
581
+ border: 1px solid rgba(255, 255, 255, 0.1);
582
+ }
583
+
584
+ .tab {
585
+ padding: 8px 20px;
586
+ border-radius: 8px;
587
+ border: none;
588
+ background: none;
589
+ color: rgba(255, 255, 255, 0.6);
590
+ font-size: 11px;
591
+ font-weight: 800;
592
+ cursor: pointer;
593
+ transition: all 0.2s;
594
+ display: flex;
595
+ align-items: center;
596
+ gap: 8px;
597
+ }
598
+
599
+ .tab.activeTab {
600
+ background: white;
601
+ color: var(--primary);
602
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
603
+ }
604
+
605
+ .growthGrid {
606
+ display: grid;
607
+ grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
608
+ gap: 32px;
609
+ }
610
+
611
+ .insightCard {
612
+ background: white;
613
+ border: 1px solid var(--border-subtle);
614
+ border-radius: var(--radius-lg);
615
+ padding: 32px;
616
+ display: flex;
617
+ flex-direction: column;
618
+ gap: 24px;
619
+ position: relative;
620
+ overflow: hidden;
621
+ transition: all 0.3s;
622
+ }
623
+
624
+ .insightCard::after {
625
+ content: '';
626
+ position: absolute;
627
+ top: 0;
628
+ right: 0;
629
+ width: 100px;
630
+ height: 100px;
631
+ background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.05) 0%, transparent 70%);
632
+ pointer-events: none;
633
+ }
634
+
635
+ .insightContent h3 {
636
+ font-size: 20px;
637
+ font-weight: 800;
638
+ color: var(--text-main);
639
+ margin-bottom: 8px;
640
+ }
641
+
642
+ .insightType {
643
+ font-size: 10px;
644
+ font-weight: 900;
645
+ color: var(--primary);
646
+ text-transform: uppercase;
647
+ letter-spacing: 0.1em;
648
+ display: block;
649
+ margin-bottom: 16px;
650
+ }
651
+
652
+ .reasoningBox {
653
+ background: #F8FAFC;
654
+ padding: 16px;
655
+ border-radius: 12px;
656
+ border-left: 3px solid var(--primary);
657
+ }
658
+
659
+ .reasoningLabel {
660
+ display: block;
661
+ font-size: 10px;
662
+ font-weight: 900;
663
+ color: var(--text-muted);
664
+ margin-bottom: 6px;
665
+ }
666
+
667
+ .reasoningText {
668
+ font-size: 13px;
669
+ color: var(--text-main);
670
+ line-height: 1.5;
671
+ font-style: italic;
672
+ }
673
+
674
+ .confidenceSection {
675
+ display: flex;
676
+ flex-direction: column;
677
+ gap: 8px;
678
+ }
679
+
680
+ .confHeader {
681
+ display: flex;
682
+ justify-content: space-between;
683
+ align-items: center;
684
+ }
685
+
686
+ .confHeader label {
687
+ font-size: 10px;
688
+ font-weight: 900;
689
+ color: var(--text-muted);
690
+ }
691
+
692
+ .confValue {
693
+ font-size: 12px;
694
+ font-weight: 800;
695
+ color: var(--primary);
696
+ }
697
+
698
+ .confMeter {
699
+ height: 6px;
700
+ background: #E2E8F0;
701
+ border-radius: 3px;
702
+ overflow: hidden;
703
+ }
704
+
705
+ .confFill {
706
+ height: 100%;
707
+ background: linear-gradient(to right, #818CF8, #6366F1);
708
+ border-radius: 3px;
709
+ }
710
+
711
+ .insightActions {
712
+ display: flex;
713
+ gap: 12px;
714
+ margin-top: auto;
715
+ }
716
+
717
+ .applyBtn {
718
+ flex: 2;
719
+ background: var(--primary);
720
+ color: white;
721
+ border: none;
722
+ padding: 12px;
723
+ border-radius: 10px;
724
+ font-weight: 800;
725
+ font-size: 12px;
726
+ cursor: pointer;
727
+ display: flex;
728
+ align-items: center;
729
+ justify-content: center;
730
+ gap: 8px;
731
+ transition: all 0.2s;
732
+ }
733
+
734
+ .applyBtn:hover {
735
+ background: #4F46E5;
736
+ transform: translateY(-2px);
737
+ box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
738
+ }
739
+
740
+ .dismissBtn {
741
+ flex: 1;
742
+ background: #F1F5F9;
743
+ color: #64748B;
744
+ border: none;
745
+ padding: 12px;
746
+ border-radius: 10px;
747
+ font-weight: 800;
748
+ font-size: 11px;
749
+ cursor: pointer;
750
+ transition: all 0.2s;
751
+ }
752
+
753
+ .dismissBtn:hover {
754
+ background: #E2E8F0;
755
+ color: #475569;
756
+ }
757
+
758
+ .sourceTag {
759
+ font-size: 9px;
760
+ font-weight: 700;
761
+ color: var(--text-muted);
762
+ background: #F1F5F9;
763
+ padding: 2px 6px;
764
+ border-radius: 4px;
765
  }
frontend/apps/internal/src/components/KnowledgeBase.tsx CHANGED
@@ -82,6 +82,11 @@ export const KnowledgeBase: React.FC = () => {
82
  const [suggestions, setSuggestions] = useState<string[]>([]);
83
  const [aiSuggestion, setAiSuggestion] = useState<string | null>(null);
84
 
 
 
 
 
 
85
  // 1. Fetch Categories
86
  const fetchCategories = useCallback(async () => {
87
  try {
@@ -119,11 +124,30 @@ export const KnowledgeBase: React.FC = () => {
119
  }
120
  }, []);
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  useEffect(() => {
123
  fetchCategories();
124
  fetchArticles('', 'All');
125
  }, [fetchCategories, fetchArticles]);
126
 
 
 
 
 
 
 
127
  const handleSearchTrigger = (e?: React.FormEvent) => {
128
  if (e) e.preventDefault();
129
  setActiveQuery(searchInput);
@@ -199,6 +223,27 @@ export const KnowledgeBase: React.FC = () => {
199
  }
200
  };
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  // Pagination Logic
203
  const totalPages = Math.ceil(articles.length / itemsPerPage);
204
  const paginatedArticles = articles.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage);
@@ -208,8 +253,28 @@ export const KnowledgeBase: React.FC = () => {
208
  <header className={styles.missionBanner}>
209
  <div className={styles.bannerContent}>
210
  <div className={styles.headerBadge}>MISSION CORE</div>
211
- <h1>Knowledge Library</h1>
212
- <p className={styles.description}>Strategic intelligence gathering and architectural documentation.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
  <form className={styles.searchControls} onSubmit={handleSearchTrigger}>
215
  <div className={styles.searchWrapper}>
@@ -271,7 +336,69 @@ export const KnowledgeBase: React.FC = () => {
271
 
272
  <div className={styles.contentArea}>
273
  <AnimatePresence mode="wait">
274
- {loading && articles.length === 0 ? (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  <motion.div key="loading" initial={{ opacity: 0 }} animate={{ opacity: 1 }} className={styles.emptyState}>
276
  <div className={styles.loadingPulse} />
277
  <p>Syncing Library Telemetry...</p>
 
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');
87
+ const [insights, setInsights] = useState<any[]>([]);
88
+ const [insightsLoading, setInsightsLoading] = useState(false);
89
+
90
  // 1. Fetch Categories
91
  const fetchCategories = useCallback(async () => {
92
  try {
 
124
  }
125
  }, []);
126
 
127
+ // 3. Fetch Insights
128
+ const fetchInsights = useCallback(async () => {
129
+ setInsightsLoading(true);
130
+ try {
131
+ const resp = await api.get('kb_insights/');
132
+ setInsights(resp.data);
133
+ } catch (err) {
134
+ console.error('Failed to fetch insights:', err);
135
+ } finally {
136
+ setInsightsLoading(false);
137
+ }
138
+ }, []);
139
+
140
  useEffect(() => {
141
  fetchCategories();
142
  fetchArticles('', 'All');
143
  }, [fetchCategories, fetchArticles]);
144
 
145
+ useEffect(() => {
146
+ if (activeTab === 'growth') {
147
+ fetchInsights();
148
+ }
149
+ }, [activeTab, fetchInsights]);
150
+
151
  const handleSearchTrigger = (e?: React.FormEvent) => {
152
  if (e) e.preventDefault();
153
  setActiveQuery(searchInput);
 
223
  }
224
  };
225
 
226
+ // Insight Actions
227
+ const handleApplyInsight = async (insight: any) => {
228
+ try {
229
+ await api.post(`kb_insights/${insight.id}/apply/`);
230
+ setInsights(prev => prev.filter(i => i.id !== insight.id));
231
+ setActiveTab('library');
232
+ fetchArticles('', selectedCategory);
233
+ } catch (err) {
234
+ console.error('Failed to apply insight:', err);
235
+ }
236
+ };
237
+
238
+ const handleDismissInsight = async (id: string) => {
239
+ try {
240
+ await api.post(`kb_insights/${id}/dismiss/`);
241
+ setInsights(prev => prev.filter(i => i.id !== id));
242
+ } catch (err) {
243
+ console.error('Failed to dismiss insight:', err);
244
+ }
245
+ };
246
+
247
  // Pagination Logic
248
  const totalPages = Math.ceil(articles.length / itemsPerPage);
249
  const paginatedArticles = articles.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage);
 
253
  <header className={styles.missionBanner}>
254
  <div className={styles.bannerContent}>
255
  <div className={styles.headerBadge}>MISSION CORE</div>
256
+
257
+ <div className={styles.headerTabs}>
258
+ <button
259
+ className={`${styles.tab} ${activeTab === 'library' ? styles.activeTab : ''}`}
260
+ onClick={() => setActiveTab('library')}
261
+ >
262
+ <Globe size={14} /> LIBRARY
263
+ </button>
264
+ <button
265
+ className={`${styles.tab} ${activeTab === 'growth' ? styles.activeTab : ''}`}
266
+ onClick={() => setActiveTab('growth')}
267
+ >
268
+ <Sparkles size={14} /> AI GROWTH CENTER
269
+ </button>
270
+ </div>
271
+
272
+ <h1>{activeTab === 'library' ? 'Knowledge Library' : 'Knowledge Growth'}</h1>
273
+ <p className={styles.description}>
274
+ {activeTab === 'library'
275
+ ? 'Strategic intelligence gathering and architectural documentation.'
276
+ : 'AI-detected blindspots and performance-driven documentation suggestions.'}
277
+ </p>
278
 
279
  <form className={styles.searchControls} onSubmit={handleSearchTrigger}>
280
  <div className={styles.searchWrapper}>
 
336
 
337
  <div className={styles.contentArea}>
338
  <AnimatePresence mode="wait">
339
+ {activeTab === 'growth' ? (
340
+ <motion.div
341
+ key="growth"
342
+ className={styles.growthGrid}
343
+ initial={{ opacity: 0, y: 20 }}
344
+ animate={{ opacity: 1, y: 0 }}
345
+ exit={{ opacity: 0, y: -20 }}
346
+ >
347
+ {insightsLoading ? (
348
+ <div className={styles.emptyState}>
349
+ <div className={styles.loadingPulse} />
350
+ <p>Scanning knowledge topology for gaps...</p>
351
+ </div>
352
+ ) : insights.length === 0 ? (
353
+ <div className={styles.emptyState}>
354
+ <ShieldCheck size={48} color="var(--primary)" />
355
+ <h3>Knowledge Equilibrium Reached</h3>
356
+ <p>AI has not detected any significant blindspots in current ticket resolutions.</p>
357
+ </div>
358
+ ) : (
359
+ insights.map((insight) => (
360
+ <motion.div key={insight.id} className={styles.insightCard}>
361
+ <span className={styles.insightType}>{insight.insight_type.replace('_', ' ')}</span>
362
+ <div className={styles.insightContent}>
363
+ <h3>{insight.suggested_title}</h3>
364
+ <div className={styles.reasoningBox}>
365
+ <span className={styles.reasoningLabel}>AI REASONING</span>
366
+ <p className={styles.reasoningText}>{insight.reasoning}</p>
367
+ </div>
368
+ </div>
369
+
370
+ <div className={styles.confidenceSection}>
371
+ <div className={styles.confHeader}>
372
+ <label>CONFIDENCE LEVEL</label>
373
+ <span className={styles.confValue}>{Math.round(insight.confidence_score * 100)}%</span>
374
+ </div>
375
+ <div className={styles.confMeter}>
376
+ <div
377
+ className={styles.confFill}
378
+ style={{ width: `${insight.confidence_score * 100}%` }}
379
+ />
380
+ </div>
381
+ </div>
382
+
383
+ <div className={styles.insightActions}>
384
+ <button
385
+ className={styles.applyBtn}
386
+ onClick={() => handleApplyInsight(insight)}
387
+ >
388
+ <Send size={14} /> DEPLOY DRAFT
389
+ </button>
390
+ <button
391
+ className={styles.dismissBtn}
392
+ onClick={() => handleDismissInsight(insight.id)}
393
+ >
394
+ DISMISS
395
+ </button>
396
+ </div>
397
+ </motion.div>
398
+ ))
399
+ )}
400
+ </motion.div>
401
+ ) : loading && articles.length === 0 ? (
402
  <motion.div key="loading" initial={{ opacity: 0 }} animate={{ opacity: 1 }} className={styles.emptyState}>
403
  <div className={styles.loadingPulse} />
404
  <p>Syncing Library Telemetry...</p>