PageSourceSearch

https://flowtrackai-crm.vercel.app/_next/static/chunks/pages/dashboard/assistants/[id]-455a08c9ff95f590.js

js flowtrackai-crm.vercel.app collected 2026-10-03 07:00:32 UTC 89,230 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8242],{31452:(e,t,r)=>{"use strict";r.d(t,{A:()=>d});var a=r(37876);r(14232);var s=r(89099),l=r(15807),n=r(62125),i=r(28567),o=r(31010);let d=e=>{let{title:t="Access Denied",message:r="You don't have permission to access this section.",description:d,requiredRoles:c,redirectPath:m="/dashboard",redirectText:u="Back to Dashboard",icon:g,variant:x="danger"}=e,h=(0,s.useRouter)(),{iconColor:b,icon:y}=(()=>{switch(x){case"warning":return{iconColor:"text-yellow-500",icon:g||o.A};case"info":return{iconColor:"text-blue-500",icon:g||o.A};default:return{iconColor:"text-red-500",icon:g||o.A}}})();return(0,a.jsx)(i.Zp,{children:(0,a.jsxs)(i.Wu,{className:"p-8 text-center",children:[(0,a.jsx)(y,{className:"h-16 w-16 ".concat(b," mx-auto mb-4")}),(0,a.jsx)("h3",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:t}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400 mb-4",children:r}),d&&(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-500 mb-4",children:d}),c&&(0,a.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-500 mb-6",children:["Required role: ",c]}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 justify-center",children:[(0,a.jsx)(n.$,{variant:"outline",onClick:()=>h.push(m),className:"w-full sm:w-auto",children:u}),(0,a.jsx)(n.$,{variant:"ghost",onClick:()=>(0,l.Tl)(h),className:"w-full sm:w-auto",children:"Go Back"})]})]})})}},34260:(e,t,r)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/dashboard/assistants/[id]",function(){return r(48365)}])},48365:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>H});var a=r(37876),s=r(89099),l=r(14232),n=r(94246),i=r(35845),o=r(19739),d=r(91040),c=r(97685),m=r(47043),u=r(68974),g=r(96668);function x(e){let{onSelect:t,toolIds:r=[]}=e,[s,n]=(0,l.useState)([]),[i,o]=(0,l.useState)(!0),[d,c]=(0,l.useState)(""),[x,h]=(0,l.useState)(""),[b,y]=(0,l.useState)("name"),[p,f]=(0,l.useState)("asc"),[v,k]=(0,l.useState)("grid");(0,l.useEffect)(()=>{j()},[]);let j=async()=>{o(!0),c("");try{let e=await fetch("/api/assistants-tools"),t=await e.json();e.ok?n(Array.isArray(t)?t:t.tools||[]):c(t.error||"Failed to load tools")}catch(e){c(e.message)}finally{o(!1)}},w=s.filter(e=>{var t,r,a,s,l,n;let i=x.toLowerCase();return(null==(r=e.function)||null==(t=r.name)?void 0:t.toLowerCase().includes(i))||(null==(a=e.name)?void 0:a.toLowerCase().includes(i))||(null==(s=e.type)?void 0:s.toLowerCase().includes(i))||(null==(n=e.function)||null==(l=n.description)?void 0:l.toLowerCase().includes(i))}).sort((e,t)=>{var r,a;let s=e[b]||(null==(r=e.function)?void 0:r[b])||"",l=t[b]||(null==(a=t.function)?void 0:a[b])||"";return("string"==typeof s&&(s=s.toLowerCase()),"string"==typeof l&&(l=l.toLowerCase()),s<l)?"asc"===p?-1:1:s>l?"asc"===p?1:-1:0});return(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 items-center justify-between",children:[(0,a.jsxs)("div",{className:"relative flex-1 w-full",children:[(0,a.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),placeholder:"Search tools...",className:"w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white"}),(0,a.jsx)(m.A,{className:"absolute left-3 top-2.5 h-5 w-5 text-gray-400"})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>k("grid"===v?"list":"grid"),className:"p-2 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg",children:"grid"===v?(0,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16m-7 6h7"})}):(0,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),(0,a.jsxs)("select",{value:b,onChange:e=>y(e.target.value),className:"px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white",children:[(0,a.jsx)("option",{value:"name",children:"Sort by Name"}),(0,a.jsx)("option",{value:"type",children:"Sort by Type"}),(0,a.jsx)("option",{value:"createdAt",children:"Sort by Date"})]}),(0,a.jsx)("button",{type:"button",onClick:()=>f("asc"===p?"desc":"asc"),className:"p-2 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg",title:"Toggle sort order",children:"asc"===p?(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})}):(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]})]}),i&&(0,a.jsxs)("div",{className:"flex items-center gap-2 p-4 bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg text-gray-500 dark:text-gray-400",children:[(0,a.jsx)(u.A,{className:"w-5 h-5 animate-spin"}),"Loading tools..."]}),d&&(0,a.jsx)("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-md text-red-700 dark:text-red-400 text-sm",children:d}),!i&&!d&&0===w.length&&(0,a.jsx)("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg text-gray-500 dark:text-gray-400",children:"No tools found."}),!i&&!d&&w.length>0&&(0,a.jsx)("div",{className:"grid"===v?"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4":"space-y-2",children:w.map(e=>{var s,l,n,i;let o=e.id||(null==(s=e.function)?void 0:s.name),d=r.includes(o);return(0,a.jsxs)("div",{className:"relative cursor-pointer p-4 border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800/50 shadow-sm hover:shadow-md transition-shadow duration-200 ".concat(d?"ring-2 ring-indigo-500":""," ").concat("grid"===v?"":"flex justify-between items-center"),onClick:()=>(e=>{var a;if(!t)return;let s=e.id||(null==(a=e.function)?void 0:a.name);r.includes(s)||t(e)})(e),children:[(0,a.jsxs)("div",{className:"grid"===v?"w-full":"flex-1 min-w-0 pr-4",children:[(0,a.jsx)("div",{className:"flex justify-between items-start w-full",children:(0,a.jsxs)("div",{className:"flex-1 min-w-0 pr-4",children:[(0,a.jsx)("h5",{className:"font-medium text-sm text-gray-900 dark:text-white truncate",children:(null==(l=e.function)?void 0:l.name)||e.name||"Unnamed Tool"}),(0,a.jsx)("p",{className:"text-xs text-gray-600 dark:text-gray-400 mt-1 line-clamp-2",children:(null==(n=e.function)?void 0:n.description)||e.description||"No description"})]})}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-x-2 gap-y-1 mt-2 items-center",children:[(0,a.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 dar
1k:bg-blue-900/50 text-blue-800 dark:text-blue-300 whitespace-nowrap",children:e.method||(null==(i=e.function)?void 0:i.method)||"API"}),(0,a.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-900/50 text-purple-800 dark:text-purple-300 whitespace-nowrap",children:e.type||"Type"}),e.orgId&&(0,a.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/50 text-green-800 dark:text-green-300 whitespace-nowrap",children:"Org"})]})]}),d&&(0,a.jsx)(g.A,{className:"absolute top-2 right-2 w-6 h-6 text-indigo-500"})]},o)})})]})}var h=r(49038);function b(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!0===e||"true"===e||!1!==e&&"false"!==e&&t}function y(e){return[{key:"name",type:"short_text",label:"Name",placeholder:"Enter your full name",required:!1,show:b(e.showNameField,!0)},{key:"email",type:"email",label:"Email Address",placeholder:"Enter your email address",required:!0,show:b(e.showEmailField,!0)},{key:"phone",type:"phone",label:"Phone Number",placeholder:"+1 (555) 123-4567",required:!0,show:b(e.showPhoneField,!0)},{key:"company",type:"short_text",label:"Company Name",placeholder:"Enter your company name",required:!1,show:b(e.showCompanyField,!0)},{key:"website",type:"url",label:"Website URL",placeholder:"https://yourcompany.com",required:!1,show:b(e.showWebsiteField,!1)}].filter(e=>e.show).map((e,t)=>({id:"legacy_".concat(e.key),key:e.key,type:e.type,label:e.label,placeholder:e.placeholder,required:e.required,order:t,system:!0}))}let p=function(e){let{assistantId:t="",assistantName:r="AI Assistant",apiEndpoint:s="https://flowtrackai-crm.vercel.app/api/assistant/voxasuite-call-with-variables",apiKey:n="",theme:i="light",showInfoMessage:o="true",submitButtonText:d="Submit",formTitle:c="Contact Us",formSubheading:m="Fill out the form below and we'll get back to you.",titleAlign:u="left",primaryColor:g="#d2bb70",secondaryColor:x="#dcdcdc",fontFamily:b="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",fontSize:p="",formBackgroundColor:f="",showNameField:v="true",showEmailField:k="true",showPhoneField:j="true",showCompanyField:w="true",showWebsiteField:N="false",formContentAlign:C="left",fieldLayout:S="grid",submitButtonColor:A="",submitButtonHoverColor:B="",submitButtonFullWidth:T="true",submitButtonAlign:M="center",configMode:F="remote",formConfig:L=null,previewMode:E=!1}=e,[z,I]=(0,l.useState)(null),[W,P]=(0,l.useState)("remote"===F&&!!t&&!L),[_,R]=(0,l.useState)(null),[D,q]=(0,l.useState)({}),[H,U]=(0,l.useState)({}),[V,O]=(0,l.useState)(!1),[Y,G]=(0,l.useState)(null),[J,K]=(0,l.useState)("");(0,l.useEffect)(()=>{if(L||"attributes"===F||"inline"===F||!t||"remote"!==F)return void P(!1);let e=!1,r=function(e,t){var r;if(!t)return null;try{if(e&&/^https?:\/\//i.test(e)){let r=new URL(e);return"".concat(r.origin,"/api/assistant/personalization-form/").concat(encodeURIComponent(t))}}catch(e){}return(null==(r=window.location)?void 0:r.origin)?"".concat(window.location.origin,"/api/assistant/personalization-form/").concat(encodeURIComponent(t)):"/api/assistant/personalization-form/".concat(encodeURIComponent(t))}(s,t);return P(!0),R(null),fetch(r).then(async t=>{let r=await t.json().catch(()=>({}));if(!t.ok)throw Error(r.error||"Failed to load form config");!e&&r.form&&I(r.form)}).catch(t=>{e||(console.warn("[PersonalizationFormWidget] config load:",t),R(t.message),I(null))}).finally(()=>{e||P(!1)}),()=>{e=!0}},[t,s,F,L]);let $=(0,l.useMemo)(()=>{let e=L||z;if(e&&("inline"===F||"remote"===F)){var t,r,a;let s=e.theme||{};return{formTitle:null!=(t=e.formTitle)?t:c,formSubheading:null!=(r=e.formSubheading)?r:m,submitButtonText:e.submitButtonText||d,themeMode:s.themeMode||i,primaryColor:s.primaryColor||g,secondaryColor:s.secondaryColor||x,fontFamily:s.fontFamily||b,fontSize:s.fontSize||p,formBackgroundColor:null!=(a=s.formBackgroundColor)?a:f,titleAlign:s.titleAlign||u,formContentAlign:s.formContentAlign||C,fieldLayout:s.fieldLayout||S,submitButtonColor:s.submitButtonColor||A,submitButtonHoverColor:s.submitButtonHoverColor||B,submitButtonFullWidth:!0===s.submitButtonFullWidth||"true"===s.submitButtonFullWidth?"true":!1===s.submitButtonFullWidth||"false"===s.submitButtonFullWidth?"fal
1se":T,submitButtonAlign:s.submitButtonAlign||M,fields:Array.isArray(e.fields)?[...e.fields].sort((e,t)=>{var r,a;return(null!=(r=e.order)?r:0)-(null!=(a=t.order)?a:0)}):y({showNameField:v,showEmailField:k,showPhoneField:j,showCompanyField:w,showWebsiteField:N}),fromRemote:!!(z||L)}}return{formTitle:c,formSubheading:m,submitButtonText:d,themeMode:i,primaryColor:g,secondaryColor:x,fontFamily:b,fontSize:p,formBackgroundColor:f,titleAlign:u,formContentAlign:C,fieldLayout:S,submitButtonColor:A,submitButtonHoverColor:B,submitButtonFullWidth:T,submitButtonAlign:M,fields:y({showNameField:v,showEmailField:k,showPhoneField:j,showCompanyField:w,showWebsiteField:N}),fromRemote:!1}},[L,z,F,c,m,d,i,g,x,b,p,f,u,C,S,A,B,T,M,v,k,j,w,N]);(0,l.useEffect)(()=>{q(e=>{let t={...e};for(let e of $.fields)void 0===t[e.key]&&(t[e.key]="");return t})},[$.fields]);let X=(e,t)=>{if(!e||!String(e).trim())return t.required?"".concat(t.label||t.key," is required"):null;let r=String(e).trim();if("email"===t.type||"email"===t.key)return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)?null:"Please enter a valid email address";if("phone"===t.type||"phone"===t.key){let e=r.replace(/\D/g,"");return e.length>=7&&e.length<=15?null:"Please enter a valid phone number"}return"url"===t.type||"website"===t.key?/^https?:\/\/.+/i.test(r)?null:"Please enter a valid website URL (starting with http:// or https://)":null},Q=(0,l.useCallback)(()=>{let e={},t=!0;for(let r of $.fields){let a=X(D[r.key],r);a&&(e[r.key]=a,t=!1)}return U(e),t},[$.fields,D]),Z=(0,l.useCallback)(async e=>{if((e.preventDefault(),!E)&&Q()){if(!t){G("error"),K("Assistant ID is required");return}O(!0),G(null),K("");try{let e={};for(let t of $.fields){let r=D[t.key];null!=r&&String(r).trim()&&(e[t.key]=String(r).trim())}let r={};e.name&&(r.name=e.name),e.email&&(r.email=e.email),e.phone&&(r.number=e.phone),e.company&&(r.company=e.company);let a=e.website||null,l={"Content-Type":"application/json"};n&&(l.Authorization="Bearer ".concat(n));let i=await fetch(s,{method:"POST",headers:l,body:JSON.stringify({assistantId:t,phoneNumber:e.phone||null,variableValues:e,customerInfo:r,callType:e.phone?"outboundPhoneCall":"webCall",websiteUrl:a,formSource:"personalization_form"})});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error||"Failed to start call")}G("success"),K("Success!"),setTimeout(()=>{let e={};for(let t of $.fields)e[t.key]="";q(e),G(null),K("")},3e3)}catch(e){console.error("❌ [PersonalizationFormWidget] Error:",e),G("error"),K(e.message||"Error. Please try again.")}finally{O(!1)}}},[E,Q,t,$.fields,D,n,s]),ee="dark"===$.themeMode,et=ee?"pcfw-dark":"pcfw-light",er={"--pcfw-primary":$.primaryColor,"--pcfw-secondary":$.secondaryColor,"--pcfw-font-family":$.fontFamily,"--pcfw-font-size":$.fontSize||null,"--pcfw-form-background-color":"transparent"===$.formBackgroundColor?"transparent":$.formBackgroundColor||(ee?"#1f2937":"#ffffff"),"--pcfw-submit-button-color":$.submitButtonColor||$.primaryColor,"--pcfw-submit-button-hover-color":$.submitButtonHoverColor||$.primaryColor},ea="transparent"===$.formBackgroundColor?{boxShadow:"none",border:"none"}:{},es="pcfw-content-align-".concat($.formContentAlign),el=$.fields,en=e=>{let t="long_text"===e.type,r={value:D[e.key]||"",onChange:t=>{var r,a;return r=e.key,a=t.target.value,void(q(e=>({...e,[r]:a})),H[r]&&U(e=>{let t={...e};return delete t[r],t}))},placeholder:e.placeholder||"",className:"pcfw-input",required:!!e.required,disabled:E&&!1};return(0,a.jsxs)("div",{className:"pcfw-field",children:[(0,a.jsxs)("label",{className:"pcfw-label",children:[e.label||e.key,e.required?" *":""]}),t?(0,a.jsx)("textarea",{...r,rows:3}):(0,a.jsx)("input",{type:function(e){switch(e.type){case"email":return"email";case"phone":return"tel";case"url":return"url";case"number":return"number";default:return"text"}}(e),...r}),H[e.key]&&(0,a.jsx)("p",{className:"pcfw-error",children:H[e.key]})]},e.id||e.key)};return W?(0,a.jsx)("div",{className:"pcfw-widget ".concat(et),style:er,children:(0,a.jsxs)("div",{className:"pcfw-container",style:{textAlign:"center",padding:24},children:[(0,a.jsx)(h.hW,{className:"pcfw-spinner"}),(0,a.jsx)("p",{className:"pcfw-form-subheading",style:{marginTop:8},children:"Loading form…"})]})}):(0,a.jsx)("div",{className:"pcfw-widget ".concat(et),style:er,children:(0,a.jsxs)("div",{className:"pcfw-container ".concat(es),style:ea,children:[($.formTitle||$.formSubheading)&&(0,a.jsxs)("div",{className:"pcfw-form-header pcfw-align-".concat($.titleAlign),children:[$.formTitle&&(0,a.jsx)("h2",{className:"pcfw-form-title",children:$.formTitle}),$.formSubheading&&(0,a.jsx)("p",{className:"pcfw-form-subheading",children:$.formSubheading})]}),_&&!$.fromRemote&&(0,a.jsxs)("p",{className:"pcfw-form-subheading",style:{opacity:.7},children:["Using default fields (",_,")"]}),(0,a.jsxs)("form",{onSubmit:Z,className:"pcfw-form",children:["inline"===$.fieldLayout?el.map(en):(0,a.jsx)(a.Fragment,{children:(()=>{let e=[];for(let t=0;t<el.length;t+=2)e.push(el.slice(t,t+2));return e.map((e,t)=>(0,a.jsx)("div",{className:"pcfw-field-grid",children:e.map(en)},"row-".concat(t)))})()}),Y&&(0,a.jsx)("div",{className:"pcfw-status pcfw-status-".concat(Y),children:J}),(0,a.jsx)("div",{className:"pcfw-submit-button-wrapper pcfw-submit-button-align-".concat($.submitButtonAlign),children:(0,a.jsx)("button",{type:"submit",disabled:V||!t||E,className:"pcfw-submit-button ".concat("false"===$.submitButtonFullWidth?"pcfw-submit-button-auto":""),children:V?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(h.hW,{className:"pcfw-spinner"}),(0,a.jsx)("span",{children:"Processing..."})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(h.CMH,{className:"pcfw-check-icon"}),(0,a.jsx)("span",{children:$.submitButtonText})]})})})]})]})})},f=["name","email","phone","company","website"],v=[{value:"short_text",label:"Short text"},{value:"long_text",label:"Long text"},{value:"email",label:"Email"},{value:"phone",label:"Phone"},{value:"url",label:"Website / URL"},{value:"number",label:"Number"}],k={name:{key:"name",type:"short_text",label:"Name",placeholder:"Enter your full name",required:!1,enabled:!0},email:{key:"email",type:"email",label:"Email Address",placeholder:"Enter your email address",required:!0,enabled:!0},phone:{key:"phone",type:"phone",label:"Phone Number",placeholder:"+1 (555) 123-4567",required:!0,enabled:!0},company:{key:"company",type:"short_text",label:"Company Name",placeholder:"Enter your company name",required:!1,enabled:!0},website:{key:"website",type:"url",label:"Website URL",placeholder:"https://yourcompany.com",required:!1,enabled:!0}};function j(){return"undefined"!=typeof crypto&&crypto.randomUUID?"pf_".concat(crypto.randomUUID().replace(/-/g,"").slice(0,12)):"pf_".concat(Date.now().toString(36),"_").concat(Math.random().toString(36).slice(2,8))}function w(){return{themeMode:"light",primaryColor:"#d2bb70",secondaryColor:"#dcdcdc",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",fontSize:"17px",formBackgroun
1dColor:"transparent",titleAlign:"center",formContentAlign:"center",fieldLayout:"inline",submitButtonColor:"#1691fb",submitButtonHoverColor:"#e7cf84",submitButtonFullWidth:!1,submitButtonAlign:"center"}}function N(){return{enabled:!0,formTitle:"",formSubheading:"",submitButtonText:"Submit",theme:w(),fields:f.map((e,t)=>{let r=k[e];return{id:j(),...r,order:t}})}}let C=new Set(v.map(e=>e.value));function S(e){var t,r;let a=N(),s=e&&"object"==typeof e?e:{},l=new Set,n=Array.isArray(s.fields)?s.fields.map((e,t)=>(function(e,t,r){var a,s,l,n,i;let o=e&&"object"==typeof e?e:{},d=String(o.key||"").trim(),c=f.includes(d);!c&&(!(d=String(d||o.label||"custom_".concat(t)||"").trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"").slice(0,48))||f.includes(d)||r.has(d))&&(d="custom_".concat(t,"_").concat(j().slice(-6))),r.add(d);let m=c&&(null==(a=k[d])?void 0:a.type)||"short_text",u=C.has(o.type)?o.type:m,g=c?(null==(s=k[d])?void 0:s.label)||d:"Custom field",x=c&&(null==(l=k[d])?void 0:l.placeholder)||"",h=!!c&&!!(null==(n=k[d])?void 0:n.required);return{id:String(o.id||j()).slice(0,64),key:d,type:u,label:String(o.label||g).slice(0,120),placeholder:String(null!=(i=o.placeholder)?i:x).slice(0,200),required:!0===o.required||"true"===o.required||null==o.required&&h,enabled:!1!==o.enabled&&"false"!==o.enabled,order:"number"==typeof o.order?o.order:t,system:c}})(e,t,l)):[];for(let e of f)if(!l.has(e)){let t=k[e];n.push({id:j(),...t,order:n.length,system:!0,enabled:t.enabled}),l.add(e)}return n=n.sort((e,t)=>{var r,a;return(null!=(r=e.order)?r:0)-(null!=(a=t.order)?a:0)}).map((e,t)=>({...e,order:t})),{enabled:!1!==s.enabled&&"false"!==s.enabled,formTitle:String(null!=(t=s.formTitle)?t:a.formTitle).slice(0,200),formSubheading:String(null!=(r=s.formSubheading)?r:a.formSubheading).slice(0,500),submitButtonText:String(s.submitButtonText||a.submitButtonText).slice(0,80),theme:function(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=w(),a=t&&"object"==typeof t?t:{};return{themeMode:"dark"===a.themeMode?"dark":"light",primaryColor:String(a.primaryColor||r.primaryColor).slice(0,32),secondaryColor:String(a.secondaryColor||r.secondaryColor).slice(0,32),fontFamily:String(a.fontFamily||r.fontFamily).slice(0,200),fontSize:String(a.fontSize||r.fontSize).slice(0,16),formBackgroundColor:String(null!=(e=a.formBackgroundColor)?e:r.formBackgroundColor).slice(0,32),titleAlign:["left","center","right"].includes(a.titleAlign)?a.titleAlign:r.titleAlign,formContentAlign:["left","center","right"].includes(a.formContentAlign)?a.formContentAlign:r.formContentAlign,fieldLayout:"grid"===a.fieldLayout?"grid":"inline",submitButtonColor:String(a.submitButtonColor||r.submitButtonColor).slice(0,32),submitButtonHoverColor:String(a.submitButtonHoverColor||r.submitButtonHoverColor).slice(0,32),submitButtonFullWidth:!0===a.submitButtonFullWidth||"true"===a.submitButtonFullWidth,submitButtonAlign:["left","center","right"].includes(a.submitButtonAlign)?a.submitButtonAlign:r.submitButtonAlign}}(s.theme),fields:n}}function A(e){return f.includes(String(e||""))}let B=[{id:"fields",label:"Fields"},{id:"design",label:"Design"},{id:"preview",label:"Preview"},{id:"embed",label:"Embed"}];function T(){let e={"Content-Type":"application/json"};{var t,r;let a=localStorage.getItem("tkn")||(null==(r=document.cookie)||null==(t=r.split(";").map(e=>e.trim()).find(e=>e.startsWith("tkn=")))?void 0:t.split("=").slice(1).join("="))||"";a&&(e.Authorization="Bearer ".concat(decodeURIComponent(a)))}return e}function M(e){var t,r,s,n,i,o;let{assistantId:d,assistantName:m="AI Assistant",initialConfig:u=null}=e,[g,x]=(0,l.useState)("fields"),[b,y]=(0,l.useState)(()=>S(u||N())),[k,w]=(0,l.useState)(!!d),[C,M]=(0,l.useState)(!1),F=(0,l.useCallback)(async()=>{if(!d)return void w(!1);w(!0);try{let e=await fetch("/api/assistant/personalization-form/".concat(encodeURIComponent(d)),{headers:T()}),t=await e.json();e.ok&&y(S(t.personalizationForm||t.form||N()))}catch(e){console.warn("[PersonalizationFormBuilder] load failed:",e),c.oR.error("Could not load form config")}finally{w(!1)}},[d]);(0,l.useEffect)(()=>{F()},[F]);let L=(e,t)=>{y(r=>({...r,theme:{...r.theme,[e]:t}}))},E=(e,t)=>{y(r=>({...r,fields:r.fields.map(r=>{var a;return r.id===e?{...r,...t,key:A(r.key)?r.key:null!=(a=t.key)?a:r.key}:r})}))},z=(e,t)=>{y(r=>{let a=[...r.fields].sort((e,t)=>
1e.order-t.order),s=a.findIndex(t=>t.id===e);if(s<0)return r;let l=s+t;if(l<0||l>=a.length)return r;let n=a[s];return a[s]=a[l],a[l]=n,{...r,fields:a.map((e,t)=>({...e,order:t}))}})},I=async()=>{if(!d)return void c.oR.error("Save the assistant first, then configure the form");M(!0);try{let e=S(b),t=await fetch("/api/assistant/personalization-form/".concat(encodeURIComponent(d)),{method:"PATCH",headers:T(),body:JSON.stringify({personalizationForm:e})}),r=await t.json();if(!t.ok)throw Error(r.error||"Failed to save");r.personalizationForm&&y(S(r.personalizationForm)),c.oR.success("Personalization form saved")}catch(e){c.oR.error(e.message||"Save failed")}finally{M(!1)}},W=window.location.origin,P=(0,l.useMemo)(()=>{let e=d||"YOUR_ASSISTANT_ID";return'<script\n  src="'.concat(W,'/widgets/personalization-form-widget.js"\n  async\n  type="text/javascript">\n<\/script>\n<personalization-form-widget\n  id="embedded-form-widget"\n  assistant-id="').concat(e,'"\n  api-endpoint="').concat(W,'/api/assistant/voxasuite-call-with-variables">\n</personalization-form-widget>')},[d,W]),_=(0,l.useMemo)(()=>{let e=b.theme||{},t={...b,fields:(b.fields||[]).filter(e=>!1!==e.enabled)};return{assistantId:d||"preview",assistantName:m,apiEndpoint:"".concat(W,"/api/assistant/voxasuite-call-with-variables"),formTitle:b.formTitle,formSubheading:b.formSubheading,submitButtonText:b.submitButtonText,theme:e.themeMode||"light",primaryColor:e.primaryColor,secondaryColor:e.secondaryColor,fontFamily:e.fontFamily,fontSize:e.fontSize,formBackgroundColor:e.formBackgroundColor,titleAlign:e.titleAlign,formContentAlign:e.formContentAlign,fieldLayout:e.fieldLayout,submitButtonColor:e.submitButtonColor,submitButtonHoverColor:e.submitButtonHoverColor,submitButtonFullWidth:e.submitButtonFullWidth?"true":"false",submitButtonAlign:e.submitButtonAlign,configMode:"inline",formConfig:t,previewMode:!0}},[b,d,m,W]),R=(0,l.useMemo)(()=>[...b.fields||[]].sort((e,t)=>e.order-t.order),[b.fields]);return k?(0,a.jsx)("div",{className:"rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-8 text-center text-gray-500",children:"Loading form configuration…"}):(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:"Form builder"}),(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Control fields, labels, and design. Embed loads this config automatically."})]}),(0,a.jsxs)("button",{type:"button",onClick:I,disabled:C||!d,className:"inline-flex items-center justify-center gap-2 px-4 py-2 rounded-lg bg-gray-900 dark:bg-white text-white dark:text-gray-900 text-sm font-medium hover:opacity-90 disabled:opacity-50",children:[(0,a.jsx)(h.dIn,{className:"w-3.5 h-3.5"}),C?"Saving…":"Save form"]})]}),!d&&(0,a.jsx)("div",{className:"rounded-lg border border-amber-200 bg-amber-50 dark:bg-amber-900/20 dark:border-amber-800 px-4 py-3 text-sm text-amber-800 dark:text-amber-200",children:"Create or open a saved assistant to persist form settings."}),(0,a.jsx)("div",{className:"flex flex-wrap gap-2 border-b border-gray-200 dark:border-gray-700 pb-2",children:B.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>x(e.id),className:"px-3 py-1.5 rounded-lg text-sm font-medium transition ".concat(g===e.id?"bg-gray-900 text-white dark:bg-white dark:text-gray-900":"text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"),children:e.label},e.id))}),"fields"===g&&(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Form title"}),(0,a.jsx)("input",{type:"text",value:b.formTitle||"",onChange:e=>y(t=>({...t,formTitle:e.target.value})),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm",placeholder:"Contact Us"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Submit button text"}),(0,a.jsx)("input",{type:"text",value:b.submitButtonText||"",onChange:e=>y(t=>({...t,submitButtonText:e.target.value})),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Subheading"}),(0,a.jsx)("input",{type:"text",value:b.formSubheading||"",onChange:e=>y(t=>({...t,formSubheading:e.target.value})),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm",placeholder:"Fill out the form below…"})]}),(0,a.jsx)("div",{className:"space-y-3",children:R.map(e=>(0,a.jsxs)("div",{className:"rounded-xl border p-4 ".concat(e.enabled?"border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800":"border-dashed border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800/50 opacity-70"),children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-2 mb-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("span",{className:"text-xs font-mono px-2 py-0.5 rounded bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300",children:[e.key,f.includes(e.ke
1y)?" \xb7 system":""]}),(0,a.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-xs text-gray-600 dark:text-gray-300",children:[(0,a.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:t=>E(e.id,{enabled:t.target.checked})}),"Visible"]}),(0,a.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-xs text-gray-600 dark:text-gray-300",children:[(0,a.jsx)("input",{type:"checkbox",checked:e.required,onChange:t=>E(e.id,{required:t.target.checked})}),"Required"]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("button",{type:"button",onClick:()=>z(e.id,-1),className:"p-1.5 rounded hover:bg-gray-100 dark:hover:bg-gray-700",title:"Move up",children:(0,a.jsx)(h.uCC,{className:"w-3 h-3"})}),(0,a.jsx)("button",{type:"button",onClick:()=>z(e.id,1),className:"p-1.5 rounded hover:bg-gray-100 dark:hover:bg-gray-700",title:"Move down",children:(0,a.jsx)(h.$TP,{className:"w-3 h-3"})}),(0,a.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void y(e=>{let r=e.fields.find(e=>e.id===t);return r?A(r.key)?{...e,fields:e.fields.map(e=>e.id===t?{...e,enabled:!1}:e)}:{...e,fields:e.fields.filter(e=>e.id!==t).map((e,t)=>({...e,order:t}))}:e})},className:"p-1.5 rounded text-red-600 hover:bg-red-50 dark:hover:bg-red-900/30",title:f.includes(e.key)?"Hide field":"Remove field",children:(0,a.jsx)(h.qbC,{className:"w-3 h-3"})})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Label"}),(0,a.jsx)("input",{type:"text",value:e.label||"",onChange:t=>E(e.id,{label:t.target.value}),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Placeholder"}),(0,a.jsx)("input",{type:"text",value:e.placeholder||"",onChange:t=>E(e.id,{placeholder:t.target.value}),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Type"}),(0,a.jsx)("select",{value:e.type,onChange:t=>E(e.id,{type:t.target.value}),disabled:f.includes(e.key),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm disabled:opacity-60",children:v.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))})]})]}),!f.includes(e.key)&&(0,a.jsxs)("div",{className:"mt-3",children:[(0,a.jsx)("label",{className:"block text-xs text-gray-500 mb-1",children:"Variable key (sent to AI call)"}),(0,a.jsx)("input",{type:"text",value:e.key,onChange:t=>E(e.id,{key:t.target.value.toLowerCase().replace(/[^a-z0-9_]/g,"_")}),className:"w-full max-w-sm px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm font-mono"})]})]},e.id))}),(0,a.jsxs)("button",{type:"button",onClick:()=>{y(e=>{let t=e.fields.length;return{...e,fields:[...e.fields,{id:j(),key:"custom_".concat(t+1),type:"short_text",label:"Custom field",placeholder:"",required:!1,enabled:!0,order:t,system:!1}]}})},className:"inline-flex items-center gap-2 px-3 py-2 rounded-lg border border-dashed border-gray-300 dark:border-gray-600 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700",children:[(0,a.jsx)(h.OiG,{className:"w-3 h-3"}),"Add custom field"]})]}),"design"===g&&(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[[["primaryColor","Primary color","color"],["secondaryColor","Secondary color","color"],["submitButtonColor","Submit button","color"],["submitButtonHoverColor","Submit hover","color"],["formBackgroundColor","Form background","text"],["fontSize","Font size","text"],["fontFamily","Font family","text"]].map(e=>{var t;let[r,s,l]=e;return(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:s}),(0,a.jsx)("input",{type:"color"===l?"color":"text",value:(null==(t=b.theme)?void 0:t[r])||"",onChange:e=>L(r,e.target.value),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm ".concat("color"===l?"h-10":"")}
1)]},r)}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Theme mode"}),(0,a.jsxs)("select",{value:(null==(t=b.theme)?void 0:t.themeMode)||"light",onChange:e=>L("themeMode",e.target.value),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm",children:[(0,a.jsx)("option",{value:"light",children:"Light"}),(0,a.jsx)("option",{value:"dark",children:"Dark"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Field layout"}),(0,a.jsxs)("select",{value:(null==(r=b.theme)?void 0:r.fieldLayout)||"inline",onChange:e=>L("fieldLayout",e.target.value),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm",children:[(0,a.jsx)("option",{value:"inline",children:"Stacked (inline)"}),(0,a.jsx)("option",{value:"grid",children:"Side-by-side (grid)"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Title align"}),(0,a.jsxs)("select",{value:(null==(s=b.theme)?void 0:s.titleAlign)||"center",onChange:e=>L("titleAlign",e.target.value),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm",children:[(0,a.jsx)("option",{value:"left",children:"Left"}),(0,a.jsx)("option",{value:"center",children:"Center"}),(0,a.jsx)("option",{value:"right",children:"Right"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Content align"}),(0,a.jsxs)("select",{value:(null==(n=b.theme)?void 0:n.formContentAlign)||"center",onChange:e=>L("formContentAlign",e.target.value),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm",children:[(0,a.jsx)("option",{value:"left",children:"Left"}),(0,a.jsx)("option",{value:"center",children:"Center"}),(0,a.jsx)("option",{value:"right",children:"Right"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Submit button width"}),(0,a.jsxs)("select",{value:(null==(i=b.theme)?void 0:i.submitButtonFullWidth)?"full":"auto",onChange:e=>L("submitButtonFullWidth","full"===e.target.value),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm",children:[(0,a.jsx)("option",{value:"full",children:"Full width"}),(0,a.jsx)("option",{value:"auto",children:"Auto width"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Submit button align"}),(0,a.jsxs)("select",{value:(null==(o=b.theme)?void 0:o.submitButtonAlign)||"center",onChange:e=>L("submitButtonAlign",e.target.value),className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-700 text-sm",children:[(0,a.jsx)("option",{value:"left",children:"Left"}),(0,a.jsx)("option",{value:"center",children:"Center"}),(0,a.jsx)("option",{value:"right",children:"Right"})]})]})]}),"preview"===g&&(0,a.jsxs)("div",{className:"rounded-xl border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/40 p-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-3 text-sm text-gray-500",children:[(0,a.jsx)(h.Ny1,{}),"Live preview (submit disabled in builder)"]}),(0,a.jsx)(p,{..._})]}),"embed"===g&&(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Paste this on your site. The widget loads your saved fields and design from the CRM — no need to hardcode show-* attributes."}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("textarea",{readOnly:!0,rows:12,value:P,className:"w-full px-4 py-3 bg-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-xl font-mono text-sm"}),(0,a.jsxs)("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(P),c.oR.success("Embed code copied")},className:"absolute top-3 right-3 inline-flex items-center gap-1 px-3 py-1.5 bg-gray-900 dark:bg-white text-white dark:text-gray-900 text-xs rounded-lg",children:[(0,a.jsx)(h.paH,{className:"w-3 h-3"}),"Copy"]})]})]})]})}function F(e){if(Array.isArray(e))return e.filter(e=>""!==e&&null!=e&&!(Array.isArray(e)&&0===e.length)&&("object"!=typeof e||null===e||0!==Object.keys(e).length)).map(F);if("object"==typeof e&&null!==e){let t={};for(let r in e){let a=F(e[r]);""===a||null==a||Array.isArray(a)&&0===a.length||"object"==typeof a&&null!==a&&0===Object.keys(a).length||(t[r]=a)}return t}return e}
1let L='**Date/Time Context:**\n- Date: {{ "now" | date: "%B %d, %Y", "Europe/London" }}\n- Time: {{ "now" | date: "%I:%M %p", "Europe/London" }}',E={name:"Test Assistant",voice:{model:"eleven_turbo_v2_5",voiceId:"lFMekEu7QFl9cbEa8iGg",provider:"11labs",stability:.5,similarityBoost:.75},model:{model:"gpt-4o",toolIds:[""],messages:[{role:"system",content:"You are a helpful assistant that can answer questions and help with tasks.\n\n".concat(L)}],provider:"openai",maxTokens:1e3,temperature:.7},forwardingPhoneNumber:"+447300419422",firstMessage:"Hello, how can I help you today?",voicemailMessage:"Thank you for calling. Please leave a message after the beep.",endCallFunctionEnabled:!1,endCallMessage:"Thank you for calling. Goodbye!",transcriber:{model:"nova-3",language:"en",numerals:!1,provider:"deepgram",endpointing:300,confidenceThreshold:.4},silenceTimeoutSeconds:10,clientMessages:["conversation-update","function-call","hang","model-output","speech-update","status-update","transfer-update","transcript","tool-calls","user-interrupted","voice-input","workflow.node.started"],serverMessages:["conversation-update","end-of-call-report","function-call","hang","speech-update","status-update","tool-calls","transfer-destination-request","user-interrupted"],dialKeypadFunctionEnabled:!0,hipaaEnabled:!1,maxDurationSeconds:21409,backgroundSound:"off",backchannelingEnabled:!0,backgroundDenoisingEnabled:!1,messagePlan:{idleMessages:["Are you still there?","Feel free to ask me any questions.","I'm ready to help whenever you are."]},startSpeakingPlan:{waitSeconds:.1,transcriptionEndpointingPlan:{onPunctuationSeconds:.1,onNoPunctuationSeconds:1.5,onNumberSeconds:.5},smartEndpointingEnabled:"livekit",smartEndpointingPlan:{provider:"vapi"}}},z=[{id:"general",label:"General"},{id:"tools",label:"Tools"},{id:"widget",label:"Widget"}];function I(e){var t,r,s,n,i,m,u;let{initialValues:g={},onSubmit:h,onCancel:b,isSubmitting:y,credentials:p}=e,[f,v]=(0,l.useState)(()=>{var e,t,r;let a={...E,...g},s=(null==(r=a.model)||null==(t=r.messages)||null==(e=t[0])?void 0:e.content)||"";if(!(s.includes("**Date/Time Context:**")||s.includes('{{ "now" | date:'))){a.model=a.model||{},a.model.messages=a.model.messages||[{role:"system",content:""}];let e=s.trim();a.model.messages[0]={...a.model.messages[0],content:e?"".concat(e,"\n\n").concat(L):L}}return a}),[k,j]=(0,l.useState)(""),[w,N]=(0,l.useState)(null),[C,S]=(0,l.useState)("general"),[A,B]=(0,l.useState)(!1),[T,I]=(0,l.useState)(""),[W,P]=(0,l.useState)(!1),[_,R]=(0,l.useState)(""),[D,q]=(0,l.useState)(0),[H,U]=(0,l.useState)(null),[V,O]=(0,l.useState)(null),[Y,G]=(0,l.useState)(!0),[J,K]=(0,l.useState)([]),[$,X]=(0,l.useState)([]),[Q,Z]=(0,l.useState)(!1),[ee,et]=(0,l.useState)(!1),[er,ea]=(0,l.useState)(""),es=(0,l.useRef)(null),el=!!(g&&g.id),en=async()=>{Z(!0);try{var e;
1let t=null==(e=document.cookie.split("; ").find(e=>e.startsWith("tkn=")))?void 0:e.split("=")[1],r=await fetch("/api/assistants/training-context",{headers:t?{Authorization:"Bearer ".concat(t)}:{},credentials:"include"}),a=await r.json();a.success&&O(a)}catch(e){console.warn("Could not load training context:",e)}finally{Z(!1)}};(0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&B(!1)};return A&&(document.addEventListener("keydown",e),document.body.style.overflow="hidden",q(0),G(!0),et(!1),en()),()=>{document.removeEventListener("keydown",e),document.body.style.overflow=""}},[A]);let ei=async e=>{U(e);try{var t,r,a,s;let l=(null==(a=f.model)||null==(r=a.messages)||null==(t=r[0])?void 0:t.content)||"",n=null==(s=document.cookie.split("; ").find(e=>e.startsWith("tkn=")))?void 0:s.split("=")[1],i=await fetch("/api/assistants/generate-message",{method:"POST",headers:{"Content-Type":"application/json",...n&&{Authorization:"Bearer ".concat(n)}},credentials:"include",body:JSON.stringify({fieldType:e,systemPrompt:l,assistantName:f.name})}),o=await i.json();if(!i.ok)throw Error(o.error||o.message||"Failed to generate");o.message&&(em(e,o.message),c.oR.success("Message generated",{duration:2500,position:"top-right"}))}catch(e){c.oR.error(e.message||"Failed to generate message",{duration:4e3,position:"top-right"})}finally{U(null)}},eo=e=>{let{fieldType:t}=e;return(0,a.jsx)("button",{type:"button",onClick:()=>ei(t),disabled:H===t,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200",title:"Generate with AI based on system prompt",children:H===t?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("svg",{className:"animate-spin w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",children:[(0,a.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,a.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Generating..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),"AI"]})})},ed=()=>{let e=es.current;if(!e)return;let t=e.selectionStart,r=e.selectionEnd;q(t<r?r-t:0)},ec=async()=>{let e=null==T?void 0:T.trim();if(!e)return void R("Describe how you want your voice assistant to behave");R(""),P(!0);try{var t,r;let a=(null==(t=f.model.messages[0])?void 0:t.content)||"",s=(()=>{let e=es.current;if(!e)return"";let t=e.selectionStart,r=e.selectionEnd;return t===r?"":e.value.substring(t,r)})(),l=null==(r=document.cookie.split("; ").find(e=>e.startsWith("tkn=")))?void 0:r.split("=")[1],n=await fetch("/api/assistants/prompt-assist",{method:"POST",headers:{"Content-Type":"application/json",...l&&{Authorization:"Bearer ".concat(l)}},credentials:"include",body:JSON.stringify({currentPrompt:a,selectedText:s||void 0,instruction:e,includeBusinessTruth:Y,selectedFileIds:J,selectedAssetKeys:$})}),i=await n.json();if(!n.ok)throw Error(i.error||i.message||"Failed to train assistant");i.prompt&&(ea(a),et(!0),em("model.messages.0.content",i.prompt),I(""),c.oR.success(s?"Selection trained with AI":"Assistant trained successfully",{duration:3e3,position:"top-right"}))}catch(e){R(e.message||"Failed to train assistant"),c.oR.error(e.message||"Failed to train assistant",{duration:4e3,position:"top-right"})}finally{P(!1)}},em=(e,t)=>{v(r=>{let a=JSON.parse(JSON.stringify(r)),s=e.split("."),l=a;for(let e=0;e<s.length-1;e++)l[s[e]]||(l[s[e]]={}),l=l[s[e]];return l[s[s.length-1]]=t,a})},eu=async e=>{e.preventDefault(),j(""),N(null);try{el?(await d.A.patch("/api/assistants/".concat(g.id),F(f)),c.oR.success("Assistant updated successfully!",{duration:4e3,position:"top-right",style:{background:"#10B981",color:"#fff"}})):(await d.A.post("/api/assistants",F(f)),c.oR.success("Assistant created successfully!",{duration:4e3,position:"top-right",style:{background:"#10B981",color:"#fff"}})),h&&h(f)}catch(l){var t,r,a,s;let e=(null==(r=l.response)||null==(t=r.data)?void 0:t.error)||l.message;j(e),N((null==(s=l.response)||null==(a=s.data)?void 0:a.details)||null),
1c.oR.error("Failed to ".concat(el?"update":"create"," assistant: ").concat(e),{duration:5e3,position:"top-right",style:{background:"#EF4444",color:"#fff"}})}},eg="w-full px-4 py-3 bg-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-xl text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:border-transparent transition-all duration-200";return(0,a.jsx)("div",{className:"",children:(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"mb-8",children:[(0,a.jsx)("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white mb-2",children:el?"Edit Assistant":"Create Assistant"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400",children:"Configure your voice AI assistant with advanced settings and capabilities."})]}),(0,a.jsxs)("form",{onSubmit:eu,className:"space-y-8",children:[(0,a.jsx)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm",children:(0,a.jsx)("div",{className:"p-1",children:(0,a.jsx)("nav",{className:"flex space-x-1",children:z.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>S(e.id),className:"flex items-center gap-2 px-4 py-3 rounded-lg font-medium text-sm transition-all duration-200 ".concat(C===e.id?"bg-gray-900 dark:bg-white text-white dark:text-gray-900 shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-50 dark:hover:bg-gray-700"),children:e.label},e.id))})})}),"general"===C&&(0,a.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm hover:shadow-md transition-shadow duration-200 p-6",children:[(0,a.jsxs)("div",{className:"flex items-center mb-6",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.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"})})}),(0,a.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"General Information"})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Assistant Name"}),(0,a.jsx)("input",{className:eg,value:f.name,onChange:e=>em("name",e.target.value),placeholder:"Enter assistant name",required:!0})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Forwarding Phone Number"}),(0,a.jsx)("input",{className:eg,value:f.forwardingPhoneNumber,onChange:e=>em("forwardingPhoneNumber",e.target.value),placeholder:"+1234567890"})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white",children:"First Message"}),(0,a.jsx)(eo,{fieldType:"firstMessage"})]}),(0,a.jsx)("input",{className:eg,value:f.firstMessage,onChange:e=>em("firstMessage",e.target.value),placeholder:"Hello, how can I help you today?"})]})]})]}),(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm hover:shadow-md transition-shadow duration-200 p-6",children:[(0,a.jsxs)("div",{className:"flex items-center mb-6",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z"})})}),(0,a.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Voice Configuration"})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Voice Model"}),(0,a.jsx)("input",{className:eg,value:f.voice.model,onChange:e=>em("voice.model",e.target.value)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Voice ID"}),(0,a.jsx)("input",{className:eg,value:f.voice.voiceId,onChange:e=>em("voice.voiceId",e.target.value)})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Stability"}),(0,a.jsx)("input",{type:"number",step:"0.01",min:"0",max:"1",className:eg,value:f.voice.stability,onChange:e=>em("voice.stability",parseFloat(e.target.value))})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Similarity Boost"}),(0,a.jsx)("input",{type:"number",step:"0.01",min:"0",max:"1",className:eg,value:f.voice.similarityBoost,onChange:e=>em("voice.similarityBoost",parseFloat(e.target.value))})]})]})]})]}),(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm hover:shadow-md transition-shadow duration-200 p-6",children:[(0,a.jsxs)("div",{className:"flex items-center mb-6",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})})}),(0,a.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"AI Model Settings"})]}),(0,a.jsxs)("div",{className:"",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Model"}),(0,a.jsx)("input",{className:eg,value:f.model.model,onChange:e=>em("model.model",e.target.value)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Provider"}
1),(0,a.jsx)("input",{className:eg,value:f.model.provider,onChange:e=>em("model.provider",e.target.value)})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4 mb-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Max Tokens"}),(0,a.jsx)("input",{type:"number",className:eg,value:f.model.maxTokens,onChange:e=>em("model.maxTokens",parseInt(e.target.value))})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Temperature"}),(0,a.jsx)("input",{type:"number",step:"0.01",min:"0",max:"2",className:eg,value:f.model.temperature,onChange:e=>em("model.temperature",parseFloat(e.target.value))})]})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white",children:"System Prompt"}),(0,a.jsxs)("button",{type:"button",onClick:()=>B(!0),className:"flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium text-gray-900 dark:text-white bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 transition-all duration-200",children:[(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})}),"Focus Mode"]})]}),(0,a.jsx)("textarea",{className:"".concat(eg," resize-none"),rows:4,value:f.model.messages[0].content,onChange:e=>em("model.messages.0.content",e.target.value),placeholder:"Enter the system prompt for your assistant...",required:!0})]}),A&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-2 sm:p-4 bg-black/60 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-2xl border border-gray-200 dark:border-gray-700 shadow-2xl w-[95vw] max-w-7xl max-h-[95dvh] flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,a.jsxs)("div",{className:"relative overflow-hidden border-b border-gray-200 dark:border-gray-700 bg-gradient-to-r from-gray-50 to-white dark:from-gray-800 dark:to-gray-800/80",children:[(0,a.jsx)("div",{className:"absolute inset-0 bg-gradient-to-r from-transparent via-gray-100/30 to-transparent dark:via-gray-700/20"}),(0,a.jsxs)("div",{className:"relative flex items-center justify-between px-6 py-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-4",children:[(0,a.jsx)("div",{className:"w-12 h-12 bg-gray-900 dark:bg-white rounded-xl flex items-center justify-center shadow-lg",children:(0,a.jsx)("svg",{className:"w-6 h-6 text-white dark:text-gray-900",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-xl font-bold text-gray-900 dark:text-white",children:"AI Training Dashboard"}),(0,a.jsx)("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Train with Business Truth & docs. Select context sources below."})]})]}),(0,a.jsx)("button",{type:"button",onClick:()=>B(!1),className:"px-5 py-2.5 rounded-xl font-medium bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 shadow-sm transition-all duration-200",children:"Done"})]})]}),(0,a.jsx)("div",{className:"flex-1 overflow-auto p-6",children:(0,a.jsxs)("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6",children:[(0,a.jsx)("div",{className:"xl:col-span-4",children:(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm overflow-hidden",children:[(0,a.jsxs)("div",{className:"px-4 py-3 border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/80",children:[(0,a.jsxs)("h4",{className:"font-semibold text-gray-900 dark:text-white flex items-center gap-2",children:[(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}),"Context Sources"]}),(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5",children:"Select docs the AI will use when training"})]}),(0,a.jsx)("div",{className:"p-4 space-y-4 max-h-[280px] overflow-y-auto",children:Q?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsxs)("svg",{className:"animate-spin w-8 h-8 text-gray-400",fill:"none",viewBox:"0 0 24 24",children:[(0,a.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,a.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):V?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"flex items-start gap-3 p-3 rounded-lg bg-gray-50 dark:bg-gray-700/50 border border-gray-200 dark:border-gray-600 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700/70 transition-colors",children:[(0,a.jsx)("input",{type:"checkbox",checked:Y,onChange:e=>G(e.target.checked),className:"mt-1 w-4 h-4 rounded text-gray-900"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"Business Truth"}),(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:(null==(t=V.businessTruth)?void 0:t.hasData)?"Offer, ICP, UVP, brand":"Add in Truth Engine"})]})]}),(null==(r=V.projectFiles)?void 0:r.length)>0&&(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs font-medium text-gray-600 dark:text-gray-400 mb-2",children:"Project Files"}),(0,a.jsx)("div",{className:"space-y-2",children:V.projectFiles.map(e=>(0,a.jsxs)("label",{className:"flex items-center gap-3 p-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700/50 cursor-pointer",children:[(0,a.jsx)("input",{type:"checkbox",checked:J.includes(e.id),onChange:t=>K(r=>t.target.checked?[...r,e.id]:r.filter(t=>t!==e.id)),className:"w-4 h-4 rounded text-gray-900"}),(0,a.jsx)("span",{className:"text-sm text-gray-900 dark:text-white truncate flex-1",children:e.filename}),(0,a.jsx)("span",{className:"text-xs text-gray-500",children:e.textLength>0?"".concat(Math.round(e.textLength/1e3),"k"):""})]},e.id))})]}),(null==(s=V.generatedAssets)?void 0:s.length)>0&&(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs font-medium text-gray-600 dark:text-gray-400 mb-2",children:"Scripts & Voice"}),(0,a.jsx)("div",{className:"space-y-2",children:V.generatedAssets.map(e=>(0,a.jsxs)("label",{className:"flex items-center gap-3 p-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700/50 cursor-pointer",children:[(0,a.jsx)("input",{type:"checkbox",checked:$.includes(e.ke
1y),onChange:t=>X(r=>t.target.checked?[...r,e.key]:r.filter(t=>t!==e.key)),className:"w-4 h-4 rounded text-gray-900"}),(0,a.jsx)("span",{className:"text-sm text-gray-900 dark:text-white",children:e.label})]},e.key))})]}),!(null==(n=V.projectFiles)?void 0:n.length)&&!(null==(i=V.generatedAssets)?void 0:i.length)&&(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 py-2",children:"Upload docs in Truth Engine → Projects. Supported: PDF, TXT, MD, CSV, JSON, HTML, XML, RTF"})]}):(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400 py-4",children:"Could not load context. Check Truth Engine setup."})})]})}),(0,a.jsx)("div",{className:"xl:col-span-8 space-y-4",children:(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm p-4",children:[(0,a.jsxs)("h4",{className:"font-semibold text-gray-900 dark:text-white mb-3 flex items-center gap-2",children:[(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),"Train Assistant"]}),(0,a.jsxs)("div",{className:"flex gap-2 flex-wrap items-center mb-3",children:[(0,a.jsx)("input",{type:"text",value:T,onChange:e=>{I(e.target.value),R("")},placeholder:"e.g., Make it sound like our sales script, Add empathy, Use our brand voice...",className:"flex-1 min-w-[240px] px-4 py-2.5 bg-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg text-gray-900 dark:text-white placeholder-gray-500 focus:ring-2 focus:ring-gray-900 dark:focus:ring-white text-sm",onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),ec())}}),D>0&&(0,a.jsxs)("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-300 px-2 py-1 rounded bg-gray-200 dark:bg-gray-600",children:[D," chars selected"]}),(0,a.jsx)("button",{type:"button",onClick:ec,disabled:W,className:"px-4 py-2.5 rounded-lg font-medium bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 disabled:opacity-50 text-sm flex items-center gap-2",children:W?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("svg",{className:"animate-spin w-4 h-4",fill:"none",viewBox:"0 0 24 24",children:[(0,a.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,a.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})," Training..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})," Train"]})})]}),_&&(0,a.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400 mb-2",children:_}),ee?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-full min-h-[380px] px-4 py-4 bg-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-xl text-gray-900 dark:text-white font-mono text-sm leading-relaxed overflow-auto whitespace-pre-wrap",children:(()=>{var e;let t=(null==(e=f.model.messages[0])?void 0:e.content)||"";return o.b2(er||"",t).map((e,t)=>e.added?(0,a.jsx)("span",{className:"bg-yellow-300 dark:bg-yellow-500/60 text-gray-900 dark:text-gray-900 rounded-sm",children:e.value},t):e.removed?null:(0,a.jsx)("span",{children:e.value},t))})()}),(0,a.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Yellow = AI changed"}),(0,a.jsx)("button",{type:"button",onClick:()=>et(!1),className:"text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white underline",children:"Edit prompt"})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("textarea",{rows:20,ref:es,className:"w-full min-h-[380px] px-4 py-4 bg-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-xl text-gray-900 dark:text-white font-mono text-sm leading-relaxed resize-y focus:ring-2 focus:ring-gray-900 dark:focus:ring-white",value:f.model.messages[0].content,onChange:e=>{em("model.messages.0.content",e.target.value),et(!1)},onMouseUp:ed,onKeyUp:ed,onSelect:ed,placeholder:"System prompt..."}),(0,a.jsxs)("div",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400",children:[(null==(m=f.model.messages[0].content)?void 0:m.split(/\s+/).filter(
1Boolean).length)||0," words \xb7 ",(null==(u=f.model.messages[0].content)?void 0:u.length)||0," chars"]})]})]})})]})})]})})]})]}),(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm hover:shadow-md transition-shadow duration-200 p-6",children:[(0,a.jsxs)("div",{className:"flex items-center mb-6",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})})}),(0,a.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Transcription Settings"})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Model"}),(0,a.jsx)("input",{className:eg,value:f.transcriber.model,onChange:e=>em("transcriber.model",e.target.value)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Language"}),(0,a.jsx)("input",{className:eg,value:f.transcriber.language,onChange:e=>em("transcriber.language",e.target.value)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Provider"}),(0,a.jsx)("input",{className:eg,value:f.transcriber.provider,onChange:e=>em("transcriber.provider",e.target.value)})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Endpointing (ms)"}),(0,a.jsx)("input",{type:"number",className:eg,value:f.transcriber.endpointing,onChange:e=>em("transcriber.endpointing",parseInt(e.target.value))})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Confidence Threshold"}),(0,a.jsx)("input",{type:"number",step:"0.01",min:"0",max:"1",className:eg,value:f.transcriber.confidenceThreshold,onChange:e=>em("transcriber.confidenceThreshold",parseFloat(e.target.value))})]})]}),(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("input",{type:"checkbox",id:"numerals",className:"w-4 h-4 text-gray-900 dark:text-white bg-white dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:ring-offset-0",checked:f.transcriber.numerals,onChange:e=>em("transcriber.numerals",e.target.checked)}),(0,a.jsx)("label",{htmlFor:"numerals",className:"ml-2 text-sm text-gray-900 dark:text-white",children:"Enable numerals"})]})]})]}),(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm hover:shadow-md transition-shadow duration-200 p-6",children:[(0,a.jsxs)("div",{className:"flex items-center mb-6",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),(0,a.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Messages & Plans"})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white",children:"Voicemail Message"}),(0,a.jsx)(eo,{fieldType:"voicemailMessage"})]}),(0,a.jsx)("input",{className:eg,value:f.voicemailMessage,onChange:e=>
1em("voicemailMessage",e.target.value),placeholder:"Thank you for calling. Please leave a message after the beep."})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white",children:"End Call Message"}),(0,a.jsx)(eo,{fieldType:"endCallMessage"})]}),(0,a.jsx)("input",{className:eg,value:f.endCallMessage,onChange:e=>em("endCallMessage",e.target.value),placeholder:"Thank you for calling. Goodbye!"})]}),(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("input",{type:"checkbox",id:"endCallFunction",className:"w-4 h-4 text-gray-900 dark:text-white bg-white dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:ring-offset-0",checked:f.endCallFunctionEnabled,onChange:e=>em("endCallFunctionEnabled",e.target.checked)}),(0,a.jsx)("label",{htmlFor:"endCallFunction",className:"ml-2 text-sm text-gray-900 dark:text-white",children:"Enable end call function"})]})]})]}),(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm hover:shadow-md transition-shadow duration-200 p-6",children:[(0,a.jsxs)("div",{className:"flex items-center mb-6",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3",children:(0,a.jsxs)("svg",{className:"w-5 h-5 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,a.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"}),(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),(0,a.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Advanced Settings"})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Silence Timeout (s)"}),(0,a.jsx)("input",{type:"number",className:eg,value:f.silenceTimeoutSeconds,onChange:e=>em("silenceTimeoutSeconds",parseInt(e.target.value))})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Max Duration (s)"}),(0,a.jsx)("input",{type:"number",className:eg,value:f.maxDurationSeconds,onChange:e=>em("maxDurationSeconds",parseInt(e.target.value))})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Backgroun
1d Sound"}),(0,a.jsx)("input",{className:eg,value:f.backgroundSound,onChange:e=>em("backgroundSound",e.target.value)})]}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("input",{type:"checkbox",id:"backchanneling",className:"w-4 h-4 text-gray-900 dark:text-white bg-white dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:ring-offset-0",checked:f.backchannelingEnabled,onChange:e=>em("backchannelingEnabled",e.target.checked)}),(0,a.jsx)("label",{htmlFor:"backchanneling",className:"ml-2 text-sm text-gray-900 dark:text-white",children:"Enable backchanneling"})]}),(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("input",{type:"checkbox",id:"backgroundDenoising",className:"w-4 h-4 text-gray-900 dark:text-white bg-white dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:ring-offset-0",checked:f.backgroundDenoisingEnabled,onChange:e=>em("backgroundDenoisingEnabled",e.target.checked)}),(0,a.jsx)("label",{htmlFor:"backgroundDenoising",className:"ml-2 text-sm text-gray-900 dark:text-white",children:"Enable background denoising"})]})]})]})]})]}),"tools"===C&&(0,a.jsxs)("div",{children:[f.model.toolIds&&f.model.toolIds.length>0&&(0,a.jsx)("div",{className:"mb-4 flex flex-wrap gap-2",children:f.model.toolIds.map(e=>(0,a.jsxs)("span",{className:"inline-flex items-center px-3 py-1 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 text-xs font-medium",children:[e,(0,a.jsx)("button",{type:"button",className:"ml-2 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400",onClick:()=>{v(t=>({...t,model:{...t.model,toolIds:(t.model.toolIds||[]).filter(t=>t!==e)}}))},"aria-label":"Remove tool",children:"\xd7"})]},e))}),(0,a.jsx)(x,{onSelect:e=>{var t;let r=e.id||(null==(t=e.function)?void 0:t.name);r&&v(e=>{let t=e.model.toolIds||[];return t.includes(r)?e:{...e,model:{...e.model,toolIds:[...t,r]}}})},toolIds:f.model.toolIds||[]})]}),"knowledge"===C&&(0,a.jsx)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm p-8",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"w-16 h-16 bg-gray-100 dark:bg-gray-700 rounded-full flex items-center justify-center mx-auto mb-4",children:(0,a.jsx)("svg",{className:"w-8 h-8 text-gray-600 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.746 0 3.332.477 4.5 1.253v13C19.832 18.477 18.246 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"})})}),(0,a.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"Knowledge Base"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400",children:"Knowledge base configuration will be available soon."})]})}),"widget"===C&&(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsx)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm p-6",children:(0,a.jsxs)("div",{className:"flex items-center mb-4",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Website Widget"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400 text-sm",children:"Embed this assistant on your website"})]})]})}),(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm p-6",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,a.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:"Embed Code"}),(0,a.jsxs)("div",{className:"flex items-center space-x-2 text-sm text-gray-600 dark:text-gray-400",children:[(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,a.jsx)("span",{children:"Copy & paste into your website"})]})]}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("textarea",{readOnly:!0,className:"w-full px-4 py-3 bg-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-xl text-gray-900 dark:text-white font-mono text-sm resize-none focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:border-transparent transition-all duration-200",rows:11,value:'<script \n  src="https://www.voxasuite.com/widgets/voxasuite-assistant-widget2.js" \n  async \n  type="text/javascript">\n<\/script>\n<voxasuite-assistant-widget2 \n  assistant-id="'.concat((null==g?void 0:g.id)||"YOUR_ASSISTANT_ID",'" \n  token="').concat(p||"YOUR_API_KEY",'" \n  assistant-name="').concat(f.name||"YOUR_ASSISTANT_NAME",'">\n</voxasuite-assistant-widget2>')}),(0,a.jsxs)("button",{type:"button",onClick:()=>{let e='<script \n  src="https://www.voxasuite.com/widgets/voxasuite-assistant-widget2.js" \n  async \n  type="text/javascript">\n<\/script>\n<voxasuite-assistant-widget2 \n  assistant-id="'.concat((null==g?void 0:g.id)||"YOUR_ASSISTANT_ID",'" \n  token="').concat(p||"YOUR_API_KEY",'" \n  assistant-name="').concat(f.name||"YOUR_ASSISTANT_NAME",'">\n</voxasuite-assistant-widget2>');
1navigator.clipboard.writeText(e),c.oR.success("Widget code copied to clipboard!",{duration:3e3,position:"top-right",style:{background:"#10B981",color:"#fff"}})},className:"absolute top-3 right-3 px-3 py-1.5 bg-gray-900 dark:bg-white text-white dark:text-gray-900 text-xs rounded-lg hover:bg-gray-800 dark:hover:bg-gray-100 shadow-sm transition-all duration-200 flex items-center space-x-1",children:[(0,a.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})}),(0,a.jsx)("span",{children:"Copy"})]})]})]}),(0,a.jsx)("div",{className:"bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700 rounded-xl p-6",children:(0,a.jsxs)("div",{className:"flex items-start",children:[(0,a.jsx)("div",{className:"w-8 h-8 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3 mt-0.5",children:(0,a.jsx)("svg",{className:"w-4 h-4 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.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"})})}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("h3",{className:"text-gray-900 dark:text-white font-medium mb-3",children:"Setup Instructions"}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,a.jsx)("div",{className:"w-6 h-6 bg-gray-200 dark:bg-gray-600 rounded-full flex items-center justify-center mt-0.5",children:(0,a.jsx)("span",{className:"text-gray-900 dark:text-white text-xs font-medium",children:"1"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-gray-900 dark:text-white text-sm font-medium",children:"Replace the token"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400 text-xs",children:'Change "YOUR_TOKEN" with your actual API token'})]})]}),(0,a.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,a.jsx)("div",{className:"w-6 h-6 bg-gray-200 dark:bg-gray-600 rounded-full flex items-center justify-center mt-0.5",children:(0,a.jsx)("span",{className:"text-gray-900 dark:text-white text-xs font-medium",children:"2"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-gray-900 dark:text-white text-sm font-medium",children:"Assistant details are ready"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400 text-xs",children:"The assistant-id and assistant-name are automatically filled from the current assistant"})]})]}),(0,a.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,a.jsx)("div",{className:"w-6 h-6 bg-gray-200 dark:bg-gray-600 rounded-full flex items-center justify-center mt-0.5",children:(0,a.jsx)("span",{className:"text-gray-900 dark:text-white text-xs font-medium",children:"3"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-gray-900 dark:text-white text-sm font-medium",children:"Add to your website"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400 text-xs",children:"Paste the code before the closing </body> tag of your HTML"})]})]}),(0,a.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,a.jsx)("div",{className:"w-6 h-6 bg-gray-200 dark:bg-gray-600 rounded-full flex items-center justify-center mt-0.5",children:(0,a.jsx)("span",{className:"text-gray-900 dark:text-white text-xs font-medium",children:"4"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-gray-900 dark:text-white text-sm font-medium",children:"Widget appears"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400 text-xs",children:"A floating chat button will appear on your website"})]})]})]})]})]})})]}),"widget"===C&&(0,a.jsx)("div",{className:"space-y-6 mt-8",children:(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm p-6",children:[(0,a.jsxs)("div",{className:"flex items-center mb-6",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center mr-3",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-gray-600 dark:text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Personalization Form Widget"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400 text-sm",children:"Full control of fields, labels, and design. Embed loads your saved config automatically."})]})]}),(0,a.jsx)(M,{assistantId:(null==g?void 0:g.vapiAssistantId)||(null==g?void 0:g.id)||"",assistantName:f.name||(null==g?void 0:g.name)||"AI Assistant"})]})}),(0,a.jsxs)("div",{className:"flex justify-end gap-4 pt-6 border-t border-gray-200 dark:border-gray-700",children:[(0,a.jsx)("button",{type:"button",onClick:b,className:"px-6 py-3 rounded-xl font-medium border border-gray-200 dark:border-gray-600 text-gray-900 dark:text-white hover:bg-gray-50 dark:hover:bg-gray-700 transition-all duration-200",children:"Cancel"}),(0,a.jsx)("button",{type:"submit",disabled:y,className:"px-6 py-3 rounded-xl font-medium bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 shadow-lg hover:shadow-xl transition-all duration-300 transform hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed disabled:transform-none disabled:hover:scale-100",children:y?el?"Saving...":"Creating...":el?"Save Assistant":"Create Assistant"})]}
1),k&&(0,a.jsx)("div",{className:"bg-red-500/10 border border-red-500/20 rounded-xl p-4",children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("svg",{className:"w-5 h-5 text-red-500 dark:text-red-400 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,a.jsx)("span",{className:"text-red-600 dark:text-red-400 font-medium",children:k})]})}),w&&(0,a.jsx)("div",{className:"bg-red-500/10 border border-red-500/20 rounded-xl p-4",children:(0,a.jsx)("div",{className:"text-red-600 dark:text-red-400 text-sm whitespace-pre-line",children:Array.isArray(w)?w.join("\n"):w})})]})]})})}var W=r(48230),P=r.n(W),_=r(35588),R=r(31452),D=r(85663);function q(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Request failed";return e?"string"==typeof e?e:"object"==typeof e?e.message||e.error||JSON.stringify(e):String(e):t}function H(){let{user:e,loading:t}=(0,n.A)(),{can:r}=(0,i.A)(),o=(0,s.useRouter)(),{id:d}=o.query,[c,m]=(0,l.useState)(null),[u,g]=(0,l.useState)(!0),[x,h]=(0,l.useState)(""),[b,y]=(0,l.useState)(!1),[p,f]=(0,l.useState)(!1),[v,k]=(0,l.useState)(!1),[j,w]=(0,l.useState)(!1),[N,C]=(0,l.useState)(""),S=r("canManageAssistants"),A=r("canCreateAssistants"),B=r("canDeleteAssistants");(0,l.useEffect)(()=>{if(!t&&d){if(!e)return void o.push("/auth/login");S&&(g(!0),h(""),fetch("/api/assistants/".concat(d)).then(e=>e.json()).then(e=>{e&&!e.error?m(e):h(q(e.error,"Failed to load assistant"))}).catch(e=>h(e.message)).finally(()=>g(!1)))}},[d,e,t,o,S]);let T=async e=>{if(!A)return void h("You don't have permission to edit assistants");f(!0),h(""),y(!1);try{let t=await fetch("/api/assistants/".concat(d),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await t.json();t.ok?(y(!0),m(r)):h(q(r.error,"Failed to update assistant"))}catch(e){h(e.message)}finally{f(!1)}},M=async()=>{if(!B)return void C("You don't have permission to delete assistants");C("");try{let e=await fetch("/api/assistants/".concat(d),{method:"DELETE"});if(e.ok)w(!0),setTimeout(()=>o.push("/dashboard/assistants"),1500);else{let t=await e.json();C(q(t.error,"Failed to delete assistant"))}}catch(e){C(e.message)}};return t?(0,a.jsx)(_.A,{children:(0,a.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,a.jsx)("div",{className:"animate-spin rounded-full h-32 w-32 border-b-2 border-blue-600"})})}):e?S?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(_.A,{children:(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsxs)("div",{className:"relative overflow-hidden rounded-2xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm mb-8",children:[(0,a.jsx)("div",{className:"absolute inset-0 bg-gradient-to-r from-transparent via-gray-50/50 to-transparent dark:via-gray-700/20"}),(0,a.jsx)("div",{className:"relative p-6",children:(0,a.jsxs)("div",{className:"flex items-center gap-4",children:[(0,a.jsx)(P(),{href:"/dashboard/assistants",children:(0,a.jsx)("button",{className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl transition-colors duration-200",children:"←"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:"Assistant Details"}),(0,a.jsx)("p",{className:"mt-2 text-gray-600 dark:text-gray-400",children:"View and edit assistant configuration"})]})]})})]}),u?(0,a.jsx)("div",{className:"text-center text-gray-400",children:"Loading assistant..."}):x?(0,a.jsx)("div",{className:"text-red-500 text-center",children:x}):c?(0,a.jsx)(I,{initialValues:c.data,credentials:c.credentials,onSubmit:T,isSubmitting:p,onCancel:()=>o.push("/dashboard/assistants")}):null,b&&(0,a.jsx)("div",{className:"text-green-600 mt-4 text-center",children:"Assistant updated successfully!"}),j&&(0,a.jsx)("div",{className:"text-green-600 mt-4 text-center",children:"Assistant deleted successfully! Redirecting..."}),N&&(0,a.jsx)("div",{className:"text-red-500 mt-4 text-center",children:N})]})}),(0,a.jsx)(D.A,{open:v,title:"Delete Assistant?",description:"Are you sure you want to delete this assistant? This action cannot be undone.",onConfirm:()=>{k(!1),M()},onCancel:()=>k(!1),confirmText:"Delete",cancelText:"Cancel"})]}):(0,a.jsx)(_.A,{children:(0,a.jsx)("div",{className:"space-y-6 mt-2 mb-2",children:(0,a.jsx)(R.A,{title:"Access Denied",message:"You don't have permission to view assistant details.",requiredRoles:"Admin or Manager",redirectPath:"/dashboard/assistants",redirectText:"Back to Assistants"})})}):null}},85663:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});var a=r(37876);
1function s(e){let{open:t,title:r,description:s,onConfirm:l,onCancel:n,confirmText:i="Confirm",cancelText:o="Cancel"}=e;return t?(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 overflow-y-auto",children:(0,a.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-lg p-8 max-w-md w-full max-h-[90dvh] overflow-y-auto my-auto border border-gray-200 dark:border-gray-700",children:[(0,a.jsx)("h2",{className:"text-xl font-bold mb-2 text-gray-900 dark:text-white",children:r}),s&&(0,a.jsx)("p",{className:"mb-6 text-gray-600 dark:text-gray-300",children:s}),(0,a.jsxs)("div",{className:"flex justify-end gap-4",children:[(0,a.jsx)("button",{onClick:n,className:"px-4 py-2 rounded-lg font-medium bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-white hover:bg-gray-300 dark:hover:bg-gray-600 transition-all",children:o}),(0,a.jsx)("button",{onClick:l,className:"px-4 py-2 rounded-lg font-medium bg-gradient-to-r from-red-500 to-pink-500 text-white shadow hover:from-red-600 hover:to-pink-600 transition-all",children:i})]})]})}):null}r(14232)}},e=>{e.O(0,[7725,4938,4429,6989,2909,9004,5885,5588,636,6593,8792],()=>e(e.s=34260)),_N_E=e.O()}]);

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.