import{z as R,A as N}from"./lodash-ZyeDnt0e.js";import{h as b,j as q,aw as A,b as C,ar as y,q as T,i as S,g as H,f as F}from"./index-OtVJl4GC.js";import{f as D}from"./vendor-ClLR6ncd.js";import{c as V,v as K}from"./model-BneMh0-t.js";import{h as l}from"./model-Cx9iH8L7.js";import{u as j}from"./index-PJ52zw2m.js";import{a as E}from"./model-Dfrorm_S.js";import{r as z}from"./model-C9Idzwgo.js";import{d as G}from"./model-CvVGVe3F.js";import{p as g}from"./model-DAvH-x8m.js";const L={evdb:"Expertise Vector Database",expertiseMaxMatches:"Maximum number of expertise matches",expertiseMinScore:"Minimum score for expertise matches",hvdb:"History Vector Database",historyMaxMatches:"Maximum number of history matches",historyMinScore:"Minimum score for history matches",bot:"Bot display name",human:"Client display name",windowSize:"Number of dialog lines in an embedded memory window",windowOverlap:"Number of lines overlapping between adjacent embedded windows",storyFmtString:"A statement about the feed",historyMatchFmtString:"Match string for history vector lookup",historyHintsFmtString:"Statement about the history matches",noHistoryHintsString:"Statement when no history matches found",expertiseMatchFmtString:"Match string for expertise vector lookup",expertiseHintsFmtString:"Statement about the expertise matches",noExpertiseHintsString:"Statement when no expertise matches found",stateFmtString:"Complete LLM Prompt for chatState",noResponseString:"Statement when the chatState query returns no rows",noStoryString:"Statement when the chatState doesn't have a feed"},w=Object.keys(L),P=new Set(["evdb","expertiseMaxMatches","expertiseMinScore","hvdb","historyMaxMatches","historyMinScore"]),ht=w.filter(t=>!P.has(t)),k=Object.assign({},...w.map(t=>({[t]:"text"})),{windowSize:"integer",windowOverlap:"integer",expertiseMinScore:"float",historyMinScore:"float",expertiseMaxMatches:"integer",historyMaxMatches:"integer"});function x(){const t=A(),{catalogId:e}=C();return({removeChatBot:s}={})=>{const o=[...t,"chat-bot-list"];s&&y.setQueryData(o,a=>a&&{...a,chatBots:Array.isArray(a==null?void 0:a.chatBots)?a.chatBots.filter(n=>n.id!==s):a==null?void 0:a.chatBots}),y.invalidateQueries(z(e)),y.invalidateQueries(o)}}function U(){const t=f();return q(["chat-bot-list"],async e=>{const s=await l({urlSuffix:e,queryText:`SELECT ?s ?p ?o {
        { ?s rdf:type ${M} ;
             ?p ?o .
          FILTER NOT EXISTS { GRAPH ?g { ?s ?p ?o } }
        }
        UNION
        { GRAPH ${t} { ?s ?p ?o . }  }
      }`}),o=R(s.data.values,([a])=>a);return{chatBots:N(Object.entries(o),"[0]","desc").map(([,a])=>Object.fromEntries(a.map(([,n,c])=>{const r=E(c);return[n.substring(n.lastIndexOf("/")+1,n.length-1),r.termType==="Literal"?isNaN(Number(r.value))?r.value.replace(/\\\\/g,"\\"):Number(r.value):c]})))}},{enabled:!!t})}const J="Insert the list of citations whose hints informed the response into the 'citation_ids' array.",X=(t,e)=>S({method:"delete",url:H({catalogId:t,repositoryId:e})});function _(t,e){const{catalogId:s,repositoryId:o}=g(t);return G({catalogId:s,repositoryId:o,embedder:"openai",model:"text-embedding-ada-002",apiKey:e})}const m=t=>`<http://franz.com/chatState/${t}>`,d=t=>m(`profile#${t}`),W=(t,e)=>e==="text"||!e?`"""${t.replace(/\\/g,"\\\\")}"""`:`"${t}"^^xsd:${e}`,M=m("chat-bot"),B="hvdb";function f(){const{username:t}=T();return t?m(t):""}const O=t=>(e,s,o)=>{const a=`${t} ${m(e)} ${W(s,k[e])} .`;return o?`graph ${o} { ${a} } .`:a};function v(t,e,s){return O(d(t))(B,e,s)}function dt(t,e){const s=f();return v(t,e,s)}function I(t,e){return l({urlSuffix:e,queryText:`delete { ?s ?p ?o }
where {
  bind(${d(t)} as ?s)
  ?s ?p ?o 
}`})}function Y(){var e;const t=V();return Array.isArray(t.data)?(e=t.data.find(s=>s.name==="openaiApiKey"&&s.shadowed===!1))==null?void 0:e.value:null}function mt(t){const e=D(),s=f(),o=x(),a=Y(),{vectorDatabases:n}=j("dummy");return b(async({stateFmtString:c,[B]:r,apiKey:u,...i},h)=>{!n.find(({value:p})=>p===r)&&(await K(u),a||await S({url:F(h,"query-options/openaiApiKey"),method:"put",data:u,params:{type:"user"}}),await _(r,u)),await I(i.id,h);const $=O(d(i.id));await l({urlSuffix:h,queryText:`insert data {
          ${d(i.id)} rdf:type ${M} .
          ${v(i.id,r,s)}
${Object.entries({stateFmtString:`${c}. ${J}`,...i}).map(([p,Q])=>$(p,Q)).join(`
`)}
}`})},{invalidateRepoKeysOnSuccess:["size"],onSuccess:()=>{o(),e(t?"./..":"./../..",{relative:"path"})}})}function pt({useDeleteChatBotContext:t}){const e=t(),s=x(),o=U(),a=e.openParameter;return b(async(n,c)=>{var i;await I(a,c);const{catalogId:r,repositoryId:u}=g((i=o.data)==null?void 0:i.chatBots.find(h=>h.id===a).hvdb);await X(r,u)},{invalidateRepoKeysOnSuccess:["size"],onSettled:()=>{e.resetOpenParameter()},onSuccess:()=>s({removeChatBot:a})})}export{U as a,x as b,w as c,Y as d,mt as e,k as f,dt as g,_ as h,L as n,ht as p,pt as u};
