PageSourceSearch

https://dc-connected.ai/assets/RagCollections-x9FoZ4nN.js

js dc-connected.ai collected 2026-10-05 16:15:29 UTC 11,872 bytes, 1 lines download raw bytes

1import{u as pe,c as je,r,j as e,af as fe,b1 as Ce,B as c,ag as ve,ah as Ne,ai as ye,aj as be,l as d,I as ke,aQ as Y,ap as _,aq as z,ar as A,as as R,at as C,aD as we,e as q,C as Z,f as $,g as J,k as K,H as m,p as Se,aV as De,aW as Te,aX as U,aY as u,aZ as _e,a_ as p,ad as i,o as j}from"./index-X4aSNaeS.js";import{A as ze,b as Ae,c as Re,d as qe,e as Oe,f as Fe,g as Le,h as Ee}from"./alert-dialog-DW5KT5EB.js";import{C as Ie}from"./checkbox-DUk-VD1l.js";import{S as He}from"./switch-CfX6Yh26.js";import{P as Me}from"./plus-BPH5LubD.js";import{S as ee}from"./search-l0aUOaDO.js";import{C as Pe}from"./copy-Cu6xlyxp.js";import{F as Qe}from"./folder-open-C8untBPI.js";import{T as Ve}from"./trash-2-c6Wan5m4.js";function Ue(){const{t}=pe("knowledge"),se=je(),[o,te]=r.useState([]),[ae,re]=r.useState([]),[ne,O]=r.useState(!0),[le,v]=r.useState(!1),[F,L]=r.useState(!1),[g,N]=r.useState(null),[E,I]=r.useState(!1),[n,x]=r.useState({name:"",description:"",scope:"global",organization_id:""}),[H,ie]=r.useState(""),[y,b]=r.useState(new Set),[M,oe]=r.useState(3),[P,ce]=r.useState(!0),[Q,V]=r.useState(!1),[h,B]=r.useState(null),[f,G]=r.useState(null),[W,X]=r.useState(null),de=s=>{b(a=>{const l=new Set(a);return l.has(s)?l.delete(s):l.add(s),l})},me=async()=>{const s=H.trim();if(!s){i.error(t("rag.test.errors.queryRequired","Query is required"));return}if(y.size===0){i.error(t("rag.test.errors.pickCollection","Select at least one collection"));return}V(!0),X(null),B(null),G(null);const a=o.filter(T=>y.has(T.id)).map(T=>T.name),{data:l,error:S}=await j.functions.invoke("rag-documents",{body:{query:s,collection_names:a,top_documents:M,rerank:P}});V(!1);const D=(S==null?void 0:S.message)||(l==null?void 0:l.error);if(D){X(D),i.error(D);return}B((l==null?void 0:l.documents)??[]),G((l==null?void 0:l.meta)??null)},ge=async s=>{try{await navigator.clipboard.writeText(s),i.success(t("rag.test.copied","Copied to clipboard"))}catch{i.error(t("rag.test.copyFailed","Copy failed"))}},k=async()=>{O(!0);const{data:s,error:a}=await j.functions.invoke("rag-admin",{body:{action:"list_collections"}});a||s!=null&&s.error?i.error((a==null?void 0:a.message)||(s==null?void 0:s.error)||"Failed to load collections"):te(s.collections??[]),O(!1)},xe=async()=>{const{data:s}=await j.from("organizations").select("id,name").order("name");re(s??[])};r.useEffect(()=>{k(),xe()},[]);const he=async()=>{if(!n.name.trim()){i.error(t("rag.errors.nameRequired","Name is required"));return}if(n.scope==="org"&&!n.organization_id){i.error(t("rag.errors.orgRequired","Please select an organization"));return}L(!0);const{data:s,error:a}=await j.functions.invoke("rag-admin",{body:{action:"create_collection",name:n.name.trim(),description:n.description.trim()||null,organization_id:n.scope==="org"?n.organization_id:null}});if(L(!1),a||s!=null&&s.error){i.error((a==null?void 0:a.message)||(s==null?void 0:s.error)||"Failed to create");return}i.success(t("rag.toasts.created","Collection created")),v(!1),x({name:"",description:"",scope:"global",organization_id:""}),k()},ue=async()=>{if(!g)return;I(!0);const{data:s,error:a}=await j.functions.invoke("rag-admin",{body:{action:"delete_collection",collection_id:g}});I(!1),a||s!=null&&s.error?i.error((a==null?void 0:a.message)||(s==null?void 0:s.error)||"Delete failed"):(i.success(t("rag.toasts.deleted","Collection deleted")),N(null),k())},w=r.useMemo(()=>o.find(s=>s.id===g),[g,o]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:t("rag.title","RAG Collections")}),e.jsx("p",{className:"text-muted-foreground",children:t("rag.subtitle","Manage document collections used for retrieval-augmented answers.")})]}),e.jsxs(fe,{open:le,onOpenChange:v,children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(c,{children:[e.jsx(Me,{className:"h-4 w-4 mr-2"}),t("rag.actions.newCollection","New Collection")]})}),e.jsxs(ve,{children:[e.jsxs(Ne,{children:[e.jsx(ye,{children:t("rag.dialogs.createTitle","Create collection")}),e.jsx(be,{children:t("rag.dialogs.createDesc","A collection groups documents. Choose global scope or attach it to a single organization.")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(d,{children:t("rag.fields.name","Name")}),e.jsx(ke,{value:n.name,onChange:s=>x({...n,name:s.target.value}),placeholder:"e.g. DE Roadside SOPs"})]}),e.jsxs("div",{children:[e.jsx(d,{children:t("rag.fields.description","Description")}),e.jsx(Y,{value:n.description,onChange:s=>x({...n,description:s.target.value}),rows:3})]}),e.jsxs("div",{children:[e.jsx(d,{children:t("rag.fields.scope","Scope")}),e.jsxs(_,{value:n.scope,onValueChange:s=>x({...n,scope:s}),children:[e.jsx(z,{children:e.jsx(A,{})}),e.jsxs(R,{children:[e.jsx(C,{value:"global",children:t("rag.scope.global","Global")}),e.jsx(C,{value:"org",children:t("rag.scope.org","Organization")})]})]})]}),n.scope==="org"&&e.jsxs("div",{children:[e.jsx(d,{children:t("rag.fields.organization","Organization")}),e.jsxs(_,{value:n.organization_id,onValueChange:s=>x({...n,organization_id:s}),children:[e.jsx(z,{children:e.jsx(A,{placeholder:t("rag.fields.selectOrg","Select organization")})}),e.jsx(R,{children:ae.map(s=>e.jsx(C,{value:s.id,children:s.name},s.id))})]})]})]}),e.jsxs(we,{children:[e.jsx(c,{variant:"outline",onClick:()=>v(!1),children:t("common.cancel","Cancel")}),e.jsxs(c,{onClick:he,disabled:F,children:[F&&e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}),t("rag.actions.create","Create")]})]})]})]})]}),e.jsxs(Z,{children:[e.jsx($,{children:e.jsxs(J,{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),t("rag.test.title","Test search")]})}),e.jsxs(K,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(d,{children:t("rag.test.query","Query")}),e.jsx(Y,{value:H,onChange:s=>ie(s.target.value),rows:3,placeholder:t("rag.test.queryPlaceholder","Ask a question or paste a snippet…")})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(d,{children:t("rag.test.collections","Collections")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{type:"button",variant:"ghost",size:"sm",onClick:()=>b(new Set(o.map(s=>s.id))),children:t("rag.test.selectAll","All")}),e.jsx(c,{type:"button",variant:"ghost",size:"sm",onClick:()=>b(new Set),children:t("rag.test.clear","Clear")})]})]}),o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:t("rag.test.noCollections","Create a collection first.")}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2 max-h-40 overflow-auto rounded-md border p-2",children:o.map(s=>e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer px-2 py-1 rounded hover:bg-muted/50",children:[e.jsx(Ie,{checked:y.has(s.id),onCheckedChange:()=>de(s.id)}),e.jsx("span",{className:"truncate",children:s.name}),e.jsx(m,{variant:"outline",className:"ml-auto text-xs",children:s.document_count})]},s.id))})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-4",children:[e.jsxs("div",{className:"w-32",children:[e.jsx(d,{children:t("rag.test.topDocs","Top docs")}),e.jsxs(_,{value:String(M),onValueChange:s=>oe(Number(s)),children:[e.jsx(z,{children:e.jsx(A,{})}),e.jsx(R,{children:[1,2,3,4,5].map(s=>e.jsx(C,{value:String(s),children:s},s))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{checked:P,onCheckedChange:ce,id:"rag-test-rerank"}),e.jsx(d,{htmlFor:"rag-test-rerank",className:"cursor-pointer",children:t("rag.test.rerank","LLM rerank")})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs(c,{onClick:me,disabled:Q,children:[Q?e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ee,{className:"h-4 w-4 mr-2"}),t("rag.test.run","Run search")]})})]}),W&&e.jsx("div",{className:"rounded-md border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:W}),f&&e.jsxs("div",{className:"text-xs text-muted-foreground flex flex-wrap gap-3",children:[e.jsxs("span",{children:[t("rag.test.meta.latency","Latency"),": ",f.latency_ms," ms"]}),e.jsxs("span",{children:[t("rag.test.meta.pool","Candidate pool"),": ",f.candidate_pool]}),e.jsxs("span",{children:[t("rag.test.meta.reranked","Reranked"),":"," ",f.reranked?t("common.yes","yes"):t("common.no","no")]})]}),h&&h.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:t("rag.test.empty","No matching documents.")}),h&&h.length>0&&e.jsx("div",{className:"space-y-3",children:h.map(s=>{var a;return e.jsxs("div",{className:"rounded-md border p-4 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"font-medium",children:s.title}),e.jsxs(m,{variant:"secondary",children:["score ",s.score]}),e.jsxs(m,{variant:"outline",children:[s.matched_chunks," ",t("rag.test.chunks","chunks")]}),((a=s.collection)==null?void 0:a.name)&&e.jsx(m,{children:s.collection.name}),s.updated_at&&e.jsx("span",{className:"text-xs text-muted-foreground ml-auto",children:new Date(s.updated_at).toLocaleStr
1ing()}),e.jsx(c,{size:"icon",variant:"ghost",onClick:()=>ge(s.readable_content??""),title:t("rag.test.copy","Copy"),children:e.jsx(Pe,{className:"h-4 w-4"})})]}),e.jsx("pre",{className:"whitespace-pre-wrap text-sm bg-muted/40 rounded p-3 max-h-96 overflow-auto font-sans",children:s.readable_content})]},s.document_id)})})]})]}),e.jsxs(Z,{children:[e.jsx($,{children:e.jsx(J,{children:t("rag.list.title","Collections")})}),e.jsx(K,{children:ne?e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((s,a)=>e.jsx(Se,{className:"h-12 w-full"},a))}):o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:t("rag.list.empty","No collections yet. Create your first one to start uploading documents.")}):e.jsxs(De,{children:[e.jsx(Te,{children:e.jsxs(U,{children:[e.jsx(u,{children:t("rag.fields.name","Name")}),e.jsx(u,{children:t("rag.fields.scope","Scope")}),e.jsx(u,{className:"text-right",children:t("rag.fields.documents","Documents")}),e.jsx(u,{className:"text-right",children:t("rag.fields.chunks","Chunks")}),e.jsx(u,{className:"w-24"})]})}),e.jsx(_e,{children:o.map(s=>e.jsxs(U,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>se(`/internal/joy/rag/collections/${s.id}`),children:[e.jsx(p,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qe,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.name}),s.description&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s.description})]})]})}),e.jsx(p,{children:s.organization_id?e.jsx(m,{variant:"secondary",children:s.organization_name??s.organization_id.slice(0,6)}):e.jsx(m,{children:t("rag.scope.global","Global")})}),e.jsx(p,{className:"text-right",children:s.document_count}),e.jsx(p,{className:"text-right",children:s.chunk_count}),e.jsx(p,{onClick:a=>a.stopPropagation(),children:e.jsx(c,{variant:"ghost",size:"icon",disabled:s.document_count>0,title:s.document_count>0?t("rag.tooltips.notEmpty","Remove all documents first"):t("common.delete","Delete"),onClick:()=>N(s.id),children:e.jsx(Ve,{className:"h-4 w-4 text-destructive"})})})]},s.id))})]})})]}),e.jsx(ze,{open:!!g,onOpenChange:s=>!s&&N(null),children:e.jsxs(Ae,{children:[e.jsxs(Re,{children:[e.jsx(qe,{children:t("rag.dialogs.deleteTitle","Delete collection?")}),e.jsxs(Oe,{children:[t("rag.dialogs.deleteDesc","This permanently removes the collection")," ",e.jsx("strong",{children:w==null?void 0:w.name}),"."]})]}),e.jsxs(Fe,{children:[e.jsx(Le,{children:t("common.cancel","Cancel")}),e.jsxs(Ee,{onClick:ue,disabled:E,children:[E&&e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}),t("common.delete","Delete")]})]})]})})]})}export{Ue as default};

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.