import { useMemo, useState } from "react"; import { FloppyDisk, Lightbulb, NotePencil, Trash } from "../ui/icons"; import type { KnowledgeEntryRecord } from "@shared/types"; import { ActionButton, ConfirmDialog, InlineNotice, Input, ListFrame, ListRow, Modal, Select, StatusPill, TextArea } from "../ui"; import { useT } from "../../i18n"; import { knowledgeCategoryOptions, importanceOptions, splitTags, parseTags } from "./helpers"; import { SectionHeader } from "./SectionHeader"; import { NEW_ENTITY_ID } from "../../lib/constants"; function KnowledgeEditor({ companyId, entry, onSaved }: { companyId: string; entry: KnowledgeEntryRecord | null; onSaved: () => Promise; }) { const [topic, setTopic] = useState(entry?.topic ?? ""); const [category, setCategory] = useState(entry?.category ?? "technical"); const [importance, setImportance] = useState(entry?.importance ?? "medium"); const [content, setContent] = useState(entry?.content ?? ""); const [tags, setTags] = useState(parseTags(entry?.tagsJson ?? "[]")); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); async function save() { if (!topic.trim() || !content.trim()) { setError("Topic and content are required."); return; } setSaving(true); setError(null); try { const result = await window.agentCompany.saveKnowledgeEntry({ id: entry?.id ?? null, companyId, category: category as Parameters[0]["category"], topic: topic.trim(), content: content.trim(), authorAgentId: entry?.authorAgentId ?? null, importance: importance as Parameters[0]["importance"], tagsJson: splitTags(tags), referencedEntityType: entry?.referencedEntityType ?? null, referencedEntityId: entry?.referencedEntityId ?? null, }); if (!result.ok) { setError(result.error.message); return; } await onSaved(); } finally { setSaving(false); } } return (
{error ? : null}
setImportance(value as typeof importance)} options={importanceOptions} />