1import{a7 as me,r as t,b as c,j as e,L as N,a8 as re,J as v,F as A,K as w,a2 as Se,G as Te,n as S,I as $,p as le,g as T,B as I,X as _e,aB as ce,E as ke,be as Ee,R as De,D as Le,k as Fe,l as He,m as Me,aF as Pe,q as qe}from"./index-DyeZDXNF.js";import{C as i,a as r,b as o,c as d,d as _}from"./card-CEWryA27.js";import{A as oe,B as Be}from"./AdminSidebar-Bf60_kNq.js";import{A as de}from"./AdminHeader-BHcTol3x.js";import{C as Oe}from"./circle-x-VmXoGzD-.js";import"./filter-DjcmfEdK.js";/** 2 * @license lucide-react v0.475.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ge=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Re=me("CircleHelp",Ge);/** 7 * @license lucide-react v0.475.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const $e=[["path",{d:"M14.5 2v17.5c0 1.4-1.1 2.5-2.5 2.5c-1.4 0-2.5-1.1-2.5-2.5V2",key:"125lnx"}],["path",{d:"M8.5 2h7",key:"csnxdl"}],["path",{d:"M14.5 16h-5",key:"1ox875"}]],Ke=me("TestTube",$e);function Ze(){const[u,xe]=t.useState(null),[he,ge]=t.useState(!0),[h,K]=t.useState(!1),[Q,U]=t.useState(!1),[ue,k]=t.useState(!1),[m,E]=t.useState(!0),[V,pe]=t.useState(null),[W,Y]=t.useState(!1),[D,J]=t.useState(""),[x,L]=t.useState(""),[Qe,Ue]=t.useState(""),[g,F]=t.useState("+32 3 226 24 10"),[H,X]=t.useState("+32 3 226 24 10"),[p,M]=t.useState("Hello! I'm your AI assistant. I can help you with any questions about this vessel's specifications, features, and availability. How can I assist you today?"),[P,z]=t.useState("Hello! I'm your AI assistant. I can help you with any questions about this vessel's specifications, features, and availability. How can I assist you today?"),[je,q]=t.useState(!1),[Z,fe]=t.useState(""),[C,B]=t.useState(""),[O,j]=t.useState(""),[ee,f]=t.useState(""),[b,be]=t.useState(""),[G,se]=t.useState(null),[te,ae]=t.useState(null);t.useEffect(()=>{ye()},[]);const ye=async()=>{var s;try{const a=await c.auth.me();if(xe(a),(a==null?void 0:a.role)!=="admin")return;const[n,y]=await Promise.all([c.functions.invoke("getAIInstructions"),c.entities.SiteSettings.filter({settings_key:"main"})]);if((s=n.data)!=null&&s.instructions&&(J(n.data.instructions),L(n.data.instructions)),y.length>0){const l=y[0];pe(l.id),l.ai_agent_phone&&(F(l.ai_agent_phone),X(l.ai_agent_phone)),l.ai_agent_greeting&&(M(l.ai_agent_greeting),z(l.ai_agent_greeting)),E(l.ai_agent_enabled!==!1)}}catch(a){console.error("Error loading data:",a)}finally{ge(!1)}},Ne=()=>Math.floor(1e6+Math.random()*9e6).toString(),ve=()=>{if(x===D&&g===H&&p===P)return;const s=Ne();fe(s),B(""),j(""),f(""),q(!0)},Ae=async()=>{var s,a;if(C!==Z){j("Incorrect code. Please try again.");return}K(!0),j(""),f("");try{const n=await c.functions.invoke("updateAIInstructions",{instructions:x,confirmationCode:C});if((s=n.data)!=null&&s.success){const y=await c.entities.SiteSettings.filter({settings_key:"main"});y.length>0&&await c.entities.SiteSettings.update(y[0].id,{ai_agent_phone:g,ai_agent_greeting:p}),J(x),X(g),z(p),q(!1),k(!0),setTimeout(()=>k(!1),3e3)}else f(((a=n.data)==null?void 0:a.error)||"Failed to save instructions")}catch(n){console.error("Error saving instructions:",n),f(n.message)}finally{K(!1)}},we=()=>{L(D),F(H),M(P),f(""),k(!1)},ne=()=>{q(!1),B(""),j("")},ie=async()=>{if(b.trim()){U(!0),se(null),ae(null);try{const s=x.replace(/\{\{ai_agent_phone\}\}/g,g),a=await c.integrations.Core.InvokeLLM({prompt:`${s} 12 13--- 14 15User question: ${b}`});se({query:b,response:typeof a=="string"?a:(a==null?void 0:a.text)||JSON.stringify(a),timestamp:new Date().toISOString()})}catch(s){ae(s.message)}finally{U(!1)}}},R=x!==D||g!==H||p!==P,Ie=async s=>{E(s),Y(!0);try{V&&await c.entities.SiteSettings.update(V,{ai_agent_enabled:s})}catch{E(!s)}finally{Y(!1)}},Ce=[{title:"Be Explicit",description:"Clearly define what the AI should and shouldn't do. Avoid ambiguity.",example:`â 'Always mention price if available' 16â 'Talk about price sometimes'`},{title:"Set Priorities",description:"List instructions in order of importance. The AI follows them top to bottom.",example:`1. Accuracy first 172. Be helpful 183. Keep responses concise`},{title:"Include Examples",description:"Show the AI how to respond with concrete examples.",example:"When asked about availability: 'This vessel is currently available for inspection'"}
18,{title:"Define Constraints",description:"Set clear boundaries for what the AI cannot do.",example:"Never provide financial advice or guarantee vessel conditions"}];return he?e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsx(N,{className:"w-8 h-8 animate-spin text-[#1E4D8C]"})}):(u==null?void 0:u.role)!=="admin"?e.jsxs("div",{className:"min-h-screen bg-gray-50",children:[e.jsx(oe,{user:u}),e.jsxs("div",{className:"lg:ml-64",children:[e.jsx(de,{title:"AI Agent",subtitle:"Access Denied"}),e.jsx("main",{className:"p-6",children:e.jsx(i,{children:e.jsxs(r,{className:"py-12 text-center",children:[e.jsx(re,{className:"w-12 h-12 mx-auto mb-3 text-red-500"}),e.jsx("p",{className:"text-gray-600 font-medium",children:"Admin access required"})]})})})]})]}):e.jsxs("div",{className:"min-h-screen bg-gray-50",children:[e.jsx(oe,{user:u}),e.jsxs("div",{className:"lg:ml-64",children:[e.jsx(de,{title:"AI Agent Management",subtitle:"Configure vessel assistant behavior & instructions"}),e.jsxs("main",{className:"p-6",children:[e.jsxs(v,{className:"mb-6 border-amber-500 bg-amber-50",children:[e.jsx(A,{className:"w-5 h-5 text-amber-600"}),e.jsxs(w,{className:"text-amber-800 ml-2",children:[e.jsx("strong",{children:"Warning:"})," Changes to AI instructions can significantly impact system behavior. All modifications require confirmation and are logged."]})]}),ue&&e.jsxs(v,{className:"mb-6 border-green-500 bg-green-50",children:[e.jsx(Se,{className:"h-4 w-4 text-green-600"}),e.jsx(w,{className:"text-green-800 ml-2",children:"AI instructions updated successfully and logged."})]}),ee&&e.jsxs(v,{className:"mb-6 border-red-500 bg-red-50",children:[e.jsx(A,{className:"w-5 h-5 text-red-600"}),e.jsx(w,{className:"text-red-800 ml-2",children:ee})]}),e.jsxs(i,{className:"mb-6",children:[e.jsxs(o,{children:[e.jsxs(d,{className:"flex items-center gap-2",children:[e.jsx(Be,{className:"w-5 h-5"}),"AI Agent Status"]}),e.jsx(_,{children:"Globally enable or disable all AI-powered features across the platform"})]}),e.jsxs(r,{children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-xl bg-gray-50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-[#0A2540]",children:"AI Agent"}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:m?"AI features are active. The AI assistant is available site-wide.":"AI features are disabled. All AI buttons and assistants are hidden."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[W&&e.jsx(N,{className:"w-4 h-4 animate-spin text-gray-400"}),e.jsx("span",{className:`text-sm font-medium ${m?"text-green-600":"text-gray-400"}`,children:m?"ON":"OFF"}),e.jsx(Te,{checked:m,onCheckedChange:Ie,disabled:W})]})]}),e.jsx("div",{className:`mt-3 rounded-xl p-3 border ${m?"bg-green-50 border-green-200":"bg-red-50 border-red-200"}`,children:e.jsx("p",{className:`text-sm font-medium ${m?"text-green-800":"text-red-800"}`,children:m?"â AI Agent is enabled â all AI-powered features are active across the platform.":"â AI Agent is disabled â all AI buttons, assistants, and prompts are hidden site-wide."})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(i,{children:[e.jsxs(o,{children:[e.jsx(d,{children:"AI Agent Configuration"}),e.jsx(_,{children:"Configure contact information and greeting message for the AI agent"})]}),e.jsxs(r,{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx(S,{htmlFor:"ai-phone",children:"AI Agent Phone Number"}),e.jsx($,{id:"ai-phone",type:"tel",value:g,onChange:s=>F(s.target.value),placeholder:"+32 3 226 24 10",className:"mt-2"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-2",children:["This phone number will automatically replace ","{{ai_agent_phone}}"," in the AI instructions"]})]}),e.jsxs("div",{className:"border-t pt-6",children:[e.jsx(S,{htmlFor:"ai-greeting",children:"Standard Greeting Message"}),e.jsx(le,{id:"ai-greeting",value:p,onChange:s=>M(s.target.value),rows:4,className:"mt-2",placeholder:"Hello! I'm your AI assistant..."}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"This greeting will be shown automatically when visitors start a new chat session"})]})]})]}),e.jsxs(i,{children:[e.jsxs(o,{children:[e.jsxs(d,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"AI Instru
18ctions & Behavior"}),e.jsxs(T,{variant:"outline",className:"text-xs",children:[x.length," characters"]})]}),e.jsx(_,{children:"Define how the AI assistant should behave, respond, and prioritize information"})]}),e.jsxs(r,{className:"space-y-4",children:[e.jsx(le,{value:x,onChange:s=>L(s.target.value),rows:20,className:"font-mono text-sm",placeholder:"Enter detailed instructions for the AI agent..."}),e.jsxs("div",{className:"p-4 bg-blue-50 rounded-lg border border-blue-200",children:[e.jsxs("h4",{className:"font-medium text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(Re,{className:"w-4 h-4"}),"Instruction Priority Order"]}),e.jsxs("ol",{className:"text-sm text-blue-800 space-y-1 ml-4 list-decimal",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"System Rules"})," - Built-in safety and compliance (highest priority)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Your Instructions"})," - Custom behavior defined above"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"User Input"})," - Specific questions from visitors (lowest priority)"]})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsx("div",{className:"flex items-center gap-2",children:R&&e.jsxs("span",{className:"text-sm text-amber-600 flex items-center gap-1",children:[e.jsx(A,{className:"w-4 h-4"}),"Unsaved changes"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(I,{variant:"outline",onClick:we,disabled:!R||h,children:[e.jsx(_e,{className:"w-4 h-4 mr-2"}),"Cancel"]}),e.jsx(I,{onClick:ve,disabled:!R||h,className:"bg-[#0A2540] hover:bg-[#1E4D8C]",children:h?e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"w-4 h-4 mr-2 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2"}),"Save Instructions"]})})]})]})]})]}),e.jsxs(i,{children:[e.jsxs(o,{children:[e.jsxs(d,{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"w-5 h-5"}),"Test Your Instructions"]}),e.jsx(_,{children:"Preview how the AI responds with your current instructions"})]}),e.jsxs(r,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 mb-2 block",children:"Test Query"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx($,{value:b,onChange:s=>be(s.target.value),placeholder:"Ask a question as a visitor would...",onKeyDown:s=>s.key==="Enter"&&ie()}),e.jsx(I,{onClick:ie,disabled:Q||!b.trim(),children:Q?e.jsx(N,{className:"w-4 h-4 animate-spin"}):e.jsx(ke,{className:"w-4 h-4"})})]})]}),G&&e.jsxs("div",{className:"border rounded-lg p-4 bg-gray-50",children:[e.jsx("div",{className:"text-sm font-medium text-gray-700 mb-2",children:"AI Response:"}),e.jsx("div",{className:"text-sm text-gray-900 whitespace-pre-wrap",children:G.response}),e.jsxs("div",{className:"text-xs text-gray-500 mt-3",children:["Tested at ",new Date(G.timestamp).toLocaleTimeString()]})]}),te&&e.jsxs(v,{className:"border-red-200 bg-red-50",children:[e.jsx(Oe,{className:"h-4 w-4 text-red-600"}),e.jsx(w,{className:"text-red-800",children:te})]}),e.jsx("div",{className:"text-xs text-gray-500 italic",children:"Note: This is a preview. Actual responses may vary based on vessel data and context."})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(i,{children:[e.jsx(o,{children:e.jsxs(d,{className:"text-sm flex items-center gap-2",children:[e.jsx(Ee,{className:"w-4 h-4"}),"Security"]})}),e.jsxs(r,{className:"text-xs text-gray-600 space-y-2",children:[e.jsx("p",{children:"⢠All changes require 7-digit confirmation code"}),e.jsx("p",{children:"⢠Only admins can modify instructions"}),e.jsx("p",{children:"⢠All modifications are audited and logged"})]})]}),e.jsxs(i,{children:[e.jsx(o,{children:e.jsxs(d,{className:"text-sm flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4"}),"Audit Trail"]})}),e.jsxs(r,{className:"text-xs text-gray-600 space-y-2",children:[e.jsx("p",{children:"⢠View all changes in Audit Log"}),e.jsx("p",{children:"⢠Track who made changes and when"}),e.jsx("p",{children:"⢠Compare before/after values"})]})]}),e.jsxs(i,{children:[e.jsx(o,{children:e.jsx(d,{className:"text-base",children:"Writing Effective Prompts"})}),e.jsx(r,{className:"space-y-4",children:Ce.map((s,a)=>e.jsxs("div",{className:"border-b pb-4 last:border-0 last:pb-0",children:[e.jsx("h4",{className:"font-medium text-sm text-gray-900 mb-1",children:s.title}),e.jsx("p",{className:"text-xs text-gray-600 mb-2",children:s.description}),e.jsx("pre",{className:"text-xs bg-gray-50 p-2 rounded border text-gray-700 whitespace-pre-wrap",children:s.example})]},a))})]}),e.jsxs(i,{children:[e.jsx(o,{children:e.jsx(d,{className:"text-base",children:"Agent Capabilities"})}),e.jsx(r,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-gray-600",children:"Data Access"}),e.jsx(T,{variant:"outline",children:"Vessel Listings"})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-gray-600",children:"Availability"}),e.jsx(T,{className:"bg-green-100 text-green-700",children:"24/7"})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-gray-600",children:"Response Time"}),e.jsx(T,{variant:"outline",children:"Instant"})]})]})})]})]})]})]})]}),e.jsx(Le,{open:je,onOpenChange:ne,children:e.jsxs(Fe,{className:"sm:max-w-md",children:[e.jsxs(He,{children:[e.jsxs(Me,{className:"flex items-center gap-2",children:[e.jsx(re,{className:"w-5 h-5 text-amber-600"}
18),"Confirm AI Instruction Changes"]}),e.jsx(Pe,{children:"You are about to modify the AI agent's instructions. This will affect how the AI responds to users."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs(v,{className:"border-amber-500 bg-amber-50",children:[e.jsx(A,{className:"w-4 h-4 text-amber-600"}),e.jsx(w,{className:"text-amber-800 ml-2 text-sm",children:"This action will be permanently logged in the audit trail."})]}),e.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg border",children:[e.jsx(S,{className:"text-sm font-medium",children:"Confirmation Code"}),e.jsx("p",{className:"text-2xl font-mono font-bold text-center my-4 tracking-widest text-[#0A2540]",children:Z}),e.jsx("p",{className:"text-xs text-gray-500 text-center",children:"Enter this code below to confirm changes"})]}),e.jsxs("div",{children:[e.jsx(S,{htmlFor:"code-input",children:"Enter Confirmation Code"}),e.jsx($,{id:"code-input",type:"text",inputMode:"numeric",pattern:"[0-9]*",maxLength:7,value:C,onChange:s=>{B(s.target.value.replace(/\D/g,"")),j("")},placeholder:"0000000",className:`mt-1 font-mono text-lg text-center tracking-widest ${O?"border-red-500":""}`}),O&&e.jsxs("p",{className:"text-sm text-red-600 mt-1 flex items-center gap-1",children:[e.jsx(A,{className:"w-3 h-3"}),O]})]})]}),e.jsxs(qe,{children:[e.jsx(I,{variant:"outline",onClick:ne,disabled:h,children:"Cancel"}),e.jsx(I,{onClick:Ae,disabled:C.length!==7||h,className:"bg-[#0A2540] hover:bg-[#1E4D8C]",children:h?e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"w-4 h-4 mr-2 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2"}),"Confirm & Save"]})})]})]})})]})}export{Ze 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.