import{j as r,S as C,h as Q,H as y,s as D,v as k,r as f,R as d,aI as R}from"./vendor-ClLR6ncd.js";import{L as h,b as q,a as L}from"./index-OtVJl4GC.js";import{H as S}from"./index-D0mM6sVf.js";import{u as b}from"./model-Ci5wTidX.js";import{S as T}from"./SmallStandardSelect-7k6-Wr8Q.js";import{u as A}from"./index-PJ52zw2m.js";import{u as E}from"./useDirtyStateInput-CLFyv7KP.js";import{B as I}from"./Box-Co2WcNPC.js";import{b as O}from"./model-Cx9iH8L7.js";import{s as g}from"./model-Dfrorm_S.js";import"./lodash-ZyeDnt0e.js";import"./Divider-DZzUGEvZ.js";import"./dividerClasses-DvO85-mA.js";import"./MenuItem-CCerWMyq.js";import"./model-C9Idzwgo.js";import"./model-DAvH-x8m.js";import"./highlightSearch-BTHB3jgf.js";import"./WithMeasure-BDk9QPMF.js";import"./TableRow-CGDSOtFZ.js";import"./TableSortLabel-BJFq2axQ.js";import"./TypographyWithTooltip-BFAG3Va9.js";import"./Link-BLwKPJFF.js";const B={width:"300px"};function H({currentVectorDatabase:u,setCurrentVectorDatabase:e,setQueryText:t,queryText:a,execQuery:s}){const{isLoading:n,disabled:i,vectorDatabases:l}=A(u,e),[p,c]=E({setInput:t,input:a});return n?r.jsx(h,{}):i?r.jsx(C,{justifyContent:"center",alignItems:"center",sx:{p:2,height:1},spacing:2,children:r.jsxs(Q,{align:"center",children:["There are currently no vector databases defined in this repository, so your query won't yield results!"," ",r.jsx(y,{component:D,to:"../../control/llm-embedding",relative:!0,children:"Create LLM index"}),"to query strings from the repository."]})}):r.jsxs(I,{sx:{height:1,display:"flex",flexDirection:"column",gap:2,p:2,textAlign:"left"},children:[r.jsx(T,{items:l,value:u,onChange:m=>e(m.target.value),fullWidth:!1,sx:B,label:"Vector database to query"}),r.jsx(k,{disabled:i,value:p||"",onChange:m=>c(m.target.value),label:"ChatStream - RAG",helperText:"Here goes a question for your documents",variant:"standard"}),r.jsx(y,{variant:"contained",disabled:i,onClick:s,children:"Execute query"})]})}function P(u,e){const t=b();return O(`PREFIX llm: <http://franz.com/ns/allegrograph/8.0.0/llm/>

  select ?response ?score ?citation ?citationLabel {
    (?response ?score ?citation ?citationLabel) llm:askMyDocuments ("${(t||"").replaceAll('"','\\"')}" "${u}") .
  }`,[t,u],{onSettled:e,transformResponse:a=>({result:a.values.map(([s,n,i,l])=>({response:g(s),score:parseFloat(n.substring(1,n.indexOf('"',1))),citation:i,label:l&&g(l)}))})})}const V=[];function ie(){var x;const{catalogId:u,repoConnection:e,currentQuery:t}=q(),a=b(),{addOpenedAskDocumentsQuery:s,getOpenedQueries:n}=L(),i=((x=n(e)[t])==null?void 0:x.vectorDb)||"",l=f.useCallback(o=>{s(e,{id:t,vectorDb:o})},[s,t,e]),p=f.useCallback(o=>{s(e,{id:t,...o!==void 0?{local:o}:{}})},[s,e,t]);d.useEffect(()=>{p()},[p]);const c=d.useCallback(()=>{var o;return((o=n(e)[t])==null?void 0:o.results)||V},[n,e,t]),{refetch:m}=P(i,(o,v)=>{s(e,{id:t,results:c().slice(0,-1).concat({queryText:a,queryResult:o,queryError:v})})}),j=d.useCallback(()=>{s(e,{id:t,results:c().concat({queryText:a,queryResult:null,queryError:null})}),m()},[s,t,m,c,a,e]);return!e||!u?r.jsx(h,{}):r.jsx(S,{Top:r.jsx(H,{currentVectorDatabase:i,setCurrentVectorDatabase:l,setQueryText:p,queryText:a,execQuery:j}),Bottom:r.jsx(R,{context:{queryResultPairs:c()}})})}export{ie as default};
