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