Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/pages/AnalyzePage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState, useEffect } from 'react'
import ReactMarkdown from 'react-markdown'
import { categorizeMessage } from '../utils/llmHelper'
import { calculateUrgency } from '../utils/urgencyScorer'
import { getRecommendedAction } from '../utils/templates'
import { calculateUrgency, normalizeUrgency } from '../utils/urgencyScorer'
import { getRecommendedAction, normalizeCategory } from '../utils/templates'

function AnalyzePage() {
const [message, setMessage] = useState('')
Expand Down Expand Up @@ -30,16 +30,17 @@ function AnalyzePage() {
try {
// Run categorization (LLM call)
const { category, reasoning } = await categorizeMessage(message)
const normalizedCategory = normalizeCategory(category)

// Calculate urgency (rule-based)
const urgency = calculateUrgency(message)
const urgency = normalizeUrgency(normalizedCategory, calculateUrgency(message))

// Get recommended action (template-based)
const recommendedAction = getRecommendedAction(category)
const recommendedAction = getRecommendedAction(normalizedCategory)

const analysisResult = {
message,
category,
category: normalizedCategory,
urgency,
recommendedAction,
reasoning,
Expand Down
9 changes: 8 additions & 1 deletion src/pages/DashboardPage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useState, useEffect } from 'react'
import { normalizeCategory } from '../utils/templates'
import { normalizeUrgency } from '../utils/urgencyScorer'

function DashboardPage() {
const [stats, setStats] = useState({
Expand All @@ -15,7 +17,12 @@ function DashboardPage() {
}, [])

const loadDashboardData = () => {
const history = JSON.parse(localStorage.getItem('triageHistory') || '[]')
const history = JSON.parse(localStorage.getItem('triageHistory') || '[]').map(item => ({
...item,
category: normalizeCategory(item.category),
urgency: normalizeUrgency(normalizeCategory(item.category), item.urgency)
}))
localStorage.setItem('triageHistory', JSON.stringify(history))
const today = new Date().toDateString()
const todayMessages = history.filter(item =>
new Date(item.timestamp).toDateString() === today
Expand Down
16 changes: 12 additions & 4 deletions src/pages/HistoryPage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useState, useEffect } from 'react'
import ReactMarkdown from 'react-markdown'
import { normalizeCategory } from '../utils/templates'
import { normalizeUrgency } from '../utils/urgencyScorer'

function HistoryPage() {
const [history, setHistory] = useState([])
Expand All @@ -12,7 +14,13 @@ function HistoryPage() {

const loadHistory = () => {
const savedHistory = JSON.parse(localStorage.getItem('triageHistory') || '[]')
setHistory(savedHistory)
const normalizedHistory = savedHistory.map(item => ({
...item,
category: normalizeCategory(item.category),
urgency: normalizeUrgency(normalizeCategory(item.category), item.urgency)
}))
setHistory(normalizedHistory)
localStorage.setItem('triageHistory', JSON.stringify(normalizedHistory))
}

const clearHistory = () => {
Expand All @@ -28,9 +36,9 @@ function HistoryPage() {

const filteredHistory = filter === 'all'
? sortedHistory
: sortedHistory.filter(item => item.category === filter)
: sortedHistory.filter(item => normalizeCategory(item.category) === filter)

const categories = [...new Set(history.map(item => item.category))]
const categories = [...new Set(history.map(item => normalizeCategory(item.category)))]

return (
<div className="min-h-screen bg-gray-50 py-8">
Expand Down Expand Up @@ -118,7 +126,7 @@ function HistoryPage() {
</div>
<div className="flex items-center space-x-2">
<span className="text-xs bg-blue-100 text-blue-800 px-3 py-1 rounded-full font-semibold">
{item.category}
{normalizeCategory(item.category)}
</span>
<span className={`text-xs px-3 py-1 rounded-full font-semibold ${
item.urgency === 'High' ? 'bg-red-200 text-red-900' :
Expand Down
11 changes: 9 additions & 2 deletions src/pages/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Link } from 'react-router-dom'
import { useEffect, useState } from 'react'
import { normalizeCategory } from '../utils/templates'
import { normalizeUrgency } from '../utils/urgencyScorer'

function HomePage() {
const [stats, setStats] = useState({ total: 0, today: 0 })
const [recentActivity, setRecentActivity] = useState([])

useEffect(() => {
// Load stats from localStorage
const history = JSON.parse(localStorage.getItem('triageHistory') || '[]')
const history = JSON.parse(localStorage.getItem('triageHistory') || '[]').map(item => ({
...item,
category: normalizeCategory(item.category),
urgency: normalizeUrgency(normalizeCategory(item.category), item.urgency)
}))
localStorage.setItem('triageHistory', JSON.stringify(history))
const today = new Date().toDateString()
const todayCount = history.filter(item =>
new Date(item.timestamp).toDateString() === today
Expand Down Expand Up @@ -109,7 +116,7 @@ function HomePage() {
</div>
<div className="flex items-center space-x-2 mt-1">
<span className="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded">
{item.category}
{normalizeCategory(item.category)}
</span>
<span className={`text-xs px-2 py-1 rounded ${
item.urgency === 'High' ? 'bg-red-100 text-red-800' :
Expand Down
2 changes: 1 addition & 1 deletion src/utils/llmHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function categorizeMessage(message) {
const content = response.choices[0].message.content;

const lines = content.split('\n');
let category = "Unknown";
let category = 'Contact Customer';
let reasoning = content;

if (content.toLowerCase().includes('billing')) {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const actionTemplates = {
"Technical Problem": "Suggest user to restart their browser.",
"General Inquiry": "Respond with FAQ link.",
"Feature Request": "Ask user to check billing portal.",
"Unknown": "Review manually."
"Contact Customer": "Review manually."
}

export function normalizeCategory(category) {
return category === 'Unknown' ? 'Contact Customer' : category
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/utils/urgencyScorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ export function calculateUrgency(message) {
if (urgencyScore < 30) return "Low"
return "Medium"
}

export function normalizeUrgency(category, urgency) {
return category === 'Contact Customer' ? 'High' : urgency
}
3 changes: 3 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 3000,
},
})