import{w as h,C as p,y,a as b}from"./chunk-QMGIS6GS-CBZUm-7V.js";import{j as r}from"./jsx-runtime-D_zvdyIk.js";import{f as m}from"./api-tgDzxHzW.js";import{B as I}from"./polymorphic-factory-EW0USS3V.js";import{G as x}from"./Group-bnACpcuK.js";import{T as w}from"./Title-B0fFn55O.js";import{B as j}from"./Button-BhC08Y9X.js";import{c as v}from"./createReactComponent-CwEnMXT7.js";import{D as S}from"./Divider-BI4N1hoX.js";import{C as f}from"./Card-BHrMkZ_V.js";import"./Loader-1VreoqJz.js";import"./index-B4z8r-Ct.js";import"./Paper-k397c_lM.js";import"./create-safe-context-CzEsa9t0.js";/**
 * @license @tabler/icons-react v3.34.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var C=v("outline","eraser","IconEraser",[["path",{d:"M19 20h-10.5l-4.21 -4.3a1 1 0 0 1 0 -1.41l10 -10a1 1 0 0 1 1.41 0l5 5a1 1 0 0 1 0 1.41l-9.2 9.3",key:"svg-0"}],["path",{d:"M18 13.3l-6.3 -6.3",key:"svg-1"}]]);const n=[];for(let t=0;t<256;++t)n.push((t+256).toString(16).slice(1));function D(t,e=0){return(n[t[e+0]]+n[t[e+1]]+n[t[e+2]]+n[t[e+3]]+"-"+n[t[e+4]]+n[t[e+5]]+"-"+n[t[e+6]]+n[t[e+7]]+"-"+n[t[e+8]]+n[t[e+9]]+"-"+n[t[e+10]]+n[t[e+11]]+n[t[e+12]]+n[t[e+13]]+n[t[e+14]]+n[t[e+15]]).toLowerCase()}let c;const k=new Uint8Array(16);function _(){if(!c){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");c=crypto.getRandomValues.bind(crypto)}return c(k)}const E=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),d={randomUUID:E};function U(t,e,a){var s;if(d.randomUUID&&!t)return d.randomUUID();t=t||{};const o=t.random??((s=t.rng)==null?void 0:s.call(t))??_();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,D(o)}async function q(){var t;try{const e=localStorage.getItem("jivas-host")||"",a=localStorage.getItem("jivas-agent")||"",o=(t=document.cookie.match(/tsSessionId=([^;]+)/))==null?void 0:t[1],s=o&&o!=="undefined"?o:U();try{await m(`${e}/walker/add_frame`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent_id:a,session_id:s})}).catch(i=>{console.error("Error creating session:",i)})}catch{console.log("unable to create session")}return{sessionId:s,host:localStorage.getItem("jivas-host")||"",agentId:localStorage.getItem("jivas-agent")||""}}catch(e){return console.log(e),{sessionId:"jvmanager",host:localStorage.getItem("jivas-host")||"",agentId:localStorage.getItem("jivas-agent")||""}}}async function z({context:t,request:e}){const a=await e.formData(),o=a.get("_action"),s=new FormData,i=a.get("agentId")||"",l=localStorage.getItem("jivas-host")||"",g=a.get("sessionId");if(o==="wipeAgentMemory")return s.append("args",JSON.stringify({session_id:g})),s.append("module_root","actions.jivas.agent_utils_action"),s.append("agent_id",i),s.append("walker","purge_frame_memory"),await m(`${l}/action/walker`,{method:"POST",body:s}).then(async u=>await u.json())}function H(){return[{title:"Chat | JIVAS Manager"}]}const W=h(function({loaderData:e}){const{selectedAgentInfo:a}=p(),o=y(),s=b.useCallback(()=>{const i=new CustomEvent("tsmclearmessages");o.submit({_action:"wipeAgentMemory",agentId:e.agentId||"",sessionId:e.sessionId||""},{method:"POST"}),window.dispatchEvent(i)},[]);return r.jsxs(I,{py:"xl",px:"xl",children:[r.jsxs(x,{justify:"space-between",children:[r.jsx(w,{order:3,children:"Chat"}),r.jsx(j,{color:"dark",leftSection:r.jsx(C,{className:"h-5 w-5"}),size:"xs",onClick:s,loading:o.state!=="idle",children:"Clear Chat Memory"})]}),r.jsx(S,{mt:"xs",mb:"xl"}),r.jsx(f,{px:"xl",h:"80vh",withBorder:!0,children:r.jsx("ts-messenger",{host:e.host,"agent-id":e.agentId,"agent-name":a==null?void 0:a.name,theme:JSON.stringify({"--ts-chat-bg":"white","--ts-chat-fg":"black","--ts-chat-popup-bg":"white","--ts-icon-btn-bg":"transparent","--ts-icon-btn-hover-bg":"#E4E4E7","--ts-input-btn-color":"black","--ts-input-bg":"#dbdbdb42","--ts-input-bd":"#D4D4D8","--ts-chat-bd":"#D4D4D8","--chakra-colors-border":"#D4D4D8","--ts-input-color":"black","--ts-input-placeholder-color":"#000000eb","--ts-response-msg-color":"black"}),streaming:"true","with-debug":"true",layout:"standard","session-id":e.sessionId||"","use-local-storage-cache":"true",style:{height:"100%"}})})]})});export{z as clientAction,q as clientLoader,W as default,H as meta};
