module.exports=[87981,a=>{"use strict";var b=a.i(87924),c=a.i(50944),d=a.i(72131);function e(){let a=(0,c.useParams)().botId,[e,f]=(0,d.useState)([]),[g,h]=(0,d.useState)(0),[i,j]=(0,d.useState)(""),[k,l]=(0,d.useState)(""),[m,n]=(0,d.useState)(!1),[o,p]=(0,d.useState)(null),q=(0,d.useCallback)(()=>{fetch(`/api/knowledge/${a}`).then(a=>a.json()).then(a=>{f(a.chunks||[]),h(a.total||0)}).catch(console.error)},[a]);async function r(){if(i){n(!0),p(null);try{let b=await fetch("/api/knowledge/ingest",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({botId:a,url:i})}),c=await b.json();b.ok?(p({type:"success",text:`Ingested ${c.chunksCreated} chunks from URL`}),j(""),q()):p({type:"error",text:c.error})}catch{p({type:"error",text:"Failed to ingest URL"})}n(!1)}}async function s(){if(k){n(!0),p(null);try{let b=await fetch("/api/knowledge/ingest",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({botId:a,text:k})}),c=await b.json();b.ok?(p({type:"success",text:`Created ${c.chunksCreated} chunks from text`}),l(""),q()):p({type:"error",text:c.error})}catch{p({type:"error",text:"Failed to ingest text"})}n(!1)}}async function t(b){await fetch(`/api/knowledge/${a}?chunkId=${b}`,{method:"DELETE"}),q()}return(0,d.useEffect)(()=>{q()},[q]),(0,b.jsxs)("div",{className:"space-y-6",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("p",{className:"text-sm font-semibold text-[var(--color-text-secondary)]",children:"Knowledge base"}),(0,b.jsx)("h1",{className:"font-display text-3xl font-bold",children:"Train your bot"}),(0,b.jsx)("p",{className:"text-[var(--color-text-secondary)]",children:"Add URLs or text content. Your bot will reference this to answer questions."})]}),o&&(0,b.jsx)("div",{className:`rounded-xl px-4 py-3 text-sm ${"success"===o.type?"bg-green-50 text-green-700":"bg-red-50 text-red-600"}`,children:o.text}),(0,b.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,b.jsxs)("div",{className:"rounded-2xl border border-[var(--color-border-light)] bg-white p-5 shadow-sm",children:[(0,b.jsx)("p",{className:"font-semibold",children:"Add URL"}),(0,b.jsx)("p",{className:"mt-1 text-sm text-[var(--color-text-secondary)]",children:"We'll crawl the page and extract text content."}),(0,b.jsxs)("div",{className:"mt-3 flex gap-2",children:[(0,b.jsx)("input",{type:"url",value:i,onChange:a=>j(a.target.value),placeholder:"https://example.com/about",className:"input flex-1"}),(0,b.jsx)("button",{onClick:r,disabled:!i||m,className:"rounded-xl bg-[var(--color-bg-brand)] px-4 py-2 text-sm font-semibold text-white transition hover:bg-[var(--color-bg-brand-light)] disabled:opacity-50",children:m?"...":"Ingest"})]})]}),(0,b.jsxs)("div",{className:"rounded-2xl border border-[var(--color-border-light)] bg-white p-5 shadow-sm",children:[(0,b.jsx)("p",{className:"font-semibold",children:"Add text"}),(0,b.jsx)("p",{className:"mt-1 text-sm text-[var(--color-text-secondary)]",children:"Paste FAQ content, product info, or any text."}),(0,b.jsx)("textarea",{value:k,onChange:a=>l(a.target.value),rows:3,placeholder:"Paste your content here...",className:"input mt-3"}),(0,b.jsx)("button",{onClick:s,disabled:!k||m,className:"mt-2 rounded-xl bg-[var(--color-bg-brand)] px-4 py-2 text-sm font-semibold text-white transition hover:bg-[var(--color-bg-brand-light)] disabled:opacity-50",children:m?"Processing...":"Add content"})]})]}),(0,b.jsxs)("div",{className:"rounded-2xl border border-[var(--color-border-light)] bg-white shadow-sm",children:[(0,b.jsx)("div",{className:"border-b border-[var(--color-border-light)] px-5 py-3",children:(0,b.jsxs)("p",{className:"font-semibold",children:["Knowledge chunks (",g,")"]})}),0===e.length?(0,b.jsx)("div",{className:"px-5 py-8 text-center text-sm text-[var(--color-text-secondary)]",children:"No knowledge added yet. Add a URL or text above."}):(0,b.jsx)("div",{className:"divide-y divide-[var(--color-border-light)]",children:e.map(a=>(0,b.jsxs)("div",{className:"flex items-start justify-between gap-4 px-5 py-3",children:[(0,b.jsxs)("div",{className:"flex-1",children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("span",{className:`rounded-full px-2 py-0.5 text-xs font-semibold text-white ${"url"===a.source?"bg-[var(--color-bg-brand)]":"bg-slate-500"}`,children:a.source}),a.metadata.url&&(0,b.jsx)("span",{className:"text-xs text-[var(--color-text-secondary)]",children:a.metadata.url})]}),(0,b.jsx)("p",{className:"mt-1 line-clamp-2 text-sm text-[var(--color-text-secondary)]",children:a.content})]}),(0,b.jsx)("button",{onClick:()=>t(a._id),className:"shrink-0 text-xs text-red-400 hover:text-red-600",children:"Delete"})]},a._id))})]})]})}a.s(["default",()=>e])}];

//# sourceMappingURL=src_app_%28app%29_dashboard_bots_%5BbotId%5D_knowledge_page_tsx_2c377daf._.js.map