'use client'; /** * Step 3: Knowledge Base * - Add knowledge chunks * - Edit/remove chunks * - Optional step */ import { useState } from 'react'; import type { KnowledgeChunkDraft } from '@/lib/hooks/useBotBuilder'; import { TextBox } from '@/components/forms/TextBox'; interface StepKnowledgeProps { chunks: KnowledgeChunkDraft[]; onAdd: (chunk: Omit) => void; onRemove: (id: string) => void; onUpdate: (id: string, data: Partial>) => void; } interface ChunkFormData { topic: string; content: string; keywords: string; } const EMPTY_FORM: ChunkFormData = { topic: '', content: '', keywords: '' }; export function StepKnowledge({ chunks, onAdd, onRemove, onUpdate }: StepKnowledgeProps) { const [formData, setFormData] = useState(EMPTY_FORM); const [editingId, setEditingId] = useState(null); const [isAdding, setIsAdding] = useState(false); const handleSubmit = () => { if (!formData.content.trim()) return; const chunk = { topic: formData.topic.trim(), content: formData.content.trim(), keywords: formData.keywords .split(',') .map((k) => k.trim()) .filter(Boolean), }; if (editingId) { onUpdate(editingId, chunk); setEditingId(null); } else { onAdd(chunk); } setFormData(EMPTY_FORM); setIsAdding(false); }; const handleEdit = (chunk: KnowledgeChunkDraft) => { setFormData({ topic: chunk.topic, content: chunk.content, keywords: chunk.keywords.join(', '), }); setEditingId(chunk.id); setIsAdding(true); }; const handleCancel = () => { setFormData(EMPTY_FORM); setEditingId(null); setIsAdding(false); }; return (

Knowledge Base

Add information your bot should know. This is optional but helps your bot give more accurate, domain-specific answers.

{/* Add/Edit Form */} {isAdding ? (
setFormData({ ...formData, topic })} placeholder="e.g., Compensation Policy, Interview Process" maxLength={200} />
Content * } id="content" value={formData.content} onValueChange={(content) => setFormData({ ...formData, content })} placeholder="Enter the knowledge content. This could be a policy, procedure, FAQ answer, or any information your bot should know..." rows={6} maxLength={10000} required hint={`${formData.content.length}/10,000 characters`} />
setFormData({ ...formData, keywords: e.target.value })} placeholder="compensation, salary, bonus (comma-separated)" className="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:ring-blue-500" />

Comma-separated keywords for better search

) : ( )} {/* Knowledge List */} {chunks.length > 0 && (

Knowledge Chunks ({chunks.length})

{chunks.map((chunk) => (
{chunk.topic && (

{chunk.topic}

)}

{chunk.content}

{chunk.keywords.length > 0 && (
{chunk.keywords.slice(0, 5).map((keyword) => ( {keyword} ))} {chunk.keywords.length > 5 && ( +{chunk.keywords.length - 5} more )}
)}
))}
)} {/* Empty state */} {chunks.length === 0 && !isAdding && (

No knowledge added yet

This step is optional. You can add knowledge later.

)}
); }