Spaces:
Running

anycoder-cf48624d / components /KnowledgePanel.js
powerllm's picture
Upload components/KnowledgePanel.js with huggingface_hub
ce55237 verified
Raw History Blame Contribute Delete
3.38 kB
import { BookOpen, Upload, Trash2, FileJson, Plus } from 'lucide-react'
export default function KnowledgePanel({ rules, onUpload, onRemoveRule, customRulesCount, onOpenModal }) {
return (
<div className="card flex flex-col h-full">
<div className="card-header">
<div className="flex items-center space-x-2">
<BookOpen className="w-5 h-5 text-primary-400" />
<h2 className="font-semibold text-white text-sm">Knowledge Base</h2>
</div>
<span className="text-xs bg-dark-900 text-dark-400 px-2 py-1 rounded-md border border-white/5">
{rules.length} Rules
</span>
</div>
<div className="p-4 border-b border-white/5 bg-dark-900/20">
<button
onClick={onOpenModal}
className="w-full flex items-center justify-center space-x-2 py-2.5 border border-dashed border-dark-600 rounded-xl text-dark-400 hover:text-white hover:border-primary-500 hover:bg-primary-500/5 transition-all group"
>
<Plus className="w-4 h-4 group-hover:scale-110 transition-transform" />
<span className="text-sm font-medium">Add Custom Rule</span>
</button>
{customRulesCount > 0 && (
<button
onClick={() => onRemoveRule('all')}
className="w-full mt-2 flex items-center justify-center space-x-2 text-xs text-danger/70 hover:text-danger hover:bg-danger/10 py-2 rounded-lg transition-colors"
>
<Trash2 className="w-3 h-3" />
<span>Clear All Custom Rules</span>
</button>
)}
</div>
<div className="flex-1 overflow-y-auto p-4 space-y-3">
{rules.map((rule) => (
<div key={rule.id} className="group bg-dark-900/40 border border-white/5 rounded-xl p-3 hover:border-white/10 hover:bg-dark-800/60 transition-all">
<div className="flex justify-between items-start mb-2">
<div className="flex items-center space-x-2">
{rule.isCustom && <FileJson className="w-3 h-3 text-primary-400" />}
<h3 className="text-sm font-medium text-white">{rule.rule}</h3>
</div>
<div className="flex items-center space-x-2">
<span className={`text-[10px] font-bold px-2 py-0.5 rounded-full uppercase tracking-wider ${
rule.action === 'LONG' ? 'bg-success/10 text-success' :
rule.action === 'SHORT' ? 'bg-danger/10 text-danger' :
'bg-primary-500/10 text-primary-400'
}`}>
{rule.action}
</span>
{rule.isCustom && (
<button
onClick={() => onRemoveRule(rule.id)}
className="text-dark-500 hover:text-danger transition-colors opacity-0 group-hover:opacity-100"
>
<Trash2 className="w-3 h-3" />
</button>
)}
</div>
</div>
<div className="text-xs text-dark-400 font-mono bg-dark-950/50 p-2 rounded border border-white/5 mb-2 truncate">
IF {rule.condition}
</div>
<p className="text-xs text-dark-500 leading-relaxed">
{rule.description}
</p>
</div>
))}
</div>
</div>
)
}