1import{d as F,u as L,b as m,j as e}from"./vendor-query-DPZO-Gta.js";import{b as V,r as y,L as _}from"./vendor-react-BomFe3BT.js";import{z as l,t as n,i as q}from"./index-BLzMsaFd.js";import{u as z}from"./useChatbotTabs-TDDcKjl5.js";import"./vendor-charts-DodUWJ0z.js";const f={send_email:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),search_knowledge_base:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),transfer_call:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"})}),create_crm_task:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),book_appointment:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),custom_webhook:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})})};function R(){const{id:C,botId:b}=V(),r=b||C,i=F(),[a,c]=y.useState(null),[M,d]=y.useState(!1),[u,v]=y.useState({}),{data:p}=L({queryKey:["chatbot",r],queryFn:async()=>(await q.get(r)).data}),{data:o,isLoading:T}=L({queryKey:["chatbot-tools",r],queryFn:async()=>(await n.list(r)).data,enabled:!!r}),N=m({mutationFn:async s=>n.create(r,s),onSuccess:()=>{i.invalidateQueries({queryKey:["chatbot-tools",r]}),l.success("Tool added successfully"),d(!1)},onError:s=>{var t,h;l.error(((h=(t=s.response)==null?void 0:t.data)==null?void 0:h.detail)||"Failed to add tool")}}),W=m({mutationFn:async s=>n.toggle(r,s),onSuccess:()=>{i.invalidateQueries({queryKey:["chatbot-tools",r]}),l.success("Tool updated")},onError:()=>{l.error("Failed to update tool")}}),x=m({mutationFn:async({toolId:s,data:t})=>n.update(r,s,t),onSuccess:()=>{i.invalidateQueries({queryKey:["chatbot-tools",r]}),l.success("Tool configuration saved"),c(null)},onError:()=>{l.error("Failed to save configuration")}}),g=m({mutationFn:async s=>n.delete(r,s),onSuccess:()=>{i.invalidateQueries({queryKey:["chatbot-tools",r]}),l.success("Tool removed"),c(null)},onError:()=>{l.error("Failed to remove tool")}}),A=z(r,"Tools"),k=!!b,j=(o==null?void 0:o.available_tools.filter(s=>!o.tools.some(t=>t.tool_type===s.tool_type)))||[],S=s=>{N.mutate({tool_type:s.tool_type,name:s.name.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())})},B=()=>{a&&x.mutate({toolId:a.id,data:{config:u}})},w=s=>{switch(s){case"send_email":return[{key:"from_name",label:"Sender Name",placeholder:"e.g., Sales Team"}];case"transfer_call":return[{key:"default_transfer_number",label:"Default Transfer Number",placeholder:"+1234567890"}];case"custom_webhook":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://your-api.com/webhook"}];default:return[]}};return e.jsxs("div",{children:[!k&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx(_,{to:"/chatbots",className:"text-gray-500 hover:text-gray-700",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})})}),e.jsxs("h1",{className:"text-2xl font-bold text-gray-900",children:[p==null?void 0:p.name," - Voice Tools"]})]}),e.jsx("div",{className:"border-b border-gray-200 mb-6",children:e.jsx("nav",{className:"-mb-px flex space-x-8",children:A.map(s=>e.jsx(_,{to:s.href,className:`py-4 px-1 border-b-2 font-medium text-sm ${s.current?"border-primary-500 text-primary-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:s.name},s.name))})})]}),k&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Voice Tools"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Configure AI-powered tools for your voice bot"})]}),e.jsx("div",{className:"card p-6 mb-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"p-3 bg-primary-100 rounded-lg",children:e.jsx("svg",{className:"w-6 h-6 text-primary-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Voice Function Calling"}),e.jsx("p",{className:"text-gray-600 mt-1",children:"Enable tools that your voice assistant can use during calls. When enabled, the assistant can perform actions like sending emails, creating tasks, or transferring calls based on the conversation."})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Active Tools"}),j.length>0&&e.jsx("button",{onClick:()=>d(!0),className:"btn-primary text-sm",children:"Add Tool"})]}),T?e.jsx("div",{className:"text-center py-8 text-gray-500",children:"Loading tools..."}):(o==null?void 0:o.tools.length)===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("svg",{className:"w-12 h-12 mx-auto text-gray-300 mb-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No tools configured"}),e.jsx("p",{className:"text-gray-500 mb-4",children:"Add tools to enable function calling in voice conversations."}),e.jsx("button",{onClick:()=>d(!0),className:"btn-primary",children:"Add Your First Tool"})]}):e.jsx("div",{className:"space-y-4",children:o==null?void 0:o.tools.map(s=>{var t;return e.jsx("div",{className:`border rounded-lg p-4 transition-colors ${s.is_enabled?"border-gray-200 bg-white":"border-gray-100 bg-gray-50"}`,children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${s.is_enabled?"bg-primary-100 text-primary-600":"bg-gray-100 text-gray-400"}`,children:f[s.tool_type]||e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16m-7 6h7"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-gray-900",children:s.name}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:s.description||((t=o.available_tools.find(h=>h.tool_type===s.tool_type))==null?void 0:t.description)}),s.total_calls>0&&e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-xs text-gray-400",children:[e.jsxs("span",{children:[s.total_calls," calls"]}),e.jsxs("span",{className:"text-green-500",children:[s.successful_calls," successful"]}),s.failed_calls>0&&e.jsxs("span",{className:"text-red-500",children:[s.failed_calls," failed"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{c(s),v(s.config)},className:"p-2 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-lg",title:"Configure",children:e.jsxs("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:s.is_enabled,onChange:()=>W.mutate(s.id),className:"sr-only peer"}),e.jsx("div",{className:"w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-primary-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-primary-600"})]})]})]})},s.id)})})]})}),e.jsx("div",{className:"lg:col-span-1",children:a?e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Configure Tool"}),e.jsx("button",{onClick:()=>c(null),className:"text-gray-400 hover:text-gray-600",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-6 pb-4 border-b",children:[e.jsx("div",{className:"p-2 bg-primary-100 text-primary-600 rounded-lg",children:f[a.tool_type]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-gray-900",children:a.name}),e.jsx("p",{className:"text-sm text-gray-500",children:a.tool_type})]})]}),e.jsxs("div",{className:"space-y-4",children:[w(a.tool_type).length>0?e.jsxs(e.Fragment,{children:[w(a.tool_type).map(s=>e.jsxs("div",{children:[e.jsx("label",{className:"label",children:s.label}),e.jsx("input",{type:s.type||"text",value:u[s.key]||"",onChange:t=>v({...u,[s.key]:t.target.value}),placeholder:s.placeholder,className:"input"})]},s.key)),e.jsx("button",{onClick:B,disabled:x.isPending,className:"btn-primary w-full",children:x.isPending?"Saving...":"Save Configuration"})]}):e.jsx("p",{className:"text-sm text-gray-500",children:"This tool has no additional configuration options."}),e.jsx("div",{className:"pt-4 border-t",children:e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.requires_confirmation,onChange:()=>{x.mutate({toolId:a.id,data:{requires_confirmation:!a.requires_confirmation}})},className:"rounded border-gray-300 text-primary-600"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-700 font-medium",children:"Require Confirmation"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Ask user before executing this action"})]})]})}),e.jsx("button",{onClick:()=>{confirm("Are you sure you want to remove this tool?")&&g.mutate(a.id)},disabled:g.isPending,className:"w-full px-4 py-2 text-red-600 border border-red-200 rounded-lg hover:bg-red-50 transition-colors text-sm",children:g.isPending?"Removing...":"Remove Tool"})]})]}):e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"How It Works"}),e.jsxs("div",{className:"space-y-4 text-sm text-gray-600",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex-shrink-0 w-6 h-6 bg-primary-100 text-primary-600 rounded-full flex items-center justify-center text-xs font-medium",children:"1"}),e.jsx("p",{children:"Add tools that you want your voice assistant to use during calls."})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex-shrink-0 w-6 h-6 bg-primary-100 text-primary-600 rounded-full flex items-center justify-center text-xs font-medium",children:"2"}),e.jsx("p",{children:"The assistant will automatically know when to use each tool based on the conversation."})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex-shrink-0 w-6 h-6 bg-primary-100 text-primary-600 rounded-full flex items-center justify-center text-xs font-medium",children:"3"}),e.jsx("p",{children:"When a tool is triggered, it executes the action and reports the result back to the caller."})]})]}),e.jsx("div",{className:"mt-6 p-4 bg-yellow-50 border border-yellow-100 rounded-lg",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("svg",{className:"w-5 h-5 text-yellow-600 flex-shrink-0 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-yellow-800 font-medium",children:"Voice Feature Required"}),e.jsx("p",{className:"text-xs text-yellow-700 mt-1",children:"Tools are only used during voice calls. Make sure voice is enabled in your chatbot settings."})]})]})})]})})]}),M&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-lg w-full mx-4 max-h-[80vh] overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Add Tool"}),e.jsx("button",{onClick:()=>d(!1),className:"text-gray-400 hover:text-gray-600",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Select a tool to add to your voice assistant."})]}),e.jsx("div",{className:"p-6 overflow-y-auto max-h-96",children:j.length===0?e.jsx("p",{className:"text-center text-gray-500 py-4",children:"All available tools have been added."}):e.jsx("div",{className:"space-y-3",children:j.map(s=>e.jsx("button",{onClick:()=>S(s),disabled:N.isPending,className:"w-full text-left p-4 border rounded-lg hover:border-primary-300 hover:bg-primary-50 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 bg-gray-100 text-gray-600 rounded-lg",children:f[s.tool_type]||e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16m-7 6h7"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-gray-900",children:s.name.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:s.description})]})]})},s.tool_type))})})]})})]})}export{R 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.