1import{a as e,r as t}from"./react-vendor-690ef4bc.js";import{A as a,c as n,b as l}from"./index-d3072779.js";import{S as o}from"./skeleton-loader-c65511d9.js";import{m as r}from"./utils-b81ec68d.js";import"./mui-core-0fc19580.js";const i="_panel_3i2m2_1",s="_panelHeader_3i2m2_15",c="_panelTitle_3i2m2_25",m="_panelBody_3i2m2_37",_="_formGrid_3i2m2_45",u="_formGridFull_3i2m2_59",d="_field_3i2m2_67",v="_fieldLabel_3i2m2_77",g="_required_3i2m2_91",E="_input_3i2m2_101",p="_textarea_3i2m2_143",h="_selectWrap_3i2m2_155",f="_select_3i2m2_155",w="_selectArrow_3i2m2_201",y="_sectionDivider_3i2m2_229",N="_sectionSubtitle_3i2m2_241",S="_voiceCount_3i2m2_255",x="_voiceGrid_3i2m2_267",b="_voiceCard_3i2m2_279",C="_voiceCardSelected_3i2m2_315",A="_voiceTop_3i2m2_325",B="_voiceName_3i2m2_337",I="_voiceBadge_3i2m2_349",k="_voiceBadgeFemale_3i2m2_365",M="_voiceBadgeMale_3i2m2_375",$="_voiceLang_3i2m2_385",L="_voicePlay_3i2m2_395",P="_playBtn_3i2m2_409",T="_playLabel_3i2m2_457",F="_selectedCheck_3i2m2_467",V="_loadMoreBtn_3i2m2_517",j="_loadMoreBtnExpanded_3i2m2_573",G="_voicesLoading_3i2m2_581",U="_voicesError_3i2m2_595",D="_panelFooter_3i2m2_609",R="_btnCancel_3i2m2_625",W="_btnSave_3i2m2_667",O="_successMsg_3i2m2_711",z="_errorMsg_3i2m2_725",q=({agentData:t,voices:a,isLoadingVoices:n,voicesError:l,showAllVoices:o,currentlyPlaying:r,isUpdating:q,successMessage:H,errorMessage:J,canSave:K,onInputChange:Q,onVoiceSelect:X,onTogglePlay:Y,onToggleShowAll:Z,onCancel:ee,onSave:te})=>{const ae=o?a:a.slice(0,6),ne=a.length>6;return e.createElement("div",{className:i},e.createElement("div",{className:s},e.createElement("div",{className:c},"AI Agent Details")),e.createElement("div",{className:m},e.createElement("div",{className:_},e.createElement("div",{className:d},e.createElement("label",{className:v,htmlFor:"agent-name"},"AI Agent Name ",e.createElement("span",{className:g},"*")),e.createElement("input",{id:"agent-name",className:E,type:"text",placeholder:"e.g. Danaa",maxLength:60,value:t.agent_name,onChange:e=>Q("agent_name",e.target.value)})),e.createElement("div",{className:d},e.createElement("label",{className:v,htmlFor:"consent-mode"},"Consent Mode ",e.createElement("span",{className:g},"*")),e.createElement("div",{className:h},e.createElement("select",{id:"consent-mode",className:f,value:t.consent_mode?"true":"false",onChange:e=>Q("consent_mode","true"===e.target.value)},e.createElement("option",{value:"false"},"False"),e.createElement("option",{value:"true"},"True")),e.createElement("div",{className:w},e.createElement("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2"},e.createElement("polyline",{points:"6,9 12,15 18,9"})))))),e.createElement("div",{className:`${_} ${u}`},e.createElement("div",{className:d},e.createElement("label",{className:v,htmlFor:"who-we-are"},"Agent Description ",e.createElement("span",{className:g},"*")),e.createElement("textarea",{id:"who-we-are",className:`${E} ${p}`,placeholder:"Briefly describe your company...",value:t.who_we_are,onChange:e=>Q("who_we_are",e.target.value)}))),e.createElement("div",{className:y}),e.createElement("div",{className:N},"Agent Voice"," ",e.createElement("span",{className:S},a.length?`(${a.length} available)`:"")),n?e.createElement("div",{className:G},"Loading voices..."):l?e.createElement("div",{className:U},l):e.createElement(e.Fragment,null,e.createElement("div",{className:x},ae.map(a=>{const n=a.voiceId===t.ultravox_voice_id,l=r===a.voiceId,o="female"===a.gender;return e.createElement("div",{key:a.voiceId,className:`${b} ${n?C:""}`,onClick:()=>X(a.voiceId),onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||X(a.voiceId)},role:"button",tabIndex:0},e.createElement("div",{className:F},e.createElement("svg",{viewBox:"0 0 24 24"},e.createElement("polyline",{points:"20,6 9,17 4,12"}))),e.createElement("div",{className:A},e.createElement("div",{className:B},a.name),e.createElement("div",{className:`${I} ${o?k:M}`},a.gender)),e.createElement("div",{className:$},a.languageLabel),e.createElement("div",{className:L},e.createElement("button",{type:"button",className:P,title:"Preview voice",onClick:e=>{e.stopPropagation(),Y(a.voiceId,a.previewUrl)}},l?e.createElement("svg",{viewBox:"0 0 24 24"},e.createElement("rect",{x:"6",y:"4",width:"4",height:"16"}),e.createElement("rect",{x:"14",y:"4",width:"4",height:"16"})):e.createElement("svg",{viewBox:"0 0 24 24"},e.createElement("polygon",{points:"5,3 19,12 5,21"}))),e.createElement("span",{className:T},l?"Playing...":"Preview")))})),ne&&e.createElement("button",{type:"button",className:`${V} ${o?j:""}`,onClick:Z},e.createElement("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2"},e.createElement("polyline",{points:"6,9 12,15 18,9"})),o?"Show less":`Show ${a.length-6} more voices`))),H&&e.createElement("div",{className:O},H),J&&e.createElement("div",{className:z},J),e.createElement("div",{className:D},e.createElement("button",{type:"button",className:R,onClick:ee,disabled:q},"Cancel"),e.createElement("button",{type:"button",className:W,onClick:te,disabled:q||!K},q?"Saving...":"Save")))},H={agent_name:"",who_we_are:"",consent_mode:!1,ultravox_voice_id:null},J=()=>{const{settings:i,isLoading:s,isUpdating:c,updateAIAgentSettings:m}=(()=>{const[e,l]=t.useState(null),[o,r]=t.useState(!1),[i,s]=t.useState(!1),c=t.useRef(!1),m=t.useRef(!1),_=()=>sessionStorage.getItem("authToken"),u=async()=>
1{if(o||c.current)return e;r(!0);try{const e=_();if(!e)throw new Error("No authentication token found");const t=await fetch(`${a.BASE_URL}/aiagent/settings`,{method:"GET",headers:{accept:"*/*",Authorization:`Bearer ${e}`}}),n=await t.json();if(n.errorMessage)throw new Error(n.errorMessage);return l(n.data),c.current=!0,m.current=!1,n.data}catch(t){if(!m.current){const e=t instanceof Error?t.message:"Failed to load settings";n.error(e),m.current=!0}return null}finally{r(!1)}};return t.useEffect(()=>{c.current||u()},[]),{settings:e,isLoading:o,isUpdating:i,fetchAIAgentSettings:u,updateAIAgentSettings:async t=>{s(!0);try{const o=_();if(!o)throw new Error("No authentication token found");const r=await fetch(`${a.BASE_URL}/aiagent/update-settings`,{method:"PUT",headers:{accept:"*/*","Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(t)}),i=await r.json();if(i.errorMessage)throw new Error(i.errorMessage);return e&&l({...e,...t}),n.success(i.message||"Settings updated successfully"),!0}catch(o){const e=o instanceof Error?o.message:"Failed to update settings";return n.error(e),!1}finally{s(!1)}}}})(),_=t.useRef(null),[u,d]=t.useState(H),[v,g]=t.useState(H),[E,p]=t.useState([]),[h,f]=t.useState(!0),[w,y]=t.useState(null),[N,S]=t.useState(!1),[x,b]=t.useState(null),[C,A]=t.useState(null),[B,I]=t.useState(null),k=t.useRef(!1);t.useEffect(()=>{let e=!1;return(async()=>{f(!0),y(null);try{const t=await l();if(e)return;p(t),0===t.length&&y("No voices available.")}catch{e||y("Could not load voices. Please try again.")}finally{e||f(!1)}})(),()=>{e=!0,_.current?.pause()}},[]),t.useEffect(()=>{if(!i||k.current)return;const e=i.ultravoxVoiceId||(E.length>0?E[0].voiceId:null),t={agent_name:i.agentName||"",who_we_are:i.whoWeAre||"",consent_mode:Boolean(i.consentMode),ultravox_voice_id:e};d(t),g(t),k.current=!0},[i,E]),t.useEffect(()=>{if(!k.current||!E.length||u.ultravox_voice_id)return;const e=E[0].voiceId;d(t=>({...t,ultravox_voice_id:e})),g(t=>({...t,ultravox_voice_id:e}))},[E,u.ultravox_voice_id]);const M=t.useCallback(e=>{b(t=>t===e?null:t)},[]),$=u.agent_name!==v.agent_name||u.who_we_are!==v.who_we_are||u.consent_mode!==v.consent_mode||u.ultravox_voice_id!==v.ultravox_voice_id,L=Boolean(u.agent_name.trim())&&Boolean(u.who_we_are.trim())&&Boolean(u.ultravox_voice_id)&&$;return s&&!i?e.createElement(o,null):i||s?e.createElement(r.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.8,ease:"easeInOut"}},e.createElement("audio",{ref:_,style:{display:"none"}}),e.createElement(q,{agentData:u,voices:E,isLoadingVoices:h,voicesError:w,showAllVoices:N,currentlyPlaying:x,isUpdating:c,successMessage:C,errorMessage:B,canSave:L,onInputChange:(e,t)=>
1{d(a=>({...a,[e]:t})),A(null),I(null)},onVoiceSelect:e=>{d(t=>({...t,ultravox_voice_id:e})),A(null),I(null)},onTogglePlay:(e,t)=>{const a=_.current;if(a){if(x&&x!==e&&(a.pause(),M(x)),x===e&&!a.paused)return a.pause(),void b(null);b(e),a.src=t,a.play().catch(()=>b(null)),a.onended=()=>b(null)}},onToggleShowAll:()=>S(e=>!e),onCancel:()=>{_.current?.pause(),b(null),d({...v}),S(!1),A(null),I(null)},onSave:async()=>{if(!L||!u.ultravox_voice_id)return;const e=E.find(e=>e.voiceId===u.ultravox_voice_id);A(null),I(null);if(await m({...i?.agentGuid?{agentGuid:i.agentGuid}:{},agentName:u.agent_name.trim(),whoWeAre:u.who_we_are.trim(),voiceGender:e?.gender??"female",ultravoxVoiceId:u.ultravox_voice_id,consentMode:u.consent_mode,isOnboarding:!1})){const e={...u};g(e),A("Changes saved successfully."),setTimeout(()=>A(null),3e3)}else I("Something went wrong. Please try again.")}})):e.createElement(o,null)};export{J 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.