PageSourceSearch

https://engadin.ai/admin/assets/data-sources-BaKi_tM0.js

js engadin.ai collected 2026-10-05 11:59:15 UTC 9,372 bytes, 1 lines download raw bytes

1import{u as oe,a as ce,h as M,j as t,P as O,D as de,C as q,c as H,d as K,e as W,f as Q,F as y,I as G,B as p,a2 as v,S as C,E as ue,g as J,n as pe,R as me,O as i,Q as he,a7 as xe,a$ as fe}from"./index-ePDyumzS.js";import{b as r}from"./recharts-qOI1PvBd.js";import{D as ge,a as je,b as ye,c as ve,d as be,e as we}from"./dialog-Dra4P_lX.js";import{T as V}from"./textarea-m-5pKd5_.js";import{g as X,f as Ne}from"./format-CRKJO8mk.js";import{u as ke}from"./use-async-UEQ1rRDQ.js";import{S as D}from"./knowledge-I-X-Xy1U.js";import{P as Ce}from"./plus-B9Wqxdyx.js";import{F as $}from"./file-text-D-vABE23.js";import{U as De}from"./upload-DNyqPSer.js";import{P as $e}from"./pencil-BBlHwWSp.js";import{T as Se}from"./trash-2-BEYhy3KJ.js";import"./globe-DZYBRSTv.js";function Te(a){return a?a<1024?`${a} B`:a<1024*1024?`${(a/1024).toFixed(0)} KB`:`${(a/1024/1024).toFixed(1)} MB`:"—"}function qe({view:a}){var z;const{canOperate:Y,canMutate:m}=oe(),{agents:Z,selected:ee}=ce(),c=ee||(((z=Z[0])==null?void 0:z.id)??""),{data:b,loading:S,error:T,reload:d}=ke(()=>c?M(`/sources?agent=${encodeURIComponent(c)}`):Promise.resolve({sources:[]}),[c]),[h,F]=r.useState(""),[x,E]=r.useState(""),[l,o]=r.useState(null),[te,w]=r.useState(!1),N=r.useRef(null),[n,u]=r.useState(null),[f,_]=r.useState(""),[g,k]=r.useState(""),[P,B]=r.useState(!1);async function A(e){const s=[...e??[]].slice(0,5);for(const le of s)await ae(le)}const R=(b==null?void 0:b.sources)??[],U=R.filter(e=>e.type==="snippet"),I=R.filter(e=>e.type==="file");async function se(){if(!(!h.trim()||!x.trim())){o("snippet");try{const e=await me(`/sources?agent=${encodeURIComponent(c)}`,{title:h.trim(),content:x.trim()});i.success(`Snippet added — ${e.chunk_count} chunk${e.chunk_count===1?"":"s"} indexed, live immediately.`),F(""),E(""),d()}catch(e){i.error((e==null?void 0:e.message)??"Adding the snippet failed")}finally{o(null)}}}async function ae(e){o("file");try{const s=await fe(`/sources/file?agent=${encodeURIComponent(c)}`,e);i.success(`${e.name} indexed`,{description:`${Ne(s.extracted_chars)} characters extracted → ${s.chunk_count} chunk${s.chunk_count===1?"":"s"}.`}),d()}catch(s){i.error((s==null?void 0:s.message)??"Upload failed")}finally{o(null)}}async function ne(e){if(u(e),_(e.title),k(e.content??""),e.content==null){B(!0);try{const s=await M(`/sources/${e.id}`);k(s.source.content??"")}catch(s){i.error((s==null?void 0:s.message)??"Loading the snippet failed"),u(null)}finally{B(!1)}}}async function ie(){if(!(!n||!f.trim()||!g.trim())){o(`edit:${n.id}`);try{const e=await he(`/sources/${n.id}`,{title:f.trim(),content:g.trim()});i.success(`Snippet updated — ${e.chunk_count} chunk${e.chunk_count===1?"":"s"} re-indexed, live immediately.`),u(null),d()}catch(e){i.error((e==null?void 0:e.message)??"Saving the snippet failed")}finally{o(null)}}}async function re(e){o(e.id);try{await xe(`/sources/${e.id}`),i.success(`"${e.title}" removed from the knowledge base.`),d()}catch(s){i.error((s==null?void 0:s.message)??"Delete failed")}finally{o(null)}}if(!Y)return t.jsxs(t.Fragment,{children:[t.jsx(O,{title:a==="files"?"Files":"Text snippets",description:"Extra knowledge for the agent beyond the website crawl."}),t.jsx(de,{required:"admin"})]});const L=(e,s)=>t.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[t.jsx("span",{className:"text-muted-foreground",children:s}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"truncate text-sm font-medium",children:e.title}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.type==="file"&&e.filename?`${e.filename} · ${Te(e.size)} · `:"",e.chunk_count," chunk",e.chunk_count===1?"":"s"," · ",X(e.created_at),e.updated_at&&e.updated_at!==e.created_at?` · edited ${X(e.updated_at)}`:""]})]}),m&&e.type==="snippet"&&t.jsx(p,{variant:"ghost",size:"icon","aria-label":`Edit ${e.title}`,disabled:l===e.id,onClick:()=>ne(e),children:t.jsx($e,{})}),m&&t.jsx(p,{variant:"ghost",size:"icon","aria-label":`Delete ${e.title}`,disabled:l===e.id,onClick:()=>re(e),children:l===e.id?t.jsx(v,{className:"animate-spin"}):t.jsx(Se,{})})]},e.id),j=n!==null&&l===`edit:${n.id}`;return t.jsxs(t.Fragment,{children:[t.jsx(O,{title:a==="files"?"Files":"Text snippets",description:"Extra knowledge for this agent beyond the website crawl — indexed into the same knowledge base and used to answer visitors."}),t.jsxs("div",{className:"space-y-6",children:[a==="snippets"&&t.jsxs(q,{children:[t.jsxs(H,{
1children:[t.jsxs(K,{className:"flex items-center gap-2 text-base",children:[t.jsx(D,{className:"h-4 w-4 text-muted-foreground"})," Text snippets"]}),t.jsx(W,{children:"The last resort, not the first. Anything that could live on a page belongs on your website: there your visitors and search engines see it too, and the crawler keeps the assistant in step with it by itself. Keep snippets for what has no page to live on, such as internal policy, a figure you do not publish, or a fact the crawler cannot reach. Indexed immediately on save, and maintained by hand from then on."})]}),t.jsxs(Q,{className:"space-y-4",children:[m&&t.jsxs("div",{className:"space-y-3 rounded-lg border bg-muted/30 p-4",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(y,{children:"Title"}),t.jsx(G,{value:h,onChange:e=>F(e.target.value),placeholder:"e.g. Scholarship deadlines 2026"})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(y,{children:"Content"}),t.jsx(V,{rows:4,value:x,onChange:e=>E(e.target.value),placeholder:"The knowledge itself — plain text or markdown."})]}),t.jsxs(p,{variant:"gold",size:"sm",onClick:se,disabled:l==="snippet"||!h.trim()||!x.trim(),children:[l==="snippet"?t.jsx(v,{className:"animate-spin"}):t.jsx(Ce,{})," Add snippet"]})]}),S?t.jsx(C,{className:"h-16 w-full"}):T?t.jsx(ue,{message:T,onRetry:d}):U.length===0?t.jsx(J,{icon:t.jsx(D,{}),title:"No snippets yet",description:"Nothing here is usually a good sign: it means your website carries the answers. Add a snippet only for a fact that has no page to live on."}):t.jsx("div",{className:"space-y-2",children:U.map(e=>L(e,t.jsx(D,{className:"h-4 w-4"})))})]})]}),a==="files"&&t.jsxs(q,{children:[t.jsxs(H,{children:[t.jsxs(K,{className:"flex items-center gap-2 text-base",children:[t.jsx($,{className:"h-4 w-4 text-muted-foreground"})," Files"]}),t.jsx(W,{children:"PDFs, Word documents or plain text (max 8 MB) — brochures, price lists, fact sheets. Text is extracted and indexed."})]}),t.jsxs(Q,{className:"space-y-4",children:[m&&t.jsxs(t.Fragment,{children:[t.jsx("input",{ref:N,type:"file",multiple:!0,accept:".pdf,.docx,.doc,.txt,.md,.csv,application/pdf,text/plain,text/markdown",className:"hidden",onChange:e=>{A(e.target.files),e.target.value=""}}),t.jsxs("div",{role:"button",tabIndex:0,"aria-label":"Upload files",onClick:()=>{var e;return(e=N.current)==null?void 0:e.click()},onKeyDown:e=>{var s;(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),(s=N.current)==null||s.click())},onDragOver:e=>{e.preventDefault(),w(!0)},onDragLeave:()=>w(!1),onDrop:e=>{var s;e.preventDefault(),w(!1),A((s=e.dataTransfer)==null?void 0:s.files)},className:pe("flex cursor-pointer flex-col items-center justify-center gap-1.5 rounded-lg border-2 border-dashed p-8 text-center transition-colors",te?"border-blue-400 bg-blue-50 dark:border-blue-500/50 dark:bg-blue-500/10":"border-muted-foreground/25 hover:border-muted-foreground/50"),children:[l==="file"?t.jsx(v,{className:"h-6 w-6 animate-spin text-muted-foreground"}):t.jsx(De,{className:"h-6 w-6 text-muted-foreground"}),t.jsx("div",{className:"text-sm font-medium",children:l==="file"?"Indexing…":"Drop files here — or click to browse"}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"PDF, Word, text or markdown · max 8 MB each"})]})]}),S?t.jsx(C,{className:"h-16 w-full"}):I.length===0?t.jsx(J,{icon:t.jsx($,{}),title:"No files yet",description:"Upload brochures or fact sheets to enrich the knowledge base."}):t.jsx("div",{className:"space-y-2",children:I.map(e=>L(e,t.jsx($,{className:"h-4 w-4"})))})]})]})]}),t.jsx(ge,{open:n!==null,onOpenChange:e=>!e&&!j&&u(null),children:t.jsx(je,{className:"max-h-[90vh] overflow-y-auto sm:max-w-2xl",children:t.jsxs("form",{onSubmit:e=>{e.preventDefault(),ie()},children:[t.jsxs(ye,{children:[t.jsxs(ve,{children:["Edit “",n==null?void 0:n.title,"”"]}),t.jsx(be,{children:"Saving re-indexes the snippet: the old chunks are replaced and the assistant answers from the new text immediately."})]}),t.jsxs("div",{className:"space-y-4 py-4",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(y,{htmlFor:"edit-snippet-title",children:"Title"}),t.jsx(G,{id:"edit-snippet-title",value:f,onChange:e=>_(e.target.value),required:!0})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(y,{htmlFor:"edit-snippet-content",children:"Content"}),P?t.jsx(C,{className:"h-40 w-full"}):t.jsx(V,{id:"edit-snippet-content",rows:12,value:g,onChange:e=>k(e.target.value),placeholder:"The knowledge itself — plain text or markdown.",required:!0})]})]}),t.jsxs(we,{className:"gap-2",children:[t.jsx(p,{type:"button",variant:"outline",onClick:()=>u(null),disabled:j,children:"Cancel"}),t.jsxs(p,{type:"submit",variant:"gold",disabled:j||P||!f.trim()||!g.trim(),children:[j?t.jsx(v,{className:"animate-spin"}):null,"Save and re-index"]})]})]})})})]})}export{qe as DataSourcesPage};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.