1import{r as ia,l as P,q as e,a as Rt}from"./index-Chw7iKGq.js";import{i as la,e as d}from"./vendor-feOCaMQ1.js";import{d as at,b as mt,a as Y,r as Ft,e as Et,f as Wt,m as zt,c as oa}from"./outreachSettings-Cz5HzJEP.js";const ft=[{id:"email",label:"Email",description:"Mailbox and provider-based email delivery."},{id:"sms",label:"SMS",description:"Customer SMS accounts and sender numbers."},{id:"whatsapp",label:"WhatsApp",description:"WhatsApp Business API via Meta Cloud."},{id:"call",label:"Call",description:"Human-call routing and telephony handoff."},{id:"voice",label:"Voice AI",description:"AI voice runtime, telephony, and conversation design."}],ra={email:"outreach:profile:email",sms:"outreach:profile:sms",call:"outreach:profile:call",voice:"outreach:profile:voice",whatsapp:"outreach:profile:whatsapp"},ca=[{id:"live",label:"Live call"},{id:"manual",label:"Manual handoff"},{id:"hybrid",label:"Hybrid"},{id:"voice_agent",label:"Voice AI"}],Vt=[{id:"gpt-realtime-1.5",label:"gpt-realtime-1.5"},{id:"gpt-realtime",label:"gpt-realtime"},{id:"gpt-realtime-mini",label:"gpt-realtime-mini"}],Ht=[{id:"alloy",label:"alloy"},{id:"ash",label:"ash"},{id:"ballad",label:"ballad"},{id:"coral",label:"coral"},{id:"echo",label:"echo"},{id:"sage",label:"sage"},{id:"shimmer",label:"shimmer"},{id:"verse",label:"verse"}],Kt=[{id:"eleven_multilingual_v2",label:"eleven_multilingual_v2"},{id:"eleven_turbo_v2_5",label:"eleven_turbo_v2_5"},{id:"eleven_flash_v2_5",label:"eleven_flash_v2_5"}],da=new Set(["google_workspace","microsoft_365"]),ua=new Set(["twilio","twilio_voice","telnyx","telnyx_voice","plivo","google_workspace","microsoft_365"]),yt={email:[{id:"resend",label:"Resend"},{id:"sendgrid",label:"SendGrid"},{id:"google_workspace",label:"Google Workspace"},{id:"microsoft_365",label:"Microsoft 365"},{id:"smtp",label:"SMTP"}],sms:[{id:"twilio",label:"Twilio"},{id:"telnyx",label:"Telnyx"},{id:"plivo",label:"Plivo"},{id:"custom_webhook",label:"Custom webhook"}],call:[{id:"twilio_voice",label:"Twilio Voice"},{id:"telnyx_voice",label:"Telnyx Voice"},{id:"plivo",label:"Plivo"},{id:"custom_sip",label:"Custom SIP"},{id:"custom_webhook",label:"Custom webhook"}],voice_telephony:[{id:"twilio_voice",label:"Twilio Voice"},{id:"telnyx_voice",label:"Telnyx Voice"},{id:"plivo",label:"Plivo"},{id:"custom_sip",label:"Custom SIP"},{id:"custom_webhook",label:"Custom webhook"}],voice_ai:[{id:"openai_realtime",label:"OpenAI Realtime"},{id:"elevenlabs",label:"ElevenLabs"}],whatsapp:[{id:"meta_cloud",label:"Meta Cloud API"},{id:"custom_webhook",label:"Custom webhook"}]};function gt(o,l){const s=Array.isArray(o==null?void 0:o[l])?o[l]:[];return s.length?s:yt[l]||[]}function Dt(o){const l=String(o||"").trim().toLowerCase();return l==="voice_agent"||l==="voice"?"voice":l==="sms"||l==="call"||l==="email"||l==="whatsapp"?l:"email"}function ha(o){return o==="voice"?"Voice call settings":o==="call"?"Call settings":o==="sms"?"SMS settings":o==="whatsapp"?"WhatsApp settings":"Email settings"}function pa(o){return o==="voice"?"Voice profiles":o==="call"?"Call profiles":o==="sms"?"SMS profiles":o==="whatsapp"?"WhatsApp profiles":"Email profiles"}function ma(o){return o==="voice_telephony"?"Telephony accounts":o==="voice_ai"?"AI voice accounts":o==="call"?"Call accounts":o==="sms"?"SMS accounts":"Email accounts"}function va(o){const l=String(o||"").trim();if(!l)return"";const s=new Date(l);if(Number.isNaN(s.getTime()))return"";const g=Math.round((s.getTime()-Date.now())/1e3),x=Math.abs(g),i=new Intl.RelativeTimeFormat("en",{numeric:"auto"});return x<60?i.format(Math.round(g),"second"):x<3600?i.format(Math.round(g/60),"minute"):x<86400?i.format(Math.round(g/3600),"hour"):i.format(Math.round(g/86400),"day")}function Gt(o){return String(o||"").replace(/_/g," ").replace(/\b\w/g,l=>l.toUpperCase()).trim()}function U(o,l,s){const x=gt(o,l).find(i=>i.id===s);return(x==null?void 0:x.label)||Gt(s)}function ga(o){const l=String(o||"").trim().toLowerCase();return l?l.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase()):"Draft"}function vt(o){return da.has(String(o||"").trim().toLowerCase())}function _t(o){return ua.has(String(o||"").trim().toLowerCase())}function Ae(o={}){return Object.fromEntries(Object.entries(o).filter(([,l])=>String(l??"").trim()!==""))}function $t(o,l,s=null){var R;const g=gt(l,o),x=((R=g==null?void 0:g[0])==null?void 0:R.id)||"",i=s&&typeof s=="object"?s:{};return{scope:o,vendor:String(i.vendor||x||"").trim(),mode:String(i.mode||"customer_managed").trim(),name:String(i.name||"").trim(),shared:!!i.shared,mailbox_email:String(i.mailbox_email||"").trim(),external_account_id:String(i.external_account_id||"").trim(),status:String(i.status||"draft").trim(),api_key:"",auth_token:"",account_sid:"",auth_id:"",sip_domain:String(i.sip_domain||"").trim(),destination_country:String(i.destination_country||"US").trim(),host:"",port:"",username:"",password:"",tls_mode:"starttls",webhook_url:"",auth_header_name:"",auth_header_value:"",voice_connection_id:"",sip_uri:"",sip_transport:"udp",sip_username:"",sip_password:""}}function ba(o,l){const s=String((l==null?void 0:l.vendor)||"").trim().toLowerCase();
1return o==="voice_telephony"&&s==="telnyx_voice"?Ae({api_key:l.api_key,voice_connection_id:l.voice_connection_id}):s==="resend"||s==="sendgrid"||s==="telnyx"||s==="openai_realtime"||s==="elevenlabs"?Ae({api_key:l.api_key}):s==="smtp"?Ae({host:l.host,port:l.port,username:l.username,password:l.password,tls_mode:l.tls_mode}):s==="twilio"||s==="twilio_voice"?Ae({account_sid:l.account_sid,auth_token:l.auth_token,sip_domain:l.sip_domain,sip_username:l.sip_username,sip_password:l.sip_password,destination_country:l.destination_country}):s==="plivo"?Ae({auth_id:l.auth_id,auth_token:l.auth_token}):s==="custom_webhook"?Ae({webhook_url:l.webhook_url,auth_header_name:l.auth_header_name,auth_header_value:l.auth_header_value}):s==="custom_sip"?Ae({sip_uri:l.sip_uri,username:l.sip_username,password:l.sip_password,transport:l.sip_transport}):{}}function xa(o){const l=(o==null?void 0:o.resource_summary)||{},s=[];return l.number_count&&s.push(`${l.number_count} numbers`),l.mailbox_count&&s.push(`${l.mailbox_count} mailboxes`),l.sender_count&&s.push(`${l.sender_count} senders`),s.join(" · ")}function Bt(o){const l=(o==null?void 0:o.resources)||{},s=[],g=new Set,x=(i,R="")=>{const I=String(i||"").trim();!I||g.has(I)||(g.add(I),s.push({value:I,label:String(R||I).trim()}))};for(const i of Array.isArray(l.mailboxes)?l.mailboxes:[])x(i==null?void 0:i.value,i==null?void 0:i.label);for(const i of Array.isArray(l.senders)?l.senders:[])x(i==null?void 0:i.value,i==null?void 0:i.label);return o!=null&&o.mailbox_email&&x(o.mailbox_email,o.mailbox_email),s}function Oe(o,l="voice"){const s=(o==null?void 0:o.resources)||{};return(Array.isArray(s.numbers)?s.numbers:[]).filter(x=>l==="sms"?(x==null?void 0:x.sms)!==!1:(x==null?void 0:x.voice)!==!1).map(x=>({value:String((x==null?void 0:x.value)||"").trim(),label:String((x==null?void 0:x.label)||(x==null?void 0:x.value)||"").trim()})).filter(x=>x.value)}function fa(o,l,s,g){const x=l||{},R=[o==="email"?x.from_email||"No sender":x.from_phone||"No phone"];if(o==="voice"){const I=s[x.telephony_connection_id]||null,c=s[x.ai_connection_id]||null;I!=null&&I.vendor&&R.push(U(g,"voice_telephony",I.vendor)),c!=null&&c.vendor&&R.push(U(g,"voice_ai",c.vendor))}else{const I=s[x.connection_id]||null;I!=null&&I.vendor&&R.push(U(g,o,I.vendor))}return R.push(x.enabled?"enabled":"draft"),R.filter(Boolean).join(" · ")}function _a({channel:o}){const l={width:18,height:18,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0};return o==="whatsapp"?e.jsx("svg",{...l,children:e.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})}):o==="sms"?e.jsx("svg",{...l,children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H8l-5 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}):o==="call"?e.jsx("svg",{...l,children:e.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.8 19.8 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.08 4.18 2 2 0 0 1 4.06 2h3a2 2 0 0 1 2 1.72c.12.89.33 1.76.61 2.6a2 2 0 0 1-.45 2.11L8 9.91a16 16 0 0 0 6 6l1.48-1.22a2 2 0 0 1 2.11-.45c.84.28 1.71.49 2.6.61A2 2 0 0 1 22 16.92z"})}):o==="voice"?e.jsxs("svg",{...l,children:[e.jsx("path",{d:"M12 3a3 3 0 0 0-3 3v5a3 3 0 0 0 6 0V6a3 3 0 0 0-3-3z"}),e.jsx("path",{d:"M19 10a7 7 0 0 1-14 0"}),e.jsx("path",{d:"M12 17v4"}),e.jsx("path",{d:"M8 21h8"})]}):e.jsxs("svg",{...l,children:[e.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),e.jsx("path",{d:"M4 7l8 6 8-6"})]})}function de({title:o,subtitle:l,children:s}){return e.jsxs("section",{className:"outreach-settings-card",children:[e.jsxs("div",{className:"outreach-settings-card-head",children:[e.jsx("h3",{className:"outreach-settings-card-title",children:o}),l?e.jsx("p",{className:"outreach-settings-card-subtitle",children:l}):null]}),s]})}function ya({canEdit:o,busy:l,config:s,error:g,success:x,outboundAccount:i,onConfigure:R,webhookUrl:I,onRefresh:c}){var Ze,be,f,dt,ut;const[F,Re]=d.useState((s==null?void 0:s.telephony_source)||(s!=null&&s.vendor&&s.vendor!=="twilio_voice"||s!=null&&s.inbound_account_sid?"custom"
1:"outbound")),[Z,xe]=d.useState([]),[ee,z]=d.useState((s==null?void 0:s.vendor)||"twilio_voice"),[fe,T]=d.useState({}),[M,V]=d.useState((s==null?void 0:s.phone_number)||""),[ue,te]=d.useState([]),[_e,Fe]=d.useState(!1),[Ee,We]=d.useState(""),[ae,H]=d.useState((s==null?void 0:s.enabled)!==!1),[X,Pe]=d.useState(s!=null&&s.voice_agent_id?"library":"inline"),[ye,ze]=d.useState((s==null?void 0:s.voice_agent_id)||""),[he,De]=d.useState([]),[ne,je]=d.useState((s==null?void 0:s.agent_name)||""),[Se,Ie]=d.useState((s==null?void 0:s.voice_provider)||""),[se,ie]=d.useState((s==null?void 0:s.voice_model)||""),[we,pe]=d.useState((s==null?void 0:s.voice_name)||""),[$e,Be]=d.useState((s==null?void 0:s.voice_language)||""),[Ue,Ve]=d.useState((s==null?void 0:s.transfer_target)||""),[nt,He]=d.useState((s==null?void 0:s.inbound_greeting)||""),[st,j]=d.useState((s==null?void 0:s.ai_guidelines)||""),[G,K]=d.useState((s==null?void 0:s.voice_prompt)||""),[q,Ce]=d.useState((s==null?void 0:s.system_prompt)||""),[O,Ke]=d.useState(""),[D,Te]=d.useState(!1),[le,k]=d.useState(""),[oe,Le]=d.useState(""),[Ne,Ge]=d.useState([]),[me,Je]=d.useState(!1),[ve,re]=d.useState(!1),ce=!!(s!=null&&s.livekit_trunk_id),Ye=s===null,Me=!Ye&&(!ce||ve);d.useEffect(()=>{s&&(Re(s.telephony_source||(s.vendor&&s.vendor!=="twilio_voice"||s.inbound_account_sid?"custom":"outbound")),z(s.vendor||"twilio_voice"),V(s.phone_number||""),H(s.enabled!==!1),Pe(s.voice_agent_id?"library":"inline"),ze(s.voice_agent_id||""),je(s.agent_name||""),Ie(s.voice_provider||""),ie(s.voice_model||""),pe(s.voice_name||""),Be(s.voice_language||""),Ve(s.transfer_target||""),He(s.inbound_greeting||""),j(s.ai_guidelines||""),K(s.voice_prompt||""),Ce(s.system_prompt||""))},[s]),d.useEffect(()=>{P("/api/outreach/voice/telephony-vendors").then(n=>xe((n==null?void 0:n.vendors)||[])).catch(()=>{})},[]),d.useEffect(()=>{P("/api/outreach/voice-agents").then(n=>De((n==null?void 0:n.items)||[])).catch(()=>{})},[]);const L=d.useCallback(()=>{P("/api/outreach/voice/agent-templates").then(n=>Ge(Array.isArray(n==null?void 0:n.items)?n.items:[])).catch(()=>{})},[]);d.useEffect(()=>{L()},[L]);async function E(){const n=window.prompt("Name this template (e.g. 'Admissions agent v1'):",ne||"");if(!(!n||!n.trim())){Je(!0),k("");try{await P("/api/outreach/voice/agent-templates",{method:"POST",body:JSON.stringify({name:n.trim(),agent_name:ne,voice_provider:Se,voice_model:se,voice_name:we,voice_language:$e,transfer_target:Ue,inbound_greeting:nt,ai_guidelines:st,voice_prompt:G,system_prompt:q})}),L(),k(`Template "${n.trim()}" saved. Reuse it from the Outbound profile or another inbound config.`)}catch(y){k(`Failed to save template: ${y.message||"unknown error"}`)}finally{Je(!1)}}}function p(n){const y=Ne.find(_=>_.id===n);y&&(je(y.agent_name||""),Ie(y.voice_provider||""),ie(y.voice_model||""),pe(y.voice_name||""),Be(y.voice_language||""),Ve(y.transfer_target||""),He(y.inbound_greeting||""),j(y.ai_guidelines||""),K(y.voice_prompt||""),Ce(y.system_prompt||""),k(`Loaded template "${y.name}". Edit any field, then Save.`))}const A=he.find(n=>n.id===ye),W=(Se||(A==null?void 0:A.voice_provider)||"").toLowerCase(),N=d.useMemo(()=>{if(F==="outbound"){const n=((i==null?void 0:i.vendor)||"twilio_voice").toLowerCase();return Z.find(y=>y.id===n)||null}return Z.find(n=>n.id===ee)||null},[Z,F,ee,i]),Q=d.useCallback(async()=>{var _;if(!((_=N==null?void 0:N.features)!=null&&_.list_numbers)){te([]);return}const n=F==="outbound";if(n||Object.values(fe).some(J=>String(J||"").trim())){Fe(!0),We("");try{const J=new URLSearchParams({vendor:N.id,use_outbound:n?"true":"false"}),et=await P(`/api/outreach/voice/list-numbers?${J}`);te((et==null?void 0:et.numbers)||[])}catch(J){We(J.message||"Couldn't fetch numbers"),te([])}finally{Fe(!1)}}},[N,F,fe]);function Xe(n){z(n),T({}),te([])}function it(n){ze(n);const y=he.find(_=>_.id===n);y&&(je(y.name||""),Ie(y.voice_provider||""),ie(y.voice_model||""),pe(y.voice_name||""),Be(y.language||""),Ve(y.transfer_target||""),He(y.greeting||""),j(y.instructions||""),K(y.call_script||""),Ce(""))}function qe(){R(M,ae,{telephonySource:F,vendor:(N==null?void 0:N.id)||"twilio_voice",inboundCredentials:F==="custom"?fe:{},voiceAgentId:X==="library"?ye:"",agentName:ne,voiceProvider:Se,voiceModel:se,voiceName:we,voiceLanguage:$e,transferTarget:Ue,inboundGreeting:nt,aiGuidelines:st,voicePrompt:G,systemPrompt:q})}
1async function lt(){if(window.confirm("Disable inbound calling? Calls to this number will stop reaching the AI agent. Carrier-side SIP routing will be removed.")){k("");try{await P("/api/outreach/voice/inbound-deprovision",{method:"POST"}),k("Inbound disabled. Carrier SIP routing removed."),c==null||c()}catch(n){k(`Failed to disable: ${n.message||"unknown error"}`)}}}async function ot(){if(window.confirm("Generate new SIP credentials? For Custom SIP setups you'll need to update your PBX with the new password. Other vendors are reconfigured automatically.")){k("");try{const n=await P("/api/outreach/voice/rotate-livekit-auth",{method:"POST"});n!=null&&n.password?(Ke(n.password),k("New SIP password generated â copy it for your PBX before leaving this page.")):k("Credentials rotated. Carrier was reconfigured automatically."),c==null||c()}catch(n){k(`Rotation failed: ${n.message||"unknown error"}`)}}}async function ke(){const n=(oe||"").trim();if(!n){k("Enter a phone number to test-call.");return}k("");try{await P("/api/outreach/voice/inbound-test-call",{method:"POST",body:JSON.stringify({to_number:n})}),k(`Test call placed to ${n}. Pick up to verify the agent answers.`)}catch(y){k(`Test call failed: ${y.message||"unknown error"}`)}}async function jt(){var n,y;Te(!0),k("");try{const _=await P("/api/outreach/voice/inbound-status?reveal_secrets=true"),J=(y=(n=_==null?void 0:_.inbound)==null?void 0:n.livekit_auth)==null?void 0:y.password;J?Ke(J):k("Password not available â only Custom SIP setups reveal it.")}catch(_){k(`Couldn't reveal password: ${_.message||"unknown error"}`)}finally{Te(!1)}}function ge(n){if(n)try{navigator.clipboard.writeText(n),k("Copied.")}catch{}}const rt=((s==null?void 0:s.vendor)||"")==="custom_sip",ct=`sip:${(s==null?void 0:s.livekit_sip_host)||"sip.livekit.cloud"}`,Qe=((Ze=s==null?void 0:s.livekit_auth)==null?void 0:Ze.username)||((be=s==null?void 0:s.extra_credentials)==null?void 0:be.sip_username)||"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[g?e.jsx("div",{className:"outreach-settings-alert is-error",children:g}):null,x?e.jsx("div",{className:"outreach-settings-alert is-success",children:x}):null,e.jsxs(de,{title:"Inbound number",subtitle:"Choose which phone number receives inbound calls. We auto-provision the SIP trunk, LiveKit routing, and ph
1one assignment â nothing else needed.",children:[Ye&&e.jsx("div",{className:"outreach-connection-list",children:e.jsxs("div",{className:"outreach-connection-card",style:{minHeight:140,opacity:.55},children:[e.jsx("div",{style:{height:18,width:"30%",background:"var(--surface2)",borderRadius:6,marginBottom:10}}),e.jsx("div",{style:{height:12,width:"55%",background:"var(--surface2)",borderRadius:6,marginBottom:16}}),e.jsx("div",{style:{height:12,width:"70%",background:"var(--surface2)",borderRadius:6,marginBottom:6}}),e.jsx("div",{style:{height:12,width:"60%",background:"var(--surface2)",borderRadius:6}})]})}),ce&&!ve&&e.jsxs("div",{className:"outreach-connection-toolbar",children:[e.jsx(B,{children:"One inbound number per workspace. To swap to a different number or vendor, click Reconfigure on the card."}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>re(!0),disabled:!o||l,children:"Reconfigure"})]}),ce&&!ve&&e.jsx("div",{className:"outreach-connection-list",children:e.jsxs("div",{className:"outreach-connection-card is-selected",children:[e.jsxs("div",{className:"outreach-connection-card-head",children:[e.jsxs("div",{children:[e.jsx("div",{className:"outreach-connection-title",children:s.phone_number||"â"}),e.jsxs("div",{className:"outreach-connection-meta",children:[(s.vendor||"twilio_voice").replace(/_/g," ")," · ",s.telephony_source==="custom"?"different account":"outbound account"]})]}),e.jsx("span",{className:`outreach-connection-status is-${s.enabled===!1?"draft":s.provision_error?"error":"connected"}`,children:s.enabled===!1?"Paused":s.provision_error?"Warning":"Connected"})]}),e.jsxs("div",{className:"outreach-connection-inline",style:{display:"grid",gridTemplateColumns:"auto 1fr",gap:"2px 12px",alignItems:"baseline"},children:[e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"LiveKit trunk"}),e.jsx("code",{style:{fontSize:11,background:"var(--surface2)",padding:"1px 6px",borderRadius:4},children:s.livekit_trunk_id||"â"}),(s.vendor_trunk_id||s.twilio_trunk_sid)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Carrier trunk"}),e.jsx("code",{style:{fontSize:11,background:"var(--surface2)",padding:"1px 6px",borderRadius:4},children:s.vendor_trunk_id||s.twilio_trunk_sid})]}),((f=s.livekit_auth)==null?void 0:f.username)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"SIP auth user"}),e.jsx("code",{style:{fontSize:11,background:"var(--surface2)",padding:"1px 6px",borderRadius:4},children:s.livekit_auth.username})]}),s.configured_at&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Configured"}),e.jsx("span",{children:new Date(s.configured_at).toLocaleDateString(void 0,{dateStyle:"medium"})})]})]}),(s.provision_error||s.twilio_error)&&e.jsxs("div",{className:"outreach-settings-alert is-error",children:["â ",s.provision_error||s.twilio_error]}),e.jsxs("div",{className:"outreach-connection-card-actions",children:[e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>re(!0),disabled:!o||l,children:"Reconfigure"}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:ot,disabled:!o||l,title:"Generate a fresh SIP digest auth password on LiveKit and re-push it to the carrier (Twilio/Telnyx/Plivo origination URL or Custom-SIP creds). Use after a suspected leak or scheduled rotation. Calls aren't interrupted.",children:"Rotate credentials"}),e.jsx("button",{type:"button",className:"btn-secondary",style:{color:"#b91c1c",borderColor:"rgba(239,68,68,.25)"},onClick:lt,disabled:!o||l,title:"Removes carrier-side SIP routing AND clears the inbound config from this workspace. Numbers stay in your vendor account, but stop reaching the AI agent until reconfigured.",children:"Disconnect"})]}),e.jsxs("div",{className:"outreach-connection-card-actions",style:{marginTop:4},children:[e.jsx("input",{className:"form-input",style:{flex:"1 1 220px",minWidth:180},value:oe,onChange:n=>Le(n.target.value),placeholder:"Test-call destination (E.164)",disabled:!o||l}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:ke,disabled:!o||l||!oe,children:"Test call"})]}),le&&e.jsx("div",{className:`outreach-settings-alert ${le.toLowerCase().includes("fail")||le.toLowerCase().includes("error")?"is-error":"is-success"}`,children:le})]})}),ce&&!ve&&rt&&e.jsxs("div",{style:{marginTop:12,padding:"14px 16px",background:"rgba(99,102,241,.07)",border:"1px solid rgba(99,102,241,.18)",borderRadius:10},children:[e.jsx("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:8},children:"Configure your PBX outbound trunk with these credentials"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr auto",gap:"6px 12px",alignItems:"center",fontSize:12},children:[e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"SIP URI"}),e.jsx("code",{style:{fontSize:12,background:"var(--surface)",padding:"4px 8px",borderRadius:6},children:ct}),e.jsx("button",{type:"button",className:"btn-secondary",style:{padding:"3px 10px",fontSize:11},onClick:()=>ge(ct),children:"Copy"}),e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Username"}),e.jsx("code",{style:{fontSize:12,background:"var(--surface)",padding:"4px 8px",borderRadius:6},children:Qe||"â"}),e.jsx("button",{type:"button",className:"btn-secondary",style:{padding:"3px 10px",fontSize:11},onClick:()=>ge(Qe),disabled:!Qe,children:"Copy"}),e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Password"}),O?e.jsx("code",{style:{fontSize:12,background:"var(--surface)",padding:"4px 8px",borderRadius:6,wordBreak:"break-all"},children:O}):e.jsx("code",{style:{fontSize:12,background:"var(--surface)",padding:"4px 8px",borderRadius:6,color:"var(--text3)"},children:"â".repeat(20)}),O?e.jsx("button",{type:"button",className:"btn-secondary",style:{padding:"3px 10px",fontSize:11},onClick:()=>ge(O),children:"Copy"}):e.jsx("button",{type:"button",className:"btn-secondary",style:{padding:"3px 10px",fontSize:11},onClick:jt,disabled:D,children:D?"â¦":"Reveal"})]}),e.jsxs("div",{className:"outreach-settings-help",style:{marginTop:10},children:["Route inbound calls to ",s.phone_number," through this trunk in your PBX. The password is shown only on demand and never returned to other API calls."]})]}),Me&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:10,marginBottom:16},children:[{id:"outbound",label:"Use outbound number",desc:i?`Reuses ${i.name} (${i.vendor_label})`:"Reuses your outbound telephony account"},{id:"custom",label:"Use a different number",desc:"Provide separate Twil
1io Account SID + Auth Token"}].map(n=>e.jsxs("button",{type:"button",onClick:()=>o&&!l&&Re(n.id),disabled:!o||l,style:{flex:1,textAlign:"left",padding:"12px 14px",borderRadius:10,cursor:o&&!l?"pointer":"default",border:F===n.id?"2px solid var(--accent, #6366f1)":"1px solid var(--border)",background:F===n.id?"var(--accent-subtle, rgba(99,102,241,.07))":"var(--surface)"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:3},children:n.label}),e.jsx("div",{style:{fontSize:12,color:"var(--text2)",lineHeight:1.45},children:n.desc})]},n.id))}),e.jsxs("div",{className:"outreach-settings-grid",children:[F==="custom"&&e.jsx(h,{label:"Telephony provider",span:2,children:e.jsx("select",{className:"form-input",value:ee,onChange:n=>Xe(n.target.value),disabled:!o||l,children:Z.map(n=>{var y;return e.jsxs("option",{value:n.id,children:[n.label,(y=n.features)!=null&&y.fully_automated?"":" (manual SIP setup)"]},n.id)})})}),F==="custom"&&((dt=N==null?void 0:N.required_fields)==null?void 0:dt.length)>0&&N.required_fields.map(n=>e.jsxs(h,{label:n.label,children:[e.jsx("input",{className:"form-input",type:n.type==="password"?"password":"text",value:fe[n.key]||"",onChange:y=>T(_=>({..._,[n.key]:y.target.value})),placeholder:n.placeholder||"",disabled:!o||l}),n.help_text?e.jsx("div",{className:"outreach-settings-help",children:n.help_text}):null]},n.key)),F==="custom"&&(N==null?void 0:N.id)==="custom_sip"&&e.jsx("div",{style:{gridColumn:"span 2",padding:"10px 12px",background:"rgba(99,102,241,.07)",borderRadius:8,fontSize:12,color:"var(--text2)",lineHeight:1.55},children:"No credentials needed up-front. After Configure, we'll display SIP username + password for you to paste into your PBX."}),e.jsx(h,{label:"Phone number",span:2,children:(ut=N==null?void 0:N.features)!=null&&ut.list_numbers?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsxs("select",{className:"form-input",style:{flex:1},value:M===""||ue.some(n=>n.e164===M)||M?M:"",onFocus:()=>{!ue.length&&!_e&&Q()},onChange:n=>{n.target.value==="__manual__"?V(""):V(n.target.value)},disabled:!o||l,children:[e.jsx("option",{value:"",children:_e?"Loading numbersâ¦":"â pick a number â"}),M&&!ue.some(n=>n.e164===M)&&e.jsxs("option",{value:M,children:[M," (currently configured)"]}),ue.map(n=>e.jsx("option",{value:n.e164,children:n.label&&n.label!==n.e164?`${n.e164} · ${n.label}`:n.e164},n.e164)),e.jsx("option",{value:"__manual__",children:"Enter manuallyâ¦"})]}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:Q,disabled:!o||l||_e,style:{flexShrink:0,padding:"0 12px"},children:_e?"â¦":ue.length?"Refresh":"Load"})]}),M===""&&ue.length>0&&e.jsx("input",{className:"form-input",style:{marginTop:6},value:M,onChange:n=>V(n.target.value),placeholder:"+1 415 555 0123 (E.164)",disabled:!o||l}),Ee&&e.jsx("div",{className:"outreach-settings-help",style:{color:"#dc2626"},children:Ee}),e.jsx("div",{className:"outreach-settings-help",children:"E.164 format. SIP trunk + LiveKit routing are created automatically when you Configure."})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"form-input",value:M,onChange:n=>V(n.target.value),placeholder:"+1 415 555 0123 (E.164)",disabled:!o||l}),e.jsxs("div",{className:"outreach-settings-help",children:["E.164 format. ",(N==null?void 0:N.id)==="custom_sip"?"After Configure, point your PBX at the SIP credentials we generate.":""]})]})}),e.jsx(h,{label:"Status",children:e.jsxs("select",{className:"form-input",value:ae?"yes":"no",onChange:n=>H(n.target.value==="yes"),disabled:!o||l,children:[e.jsx("option",{value:"yes",children:"Active â answer inbound calls"}),e.jsx("option",{value:"no",children:"Paused â do not answer"})]})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",marginTop:16,gap:8},children:[ce&&e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>re(!1),disabled:l,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn-primary",onClick:()=>{qe(),re(!1)},disabled:!o||l||!M,style:{flexShrink:0},children:l?"Configuringâ¦":ce?"Save changes":"Configure"})]})]})]}),e.jsxs(de,{title:"AI agent",subtitle:"Who answers inbound calls. Pick an existing agent or define one here.",children:[e.jsx("div",{style:{display:"flex",gap:8,marginBottom:16},children:[{id:"library",label:"Select from library"},{id:"inline",label:"Define here"}].map(n=>e.jsx("button",{type:"button",onClick:()=>o&&!l&&Pe(n.id),disabled:!o||l,style:{padding:"6px 14px",borderRadius:8,fontSize:12,fontWeight:600,cursor:o&&!l?"pointer":"default",border:X===n.id?"2px solid var(--accent, #6366f1)":"1px solid var(--border)",background:X===n.id?"var(--accent-subtle, rgba(99,102,241,.07))":"var(--surface)",color:X===n.id?"var(--accent, #6366f1)":"var(--text2)"},children:n.label},n.id))}),X==="library"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"outreach-settings-grid",children:e.jsxs(h,{label:"Agent",span:2,children:[e.jsxs("select",{className:"form-input",value:ye,onChange:n=>it(n.target.value),disabled:!o||l,children:[e.jsx("option",{value:"",children:"â select an agent â"}),he.filter(n=>!String(n.description||"").toLowerCase().includes("auto-created")).map(n=>e.jsxs("option",{value:n.id,children:[n.name,n.description?` â ${n.description}`:""]},n.id))]}),he.filter(n=>!String(n.description||"").toLowerCase().includes("auto-created")).length===0&&e.jsx("div",{className:"outreach-settings-help",children:"No agents in library yet â switch to âDefine hereâ to create one inline."})]})}),A&&e.jsxs("div",{style:{marginTop:12,padding:"12px 14px",background:"var(--surface2)",borderRadius:10,fontSize:12,color:"var(--text2)",lineHeight:1.9},children:[e.jsx("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:8},children:A.name||"Untitled agent"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",gap:"2px 12px",alignItems:"baseline"},children:[e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"AI provider"}),e.jsx("span",{children:A.voice_provider||"â"}),e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Voice model"}),e.jsx("span",{children:A.voice_model||"â"}),e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Voice"}),e.jsx("span",{children:A.voice_name||"â"}),e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Language"}),e.jsx("span",{children:A.language||"auto"}),A.transfer_target&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Escalation"}),e.jsx("span",{children:A.transfer_target})]}),A.greeting&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--text3)",fontWeight:600},children:"Greeting"}),e.jsx("span",{children:A.greeting})]})]}),e.jsx("div",{className:"outreach-settings-help",style:{marginTop:10},children:"These settings are inherited from the agent. To customise for inbound, switch to âDefine hereâ."})]})]}):e.jsxs(e.Fragment,{children:[Ne.length>0&&e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",marginBottom:12,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--text3)",fontWeight:600}
1,children:"Quick start:"}),e.jsxs("select",{className:"form-input",style:{flex:"1 1 240px",maxWidth:360},value:"",onChange:n=>{n.target.value&&p(n.target.value)},disabled:!o||l,children:[e.jsx("option",{value:"",children:"â load a saved template â"}),Ne.map(n=>e.jsx("option",{value:n.id,children:n.name},n.id))]}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:E,disabled:!o||l||me,children:me?"Savingâ¦":"Save as template"})]}),Ne.length===0&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:12},children:e.jsx("button",{type:"button",className:"btn-secondary",onClick:E,disabled:!o||l||me,title:"Save the current agent + conversation design as a reusable template. You can load it from the Outbound profile or another inbound config later.",children:me?"Savingâ¦":"Save as template"})}),e.jsxs("div",{className:"outreach-settings-grid",children:[e.jsx(h,{label:"Agent name",children:e.jsx("input",{className:"form-input",value:ne,onChange:n=>je(n.target.value),placeholder:"e.g. Sarah from Support",disabled:!o||l})}),e.jsx(h,{label:"Escalation / transfer number",children:e.jsx("input",{className:"form-input",value:Ue,onChange:n=>Ve(n.target.value),placeholder:"+1 415 555 0199",disabled:!o||l})}),e.jsx(h,{label:"AI provider",children:e.jsxs("select",{className:"form-input",value:Se,onChange:n=>{Ie(n.target.value),ie(""),pe("")},disabled:!o||l,children:[e.jsx("option",{value:"",children:"Select provider"}),e.jsx("option",{value:"openai_realtime",children:"OpenAI Realtime"}),e.jsx("option",{value:"elevenlabs",children:"ElevenLabs"})]})}),e.jsx(h,{label:"Voice model",children:W==="openai_realtime"?e.jsxs("select",{className:"form-input",value:se,onChange:n=>ie(n.target.value),disabled:!o||l,children:[e.jsx("option",{value:"",children:"Select model"}),Vt.map(n=>e.jsx("option",{value:n.id,children:n.label},n.id))]}):W==="elevenlabs"?e.jsxs("select",{className:"form-input",value:se,onChange:n=>ie(n.target.value),disabled:!o||l,children:[e.jsx("option",{value:"",children:"Select model"}),Kt.map(n=>e.jsx("option",{value:n.id,children:n.label},n.id))]}):e.jsx("input",{className:"form-input",value:se,onChange:n=>ie(n.target.value),placeholder:"Choose AI provider first",disabled:!0})}),e.jsx(h,{label:"Voice",children:W==="openai_realtime"?e.jsxs("select",{className:"form-input",value:we,onChange:n=>pe(n.target.value),disabled:!o||l,children:[e.jsx("option",{value:"",children:"Select voice"}),Ht.map(n=>e.jsx("option",{value:n.id,children:n.label},n.id))]}):e.jsx("input",{className:"form-input",value:we,onChange:n=>pe(n.target.value),placeholder:W==="elevenlabs"?"ElevenLabs voice ID":"â",disabled:!o||l||!W})}),e.jsx(h,{label:"Voice language",children:e.jsx("input",{className:"form-input",value:$e,onChange:n=>Be(n.target.value),placeholder:"auto / en-US / hi-IN",disabled:!o||l})})]})]})]}),e.jsxs(de,{title:"Conversation design",subtitle:X==="library"?"Pre-filled from the selected agent. Edit any field to override just for inbound â the library agent stays unchanged.":"What the agent says and how it behaves on inbound calls.",children:[e.jsxs("div",{className:"outreach-settings-grid",children:[e.jsxs(h,{label:"Opening greeting",span:2,children:[e.jsx("input",{className:"form-input",value:nt,onChange:n=>He(n.target.value),placeholder:'e.g. "Hello! Thanks for calling back. This is Sarah. How can I help you today?"',disabled:!o||l}),e.jsx("div",{className:"outreach-settings-help",children:"First thing the agent says when answering."})]}),e.jsx(h,{label:"Agent instructions",span:2,children:e.jsx("textarea",{className:"form-input outreach-settings-textarea",value:st,onChange:n=>j(n.target.value),placeholder:"Tone, escalation rules, compliance boundaries, and callback policy.",disabled:!o||l,style:{resize:"vertical"}})}),e.jsx(h,{label:"FAQ / call script",span:2,children:e.jsx("textarea",{className:"form-input outreach-settings-textarea",value:G,onChange:n=>K(n.target.value),placeholder:"Approved answers, objection handling, and context the agent should use.",disabled:!o||l,style:{resize:"vertical"}})}),e.jsx(h,{label:"System prompt override",span:2,children:e.jsx("textarea",{className:"form-input",rows:3,value:q,onChange:n=>Ce(n.target.value),placeholder:"Optional â replaces the entire compiled prompt. Leave blank to build from the fields above.",disabled:!o||l,style:{resize:"vertical"}})})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:8},children:e.jsx("button",{type:"button",className:"btn-primary",onClick:qe,disabled:!o||l||!M||X==="library"&&!ye,children:l?"Savingâ¦":ce?"Update":"Save"})})]}
1),e.jsxs(de,{title:"How it works",subtitle:"",children:[e.jsxs("ol",{style:{margin:0,padding:"0 0 0 18px",fontSize:13,color:"var(--text2)",lineHeight:1.9,display:"flex",flexDirection:"column",gap:2},children:[e.jsx("li",{children:"Contact calls your inbound number."}),e.jsx("li",{children:"Twilio routes the call to LiveKit via a SIP trunk (auto-created)."}),e.jsx("li",{children:"LiveKit creates a room and notifies this app."}),e.jsx("li",{children:"The AI voice agent answers with the greeting above."}),e.jsx("li",{children:"Transcript saved; contact outcome updated automatically."})]}),e.jsxs("div",{className:"outreach-settings-help",style:{marginTop:12},children:["Ensure ",e.jsx("strong",{children:"LIVEKIT_WEBHOOK_URL"})," is set to ",e.jsx("code",{style:{fontSize:11},children:I||`${window.location.origin}/api/webhooks/livekit/events`})," in your LiveKit server config."]})]})]})}function h({label:o,children:l,span:s=1}){return e.jsxs("label",{className:`outreach-settings-field${s===2?" is-span-2":""}`,children:[e.jsx("span",{className:"outreach-settings-label",children:o}),l]})}function B({children:o}){return e.jsx("div",{className:"outreach-settings-help",children:o})}function Ut(o){const l=String((o==null?void 0:o.last_error)||"").trim();return!l||l.startsWith("LiveKit SIP provisioning pending")&&String((o==null?void 0:o.outbound_trunk_id)||"").trim()?"":l}function Ca(){const{hasPermission:o}=ia(),[l,s]=la(),g=Dt(l.get("channel")),x=ra[g]||"",i=o("edit:outreach")||(x?o(x):!1),[R,I]=d.useState(!0),[c,F]=d.useState(!1),[Re,Z]=d.useState(""),[xe,ee]=d.useState(()=>at({})),[z,fe]=d.useState([]),[T,M]=d.useState({}),[V,ue]=d.useState(ft.map(t=>t.id)),[te,_e]=d.useState({}),[Fe,Ee]=d.useState(""),[We,ae]=d.useState(""),[H,X]=d.useState("outbound"),[Pe,ye]=d.useState(!1),[ze,he]=d.useState(""),[De,ne]=d.useState(null),[je,Se]=d.useState(!1),[Ie,se]=d.useState(""),[ie,we]=d.useState(""),[pe,$e]=d.useState(""),[Be,Ue]=d.useState([]),[Ve,nt]=d.useState(!1),[He,st]=d.useState(""),[j,G]=d.useState({scope:"",id:"",draft:null}),[K,q]=d.useState(""),[Ce,O]=d.useState(""),[Ke,D]=d.useState(""),Te=d.useRef(""),le=d.useRef(null),k=d.useRef(new Set),oe=d.useCallback(async()=>{var a,r;const t=await P("/api/outreach/connections");fe(Array.isArray(t==null?void 0:t.items)?t.items:[]),M(((a=t==null?void 0:t.vendor_catalog)==null?void 0:a.channels)||((r=t==null?void 0:t.catalog)==null?void 0:r.channels)||yt),_e((t==null?void 0:t.platform_managed_vendors)||{})},[]),Le=d.useCallback(async()=>{var t,a,r;I(!0),Z("");try{const u=await P("/api/outreach/config"),S=at((u==null?void 0:u.delivery_config)||((t=u==null?void 0:u.defaults)==null?void 0:t.delivery_config)||{}),v=Array.isArray(u==null?void 0:u.enabled_channels)&&u.enabled_channels.length?u.enabled_channels.map(b=>String(b||"").trim().toLowerCase()).filter(Boolean):ft.map(b=>b.id);ee(S),ue(v),fe(Array.isArray(u==null?void 0:u.connections)?u.connections:[]),M(((a=u==null?void 0:u.vendor_catalog)==null?void 0:a.channels)||((r=u==null?void 0:u.catalog)==null?void 0:r.channels)||yt),_e((u==null?void 0:u.platform_managed_vendors)||{}),Ee(String((u==null?void 0:u.settings_updated_at)||"").trim()),Te.current=JSON.stringify(S);const w=Number(u==null?void 0:u.reply_polling_days);Ge(Number.isFinite(w)&&w>=1&&w<=90?w:14)}catch(u){Z(u.message||"Failed to load outreach settings.")}finally{I(!1)}},[]),[Ne,Ge]=d.useState(10),[me,Je]=d.useState(!1),[ve,re]=d.useState("");async function ce(){const t=Math.max(1,Math.min(90,Math.round(Number(Ne)||10)));Je(!0),re("");try{await P("/api/outreach/workspace-prefs",{method:"PATCH",body:JSON.stringify({reply_polling_days:t})}),Ge(t),re(`Saved · polling window: ${t} day${t===1?"":"s"}`),setTimeout(()=>re(""),2400)}catch(a){re((a==null?void 0:a.message)||"Failed to save.")}finally{Je(!1)}}d.useEffect(()=>{Le().catch(()=>{})},[Le]),d.useEffect(()=>{let t=null;function a(){rt.current||Le().catch(()=>{})}function r(){t||(t=setInterval(a,6e4))}function u(){t&&(clearInterval(t),t=null)}function S(){document.visibilityState==="visible"?(a(),r()):u()}return document.visibilityState==="visible"&&r(),document.addEventListener("visibilitychange",S),()=>{u(),document.removeEventListener("visibilitychange",S)}},[Le]);const Ye=d.useCallback(async()=>{try{const t=await P("/api/outreach/voice/agent-templates");Ue(Array.isArray(t==null?void 0:t.items)?t.items:[])}catch{}},[]);d.useEffect(()=>{Ye()},[Ye]),d.useEffect(()=>{!V.length||V.includes(g)||Ze(V[0])},[V,g]),d.useEffect(()=>{g!=="voice"&&X("outbound")},[g]),d.useEffect(()=>{g!=="voice"||H!=="inbound"||De===null&&(P("/api/outreach/voice/inbound-status").then(t=>ne((t==null?void 0:t.inbound)||{})).catch(()=>ne({})),P("/api/config/platform").then(t=>{t!=null&&t.livekit_webhook_url&&$e(t.livekit_webhook_url)}).catch(()=>{}))},[g,H,De]),d.useEffect(()=>{function t(a){if(a.origin!==window.location.origin)return;const r=a.data||{};r.type==="outreach-connect-success"&&(O(""),D("Connected account successfully."),oe().catch(u=>O(u.message||"Failed to refresh outreach connections."))),r.type==="outreach-connect-error"&&(D(""),O(r.message||"Could not connect the outreach account."))}return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[oe]),d.useEffect(()=>{if(!j.scope||!j.draft)return;const t=gt(T,j.scope);if(!t.length)return;const a=String(j.draft.vendor||"").trim().toLowerCase();a&&t.some(r=>String(r.id||"").trim().toLowerCase()===a)||G(r=>!r.draft||r.scope!==j.scope?r:{...r,draft:{...r.draft,vendor:t[0].id}})},[j.scope,j.draft,T]);const Me=d.useMemo(()=>ft.filter(t=>V.includes(t.id)),[V]),L=xe[g]||mt(),E=d.useMemo(()=>Array.isArray(L.profiles)&&L.profiles.length?L.profiles.map(t=>Y(t)):[Ft(L)],[L]);d.useEffect(()=>{const t=E.find(a=>a.id===L.active_profile_id)||E[0];ae((t==null?void 0:t.id)||"")},[g,L.active_profile_id,E]);const p=E.find(t=>
1t.id===We)||E.find(t=>t.id===L.active_profile_id)||E[0]||Y(),A=d.useMemo(()=>Object.fromEntries((Array.isArray(z)?z:[]).map(t=>[t.id,t])),[z]),W=d.useMemo(()=>{const t=Array.isArray(z)?z:[];return{email:t.filter(a=>a.channel==="email"),sms:t.filter(a=>a.channel==="sms"),call:t.filter(a=>a.channel==="call"),whatsapp:t.filter(a=>a.channel==="whatsapp"),voice_telephony:t.filter(a=>a.channel==="voice_telephony"),voice_ai:t.filter(a=>a.channel==="voice_ai")}},[z]),N=A[p.connection_id||L.connection_id]||null,Q=A[p.telephony_connection_id||L.telephony_connection_id]||null,Xe=A[p.ai_connection_id||L.ai_connection_id]||null,it=d.useMemo(()=>Bt(N),[N]),qe=d.useMemo(()=>Oe(N,"sms"),[N]),lt=d.useMemo(()=>Oe(N,"voice"),[N]),ot=d.useMemo(()=>Oe(Q,"voice"),[Q]);d.useMemo(()=>{const t=new Set,a=[];for(const r of W.voice_telephony||[])for(const u of Oe(r,"voice"))t.has(u.value)||(t.add(u.value),a.push(u));return a},[W.voice_telephony]);const ke=String((Xe==null?void 0:Xe.vendor)||p.voice_provider||"").trim().toLowerCase(),ge=JSON.stringify(at(xe||{}))!==Te.current,rt=d.useRef(!1);rt.current=ge;const ct=ge?"Unsaved changes":Fe?`Saved ${va(Fe)}`:"Ready",Qe=d.useMemo(()=>Me.reduce((t,a)=>{const r=xe[a.id]||mt(),u=Array.isArray(r.profiles)&&r.profiles.length?r.profiles:[Ft(r)];return t[a.id]=u.length,t},{}),[xe,Me]);function Ze(t){const a=Dt(t),r=new URLSearchParams(l);r.set("channel",a),s(r,{replace:!0}),G({scope:"",id:"",draft:null}),O(""),D("")}function be(t){ee(a=>{const r=a&&typeof a=="object"?a:at({}),u=r[g]||mt();return{...r,[g]:t(u)}})}function f(t){let a="";be(r=>{var m;const u=Array.isArray(r.profiles)&&r.profiles.length?[...r.profiles]:[Y({name:"Primary profile"})],S=We||r.active_profile_id||((m=u[0])==null?void 0:m.id)||zt("profile"),v=u.findIndex(xt=>xt.id===S),w=v>=0?u[v]:u[0]||Y(),b=oa(w,{id:S,...t}),C=[...u];return v>=0?C[v]=b:C.push(b),a=b.id,{...r,profiles:C,active_profile_id:b.id}}),a&&ae(a)}function dt(){let t="";be(a=>{const r=Array.isArray(a.profiles)&&a.profiles.length?[...a.profiles]:[Y({name:"Primary profile"})],u=Y({name:`Profile ${r.length+1}`});return r.push(u),t=u.id,{...a,profiles:r,active_profile_id:u.id,enabled:!0}}),t&&ae(t)}function ut(){const t=p;if(!(t!=null&&t.id))return;let a="";be(r=>{const u=Array.isArray(r.profiles)&&r.profiles.length?[...r.profiles]:[Y({name:"Primary profile"})],S=Y({...t,id:zt("profile"),name:`${t.name||"Profile"} copy`});return u.push(S),a=S.id,{...r,profiles:u,active_profile_id:S.id}}),a&&ae(a)}function n(){if(E.length<=1)return;const t=p==null?void 0:p.id;if(!t)return;let a="";be(r=>{var w;const S=(Array.isArray(r.profiles)&&r.profiles.length?[...r.profiles]:[Y({name:"Primary profile"})]).filter(b=>b.id!==t),v=S.length?S:[Y({name:"Primary profile"})];return a=((w=v[0])==null?void 0:w.id)||"",{...r,profiles:v,active_profile_id:a}}),ae(a)}function y(t){const a=E.find(r=>r.id===t)||E[0];a&&(ae(a.id),be(r=>({...r,active_profile_id:a.id})))}function _(t){G(a=>{const r=a.draft?{...a.draft,...t}:null;return{...a,draft:r}})}function J(t,a=null){O(""),D(""),G({scope:t,id:(a==null?void 0:a.id)||"",draft:$t(t,T,a)})}function et(t,a){const r=t==="voice_telephony"||t==="voice_ai"?"voice":t,u=t==="voice_telephony"?"telephony_connection_id":t==="voice_ai"?"ai_connection_id":"connection_id";ee(S=>{const v=at(S||{}),w=v[r]||mt(),b=C=>!C||typeof C!="object"||String(C[u]||"")!==a?C:{...C,[u]:""};return{...v,[r]:{...b(w),profiles:(Array.isArray(w.profiles)?w.profiles:[]).map(C=>b(Y(C)))}}})}async function Jt({syncAfter:t=!1}={}){const a=j.scope,r=j.draft;if(!(!r||!a)){q(`save:${j.id||a}`),O(""),D("");try{const u={mode:r.mode,name:r.name,mailbox_email:r.mailbox_email,external_account_id:r.external_account_id,status:r.status,shared:!!r.shared},S=ba(a,r);j.id?Object.keys(S).length&&(u.credentials=S):(u.channel=a,u.vendor=r.vendor,r.mode==="customer_managed"&&(u.credentials=S));const v=j.id?"PATCH":"POST",w=j.id?`/api/outreach/connections/${encodeURIComponent(j.id)}`:"/api/outreach/connections",b=await P(w,{method:v,body:JSON.stringify(u)}),C=(b==null?void 0:b.item)||{};await oe(),G({scope:a,id:C.id||j.id,draft:$t(a,T,C)}),D(`${U(T,a,C.vendor||r.vendor)} account saved.`),t&&_t(C.vendor||r.vendor)&&await ht(C.id||j.id,{silent:!0})}catch(u){O(u.message||"Failed to save outreach account.")}finally{q("")}}}async function ht(t,{silent:a=!1}={}){if(t){q(`sync:${t}`),a||(O(""),D(""));try{await P(`/api/outreach/connections/${encodeURIComponent(t)}/sync`,{method:"POST"}),await oe(),a||D("Connection synced.")}catch(r){O(r.message||"Failed to sync outreach account.")}finally{q("")}}}d.useEffect(()=>{if(!(R||!Array.isArray(z)||!z.length))for(const t of z)!t||String(t.channel||"")!=="voice_telep
1hony"||String(t.vendor||"").toLowerCase()==="twilio_voice"&&(String(t.outbound_trunk_id||"").trim()||String(t.last_error||"").startsWith("LiveKit SIP provisioning pending")&&(k.current.has(t.id)||(k.current.add(t.id),ht(t.id,{silent:!0}).catch(()=>{}))))},[z,R]);async function St(t,a){if(t){q(`delete:${t}`),O(""),D("");try{await P(`/api/outreach/connections/${encodeURIComponent(t)}`,{method:"DELETE"}),et(a,t),j.id===t&&G({scope:"",id:"",draft:null}),await oe(),D("Connection removed.")}catch(r){O(r.message||"Failed to delete outreach account.")}finally{q("")}}}function wt(t){const a=window.open(`/outreach-connect?connection_id=${encodeURIComponent(t)}`,"outreach-connect","popup=1,width=560,height=760,resizable=yes,scrollbars=yes");if(!a){O("Popup blocked. Please allow popups for this site and try again.");return}a.focus()}function pt(t){var u,S;const a=A[t]||null,r={connection_id:t,provider:(a==null?void 0:a.vendor)||""};if(g==="email"){const v=p.from_email||((u=Bt(a)[0])==null?void 0:u.value)||(a==null?void 0:a.mailbox_email)||"";v&&(r.from_email=v)}else{const v=p.from_phone||((S=Oe(a,g==="sms"?"sms":"voice")[0])==null?void 0:S.value)||"";v&&(r.from_phone=v)}f(r)}function Ct(t){var u;const a=A[t]||null,r=p.from_phone||((u=Oe(a,"voice")[0])==null?void 0:u.value)||"";f({telephony_connection_id:t,from_phone:r||p.from_phone||""})}function Nt(t){const a=A[t]||null;f({ai_connection_id:t,voice_provider:(a==null?void 0:a.vendor)||""})}function kt(){const t=Et(xe||{});return ee(t),t}async function Yt(t){if(!(!t||!i||c)){ye(!0),he("");try{const a=new FormData;a.append("file",t);const r=await P("/api/outreach/config/voice-knowledge/upload",{method:"POST",body:a}),u=Wt(String((r==null?void 0:r.content_text)||"").trim());if(!u)throw new Error("Uploaded file did not contain readable text.");const S=String((r==null?void 0:r.file_name)||t.name||"uploaded file").trim(),v=Wt(String(p.voice_prompt||"").trim()),w=`Uploaded reference: ${S} 2 3${u}`;f({voice_prompt:v?`${v} 4 5--- 6${w}`:w}),he(r!=null&&r.truncated?`${S} was added to conversation context, cleaned up, and trimmed to fit the settings field.`:`${S} was added to conversation context and cleaned up for spacing.`)}catch(a){he(a.message||"Failed to process uploaded voice reference.")}finally{ye(!1),le.current&&(le.current.value="")}}}async function Xt(t,a,r={}){if(!(!i||je)){Se(!0),se(""),we("");try{const{telephonySource:u="outbound",vendor:S="twilio_voice",inboundCredentials:v={},voiceAgentId:w="",agentName:b="",voiceProvider:C="",voiceModel:m="",voiceName:xt="",voiceLanguage:Zt="",transferTarget:ea="",inboundGreeting:ta="",aiGuidelines:aa="",voicePrompt:na="",systemPrompt:sa=""}=r,Mt=Object.fromEntries(Object.entries(v||{}).filter(([,tt])=>String(tt||"").trim())),$=await P("/api/outreach/voice/inbound-configure",{method:"POST",body:JSON.stringify({phone_number:t,enabled:a,vendor:S,telephony_source:u,...u==="custom"&&Object.keys(Mt).length?{inbound_credentials:Mt}:{},voice_agent_id:w,agent_name:b,voice_provider:C,voice_model:m,voice_name:xt,voice_language:Zt,transfer_target:ea,inbound_greeting:ta,ai_guidelines:aa,voice_prompt:na,system_prompt:sa})});ne(($==null?void 0:$.inbound)||{});const Ot=($==null?void 0:$.provision_warning)||($==null?void 0:$.twilio_warning);if(Ot)se(`LiveKit configured. Carrier: ${Ot}`);else{const tt=Array.isArray($==null?void 0:$.manual_steps)?$.manual_steps:[];we(tt.length?`Inbound configured. ${tt.length} manual step${tt.length===1?"":"s"} listed below.`:"Inbound calling configured successfully.")}}catch(u){const S=u.message||"Failed to configure inbound calling.",v=S.startsWith("<")?"Server error â check LiveKit credentials in Platform Settings and try again.":S;se(v)}finally{Se(!1)}}}async function qt(){try{const t=await P("/api/outreach/voice/inbound-status");ne((t==null?void 0:t.inbound)||{})}catch{}}async function At(){if(i){F(!0),Z("");try{const t=kt();t.channel=g;const a=await P("/api/outreach/config",{method:"PATCH",body:JSON.stringify(t)}),r=Et((a==null?void 0:a.delivery_config)||t);ee(r),Ee(String((a==null?void 0:a.settings_updated_at)||"").trim()),Te.current=JSON.stringify(r)}catch(t){Z(t.message||"Failed to save outreach settings.")}finally{F(!1)}}}function Qt(t){if(j.scope!==t||!j.draft)return null;const a=j.draft,r=gt(T,t),S=new Set(Array.isArray(te==null?void 0:te[t])?te[t]:[]).has(a.vendor),v=[{id:"customer_managed",label:"Customer account"},...S||a.mode==="platform_managed"?[{id:"platform_managed",label:"Platform-managed"}]:[]],w=j.id&&A[j.id]||null,b=a.mode==="platform_managed",C=K.startsWith("save:")||K.startsWith("delete:")||K.startsWith("sync:");return e.jsxs("div",{className:"outreach-connection-editor",children:[e.jsxs("div",{className:"outreach-connection-editor-head",children:[e.jsxs("div",{children:[e.jsx("div",{className:"outreach-settings-panel-title",children:j.id?"Manage connection":"Add connection"}),e.jsx("div",{className:"outreach-connection-editor-subtitle",children:j.id?"Credentials stay encrypted. Leave secret fields blank if you are not rotating them.":"Connect a customer-owned account once, then assign it to one or more profiles in this workspace."})]}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>G({scope:"",id:"",draft:null}),disabled:C,children:"Close"})]}),e.jsxs("div",{className:"outreach-settings-grid",children:[e.jsx(h,{label:"Vendor",children:e.jsx("select",{className:"form-input",value:a.vendor,onChange:m=>_({vendor:m.target.value,mode:"customer_managed"}),disabled:!i||c||!!j.id,children:r.map(m=>e.jsx("option",{value:m.id,children:m.label},m.id))})}),e.jsx(h,{label:"Access mode",children:e.jsx("select",{className:"form-input",value:a.mode,onCh
6ange:m=>_({mode:m.target.value}),disabled:!i||c,children:v.map(m=>e.jsx("option",{value:m.id,children:m.label},m.id))})}),e.jsx(h,{label:"Connection name",children:e.jsx("input",{className:"form-input",value:a.name,onChange:m=>_({name:m.target.value}),placeholder:U(T,t,a.vendor),disabled:!i||c})}),vt(a.vendor)?e.jsx(h,{label:"Connected mailbox",children:e.jsx("input",{className:"form-input",value:(w==null?void 0:w.mailbox_email)||a.mailbox_email||"",onChange:m=>_({mailbox_email:m.target.value}),placeholder:"Mailbox appears after OAuth connect",disabled:!i||c})}):null,t==="call"||t==="voice_telephony"?e.jsxs(e.Fragment,{children:[a.vendor==="twilio_voice"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"outreach-connection-section",children:[e.jsxs("div",{className:"outreach-connection-section-head",children:[e.jsx("div",{className:"outreach-connection-section-title",children:"Twilio account"}),e.jsx("div",{className:"outreach-connection-section-copy",children:"Used to fetch the customer-owned numbers from Twilio."})]}),e.jsxs("div",{className:"outreach-connection-section-grid",children:[e.jsx(h,{label:"Twilio account SID",children:e.jsx("input",{className:"form-input",value:a.account_sid,onChange:m=>_({account_sid:m.target.value}),placeholder:"AC...",disabled:!i||c||b})}),e.jsx(h,{label:"Twilio auth token",children:e.jsx("input",{className:"form-input",type:"password",value:a.auth_token,onChange:m=>_({auth_token:m.target.value}),placeholder:"Auth token",disabled:!i||c||b})})]})]}),e.jsxs("div",{className:"outreach-connection-section",children:[e.jsxs("div",{className:"outreach-connection-section-head",children:[e.jsx("div",{className:"outreach-connection-section-title",children:"SIP trunk provisioning"}),e.jsx("div",{className:"outreach-connection-section-copy",children:"These settings let us create the LiveKit SIP trunk for this workspace automatically."})]}),e.jsxs("div",{className:"outreach-connection-section-grid",children:[e.jsx(h,{label:"Twilio SIP domain",span:2,children:e.jsx("input",{className:"form-input",value:a.sip_domain,onChange:m=>_({sip_domain:m.target.value}),placeholder:"your-trunk.pstn.twilio.com",disabled:!i||c||b})}),e.jsx(h,{label:"Twilio SIP username",children:e.jsx("input",{className:"form-input",value:a.sip_username,onChange:m=>_({sip_username:m.target.value}),placeholder:"SIP username",disabled:!i||c||b})}),e.jsx(h,{label:"Twilio SIP password",children:e.jsx("input",{className:"form-input",type:"password",value:a.sip_password,onChange:m=>_({sip_password:m.target.value}),placeholder:"SIP password",disabled:!i||c||b})}),e.jsx(h,{label:"Destination country",children:e.jsx("input",{className:"form-input",value:a.destination_country,onChange:m=>_({destination_country:m.target.value}),placeholder:"US",disabled:!i||c||b})})]})]})]}):null,a.vendor==="telnyx_voice"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Telnyx API key",children:e.jsx("input",{className:"form-input",type:"password",value:a.api_key,onChange:m=>_({api_key:m.target.value}),placeholder:"KEY...",disabled:!i||c||b})}),e.jsx(h,{label:"Voice connection ID",children:e.jsx("input",{className:"form-input",value:a.voice_connection_id,onChange:m=>_({voice_connection_id:m.target.value}),placeholder:"Optional",disabled:!i||c||b})})]}):null]}):null,a.vendor==="resend"||a.vendor==="sendgrid"||a.vendor==="telnyx"||a.vendor==="openai_realtime"||a.vendor==="elevenlabs"?e.jsx(h,{label:a.vendor==="openai_realtime"?"OpenAI API key":a.vendor==="elevenlabs"?"ElevenLabs API key":"API key",span:2,children:e.jsx("input",{className:"form-input",type:"password",value:a.api_key,onChange:m=>_({api_key:m.target.value}),placeholder:"Enter API key",disabled:!i||c||b})}):null,a.vendor==="smtp"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"SMTP host",children:e.jsx("input",{className:"form-input",value:a.host,onChange:m=>_({host:m.target.value}),placeholder:"smtp.gmail.com",disabled:!i||c||b})}),e.jsx(h,{label:"SMTP port",children:e.jsx("input",{className:"form-input",value:a.port,onChange:m=>_({port:m.target.value}),placeholder:"587",disabled:!i||c||b})}),e.jsx(h,{label:"SMTP username",children:e.jsx("input",{className:"form-input",value:a.username,onChange:m=>_({username:m.target.value}),placeholder:"[email protected]",disabled:!i||c||b})}),e.jsx(h,{label:"SMTP password",children:e.jsx("input",{className:"form-input",type:"password",value:a.password,onChange:m=>_({password:m.target.value}),placeholder:"App password",disabled:!i||c||b})})]}):null,a.vendor==="twilio"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Twilio account SID",children:e.jsx("input",{className:"form-input",value:a.account_sid,onChange:m=>_({account_sid:m.target.value}),placeholder:"AC...",disabled:!i||c||b})}),e.jsx(h,{label:"Twilio auth token",children:e.jsx("input",{className:"form-input",type:"password",value:a.auth_token,onChange:m=>_({auth_token:m.target.value}),placeholder:"Auth token",disabled:!i||c||b})})]}):null,a.vendor==="plivo"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Plivo auth ID",children:e.jsx("input",{className:"form-input",value:a.auth_id,onChange:m=>_({auth_id:m.target.value}),placeholder:"MA...",disabled:!i||c||b})}),e.jsx(h,{label:"Plivo auth token",children:e.jsx("input",{className:"form-input",type:"password",value:a.auth_token,onChange:m=>_({auth_token:m.target.value}),placeholder:"Auth token",disabled:!i||c||b})})]}):null,a.vendor==="custom_webhook"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Webhook URL",
6span:2,children:e.jsx("input",{className:"form-input",value:a.webhook_url,onChange:m=>_({webhook_url:m.target.value}),placeholder:"https://hooks.company.com/outreach",disabled:!i||c||b})}),e.jsx(h,{label:"Auth header name",children:e.jsx("input",{className:"form-input",value:a.auth_header_name,onChange:m=>_({auth_header_name:m.target.value}),placeholder:"Authorization",disabled:!i||c||b})}),e.jsx(h,{label:"Auth header value",children:e.jsx("input",{className:"form-input",type:"password",value:a.auth_header_value,onChange:m=>_({auth_header_value:m.target.value}),placeholder:"Bearer ...",disabled:!i||c||b})})]}):null,a.vendor==="custom_sip"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"SIP URI",span:2,children:e.jsx("input",{className:"form-input",value:a.sip_uri,onChange:m=>_({sip_uri:m.target.value}),placeholder:"sip:voice.company.com",disabled:!i||c||b})}),e.jsx(h,{label:"SIP username",children:e.jsx("input",{className:"form-input",value:a.sip_username,onChange:m=>_({sip_username:m.target.value}),placeholder:"Username",disabled:!i||c||b})}),e.jsx(h,{label:"SIP password",children:e.jsx("input",{className:"form-input",type:"password",value:a.sip_password,onChange:m=>_({sip_password:m.target.value}),placeholder:"Password",disabled:!i||c||b})})]}):null]}),b?e.jsxs(B,{children:["This tenant has access to a platform-managed vendor for ",U(T,t,a.vendor),". Credentials stay off the UI. Customer-facing profiles only pick sender identities, numbers, and runtime behavior."]}):vt(a.vendor)?e.jsx(B,{children:"Save this connection first, then click Connect to complete OAuth and fetch the mailbox identity into this workspace."}):e.jsx(B,{children:"Workspace credentials are encrypted server-side. This connection stays isolated to the current customer workspace only."}),e.jsxs("div",{className:"outreach-connection-editor-actions",children:[e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>Jt(),disabled:!i||c||C,children:K.startsWith("save:")?"Saving...":"Save account"}),_t(a.vendor)&&j.id?e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>ht(j.id),disabled:!i||c||C,children:K===`sync:${j.id}`?"Syncing...":"Sync resources"}):null,vt(a.vendor)&&j.id?e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>wt(j.id),disabled:!i||c||C,children:w!=null&&w.mailbox_email?"Reconnect":"Connect"}):null,j.id?e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>St(j.id,t),disabled:!i||c||C,children:K===`delete:${j.id}`?"Removing...":"Delete"}):null]})]})}function bt(t,a,r){const u=W[t]||[],S=a?u.filter(v=>v.id===a):u;return e.jsxs(de,{title:ma(t),subtitle:"Each workspace keeps its own vendor connections. Connect the account once here, then assign it to one or more outreach profiles.",children:[e.jsxs("div",{className:"outreach-connection-toolbar",children:[e.jsx(B,{children:"BYO account is the primary path. Platform-managed mode only appears here if superadmin has enabled it for this tenant and vendor."}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>J(t),disabled:!i||c,children:"Add account"})]}),S.length?e.jsx("div",{className:"outreach-connection-list",children:S.map(v=>{const w=a===v.id,b=xa(v),C=K;return e.jsxs("div",{className:`outreach-connection-card${w?" is-selected":""}`,children:[e.jsxs("div",{className:"outreach-connection-card-head",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"outreach-connection-title",children:[v.name||U(T,t,v.vendor),v.shared&&e.jsxs("span",{title:"Shared with everyone in this workspace",style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:10,fontWeight:700,padding:"2px 7px",borderRadius:999,background:"rgba(13,148,136,.12)",color:"#0d9488",marginLeft:8,verticalAlign:"middle"},children:[e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"}),e.jsx("path",{d:"M3 21v-2a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v2"})]}),"Shared"]})]}),e.jsxs("div",{className:"outreach-connection-meta",children:[U(T,t,v.vendor)," · ",v.mode==="platform_managed"?"platform managed":"customer account"]})]}),e.jsx("span",{className:`outreach-connection-status is-${String(v.status||"draft").toLowerCase()}`,children:ga(v.status)})]}),v.mailbox_email?e.jsx("div",{className:"outreach-connection-inline",children:v.mailbox_email}):null,b?e.jsx("div",{className:"outreach-connection-inline",children:b}):null,Ut(v)?e.jsx("div",{className:"outreach-settings-alert is-error",children:Ut(v)}
6):null,e.jsxs("div",{className:"outreach-connection-card-actions",children:[e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>r(v.id),disabled:!i||c,children:w?"Selected":"Use in profile"}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>J(t,v),disabled:!i||c,children:"Manage"}),vt(v.vendor)?e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>wt(v.id),disabled:!i||c,children:v.mailbox_email?"Reconnect":"Connect"}):null,_t(v.vendor)?e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>ht(v.id),disabled:!i||c||C===`sync:${v.id}`,children:C===`sync:${v.id}`?"Syncing...":"Sync"}):null,e.jsx("button",{type:"button",className:"btn-secondary",style:{color:"#b91c1c",borderColor:"rgba(239,68,68,.25)"},onClick:()=>{window.confirm(`Disconnect ${v.name||"this account"}? Vendor credentials will be wiped from this workspace and any LiveKit outbound trunks will be unlinked. The vendor account itself stays intact â re-add it later if needed.`)&&St(v.id,t)},disabled:!i||c||C===`delete:${v.id}`,title:"Wipe this vendor connection from the workspace. The Twilio/Telnyx/Plivo account stays untouched on the vendor's side â only our reference is removed.",children:C===`delete:${v.id}`?"Removingâ¦":"Disconnect"})]})]},v.id)})}):e.jsx("div",{className:"outreach-settings-empty-panel",children:"No connected accounts yet. Add one for this workspace before binding it to a profile."}),Qt(t)]})}if(R)return e.jsxs(Rt,{title:"Outreach settings",children:[e.jsx("style",{children:` 7 .al-page-body { padding: 0 !important; overflow: hidden !important; display: flex !important; flex-direction: column !important; } 8 `}),e.jsx("div",{className:"outreach-settings-page",children:e.jsx("div",{className:"outreach-settings-empty",children:e.jsxs("div",{children:[e.jsx("strong",{children:"Loading outreach settings"}),e.jsx("div",{children:"Fetching saved channels, profiles, and connected vendor accounts."})]})})})]});const Pt=`outreach-email-options-${p.id}`,It=`outreach-sms-options-${p.id}`,Tt=`outreach-call-options-${p.id}`,Lt=`outreach-voice-options-${p.id}`;return e.jsxs(Rt,{title:"Outreach settings",children:[e.jsx("style",{children:` 9 .al-page-body { padding: 0 !important; overflow: hidden !important; display: flex !important; flex-direction: column !important; } 10 `}),e.jsxs("div",{className:"outreach-settings-page",children:[e.jsxs("div",{style:{padding:"12px 18px",borderBottom:"1px solid var(--border)",background:"var(--surface)",display:"flex",alignItems:"center",gap:14,flexWrap:"wrap"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:"Reply polling window"}),e.jsx("span",{style:{fontSize:11,color:"var(--text3)"},children:"How many days after each outbound message the system keeps polling IMAP for replies. Applied workspace-wide. Max 90."})]}),e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"number",min:1,max:90,step:1,value:Ne,onChange:t=>Ge(t.target.value),disabled:!i||me,style:{width:76,padding:"6px 8px",fontSize:13,border:"1px solid var(--border)",borderRadius:6}}),e.jsx("span",{style:{fontSize:12,color:"var(--text3)"},children:"days"}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:ce,disabled:!i||me,style:{fontSize:12,padding:"6px 10px"},children:me?"Savingâ¦":"Save"}),ve&&e.jsx("span",{style:{fontSize:11,color:ve.toLowerCase().includes("fail")?"#dc2626":"#0d9488"},children:ve})]})]}),e.jsxs("div",{className:"outreach-settings-shell",children:[e.jsxs("section",{className:"outreach-settings-column outreach-settings-nav-column",children:[e.jsxs("div",{className:"outreach-settings-column-head",children:[e.jsx("h2",{className:"outreach-settings-panel-title",children:"BeetlOutreach settings"}),e.jsxs("span",{className:"outreach-settings-count",children:[Me.length," channels"]})]}),e.jsx("div",{className:"outreach-settings-column-body",children:e.jsx("div",{className:"outreach-settings-list",children:Me.map(t=>e.jsxs("button",{type:"button",className:`outreach-settings-channel${g===t.id?" is-active":""}`,onClick:()=>Ze(t.id),children:[e.jsx("span",{className:"outreach-settings-icon",children:e.jsx(_a,{channel:t.id})}),e.jsxs("span",{className:"outreach-settings-channel-copy",children:[e.jsxs("span",{className:"outreach-settings-channel-top",children:[e.jsx("span",{className:"outreach-settings-channel-name",children:t.label}),e.jsx("span",{className:"outreach-settings-count",children:Qe[t.id]||1})]}),e.jsx("span",{className:"outreach-settings-channel-meta",children:t.description})]})]},t.id))})})]}),e.jsxs("section",{className:"outreach-settings-column outreach-settings-profiles-column",children:[e.jsxs("div",{className:"outreach-settings-column-head",children:[e.jsx("h2",{className:"outreach-settings-panel-title",children:pa(g)}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:dt,disabled:!i||c,children:"Add profile"})]}),e.jsx("div",{className:"outreach-settings-column-body",children:e.jsx("div",{className:"outreach-profile-list",children:E.map(t=>e.jsxs("button",{type:"button",className:`outreach-profile-item${t.id===p.id?" is-active":""}`,onClick:()=>y(t.id),children:[e.jsxs("div",{className:"outreach-profile-name",children:[t.name||t.voice_agent_name||"Unnamed profile",t.voice_agent_name&&t.voice_agent_name!==t.name&&e.jsxs("span",{style:{display:"block",fontSize:11,fontWeight:400,color:"#64748b",marginTop:1},children:["Agent: ",t.voice_agent_name]}),t.shared&&e.jsxs("span",{title:"Shared with everyone in this workspace",style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:9.5,fontWeight:700,padding:"2px 6px",borderRadius:999,background:"rgba(13,148,136,.12)",color:"#0d9488",marginLeft:8,verticalAlign:"middle"},children:[e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"}),e.jsx("path",{d:"M3 21v-2a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v2"})]}),"Shared"]})]}),e.jsx("div",{className:"outreach-profile-meta",children:fa(g,t,A,T)})]},t.id))})})]}),e.jsxs("main",{className:"outreach-settings-content outreach-settings-column outreach-settings-main-column",children:[e.jsxs("div",{className:"outreach-settings-main-head",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"outreach-settings-heading",children:ha(g)}),e.jsx("p",{className:"outreach-settings-subtitle",children:"Connect customer-owned vendor accounts once per workspace, bind them to profiles below, and keep one-time infra secrets off the UI."})]}),e.jsxs("div",{className:"outreach-settings-main-actions",children:[e.jsxs("div",{className:"outreach-settings-state",children:[e.jsx("span",{className:"outreach-settings-state-dot"}),e.jsx("span",{children:ct})]}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:ut,disabled:!i||c,children:"Duplicate"}),e.jsx("button",{type:"button",className:"btn-primary",onClick:At,disabled:!i||c||!ge,children:c?"Saving...":"Save settings"})]})]}),e.jsxs("div",{className:"outreach-settings-main",children:[i?null:e.jsx("div",{className:"outreach-settings-alert is-info",children:"These settings are read-only for your role. You can review profiles and connections here, but only users with Outreach edit access can save changes."}),Re?e.jsx("div",{className:"outreach-settings-alert is-error",children:Re}):null,Ce?e.jsx("div",{className:"outreach-settings-alert is-error",children:Ce}):null,Ke?e.jsx("div",{className:"outreach-settings-alert is-success",children:Ke}):null,g==="voice"?e.jsx("div",{style:{display:"flex",gap:6,marginBottom:20,borderBottom:"1px solid var(--border)",paddingBottom:0}
10,children:["outbound","inbound"].map(t=>e.jsx("button",{type:"button",onClick:()=>X(t),style:{padding:"7px 16px",fontSize:13,fontWeight:600,border:"none",background:"none",cursor:"pointer",color:H===t?"var(--accent)":"var(--text2)",borderBottom:H===t?"2px solid var(--accent)":"2px solid transparent",marginBottom:-1,borderRadius:0,transition:"color 0.14s, border-color 0.14s",textTransform:"capitalize"},children:t==="outbound"?"Outbound":"Inbound callbacks"},t))}):null,g==="voice"&&H==="outbound"?e.jsxs(e.Fragment,{children:[bt("voice_telephony",p.telephony_connection_id||L.telephony_connection_id,Ct),bt("voice_ai",p.ai_connection_id||L.ai_connection_id,Nt)]}):g==="voice"&&H==="inbound"||g==="whatsapp"?null:bt(g,p.connection_id||L.connection_id,pt),g==="voice"&&H==="inbound"?e.jsx(ya,{canEdit:i,busy:je,config:De,error:Ie,success:ie,outboundAccount:Q?{name:Q.name||"Twilio account",vendor:Q.vendor||"twilio_voice",vendor_label:Q.vendor?Gt(Q.vendor):"Twilio Voice"}:null,onConfigure:Xt,onRefresh:qt,webhookUrl:pe}):null,g!=="voice"||H==="outbound"?e.jsxs(e.Fragment,{children:[e.jsxs(de,{title:"Profile identity",subtitle:"Each profile represents one sender or runtime configuration that can be invoked from the workflow board.",children:[e.jsxs("div",{className:"outreach-settings-grid",children:[e.jsx(h,{label:"Profile name",children:e.jsx("input",{className:"form-input",value:p.name||"",onChange:t=>f({name:t.target.value}),disabled:!i||c})}),e.jsx(h,{label:"Enabled",children:e.jsxs("select",{className:"form-input",value:p.enabled?"yes":"no",onChange:t=>f({enabled:t.target.value==="yes"}),disabled:!i||c,children:[e.jsx("option",{value:"yes",children:"Yes"}),e.jsx("option",{value:"no",children:"No"})]})}),e.jsx(h,{label:"Sharing",children:e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",border:"1px solid var(--border)",borderRadius:9,cursor:i&&!c?"pointer":"default",background:p.shared?"var(--active-bg)":"var(--surface)",transition:"background .15s, border-color .15s"},children:[e.jsx("input",{type:"checkbox",checked:!!p.shared,onChange:t=>f({shared:t.target.checked}),disabled:!i||c,style:{marginTop:2}}),e.jsxs("span",{children:[e.jsx("span",{style:{fontWeight:600,color:"var(--text)",fontSize:13},children:"Share this profile with everyone in the workspace"}),e.jsxs("span",{style:{display:"block",fontSize:12,color:"var(--text3)",marginTop:2,lineHeight:1.45},children:["When on, any teammate who has the ",g," profile-access permission can use this profile for outreach. When off, only you can use it. Each user can still create their own private profiles."]})]})]})}),e.jsx(h,{label:"Bulk outreach",children:e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",border:"1px solid var(--border)",borderRadius:9,cursor:i&&!c?"pointer":"default",background:p.bulk_enabled?"var(--active-bg)":"var(--surface)",transition:"background .15s, border-color .15s"},children:[e.jsx("input",{type:"checkbox",checked:!!p.bulk_enabled,onChange:t=>f({bulk_enabled:t.target.checked}),disabled:!i||c,style:{marginTop:2}}),e.jsxs("span",{children:[e.jsx("span",{style:{fontWeight:600,color:"var(--text)",fontSize:13},children:"Allow this profile to send bulk outreach"}),e.jsx("span",{style:{display:"block",fontSize:12,color:"var(--text3)",marginTop:2,lineHeight:1.45},children:"When on, this profile appears in the Bulk Outreach channel dropdown on workflow boards. Off by default to prevent accidental mass sends â flip on only for the profiles you've vetted for volume."})]})]})}),e.jsxs(h,{label:"Reply polling window",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("input",{type:"number",min:1,max:90,step:1,placeholder:"Use workspace default",value:p.reply_polling_days===void 0||p.reply_polling_days===null||p.reply_polling_days===""?"":p.reply_polling_days,onChange:t=>{const a=t.target.value;if(a==="")f({reply_polling_days:null});else{const r=Math.max(1,Math.min(90,parseInt(a,10)||14));f({reply_polling_days:r})}},disabled:!i||c,style:{width:110,padding:"7px 10px",fontSize:13,border:"1px solid var(--border)",borderRadius:6}}),e.jsx("span",{style:{fontSize:12,color:"var(--text3)"},children:"days (max 90)"})]}),e.jsx("div",{style:{fontSize:11.5,color:"var(--text3)",marginTop:6,lineHeight:1.45},children:"How long after each outbound message this profile keeps polling IMAP for replies. Leave blank to use the workspace default at the top of this page."})]}),g==="email"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Connected account",children:e.jsxs("select",{className:"form-input",value:p.connection_id||"",onChange:t=>pt(t.target.value),disabled:!i||c,children:[e.jsx("option",{value:"",children:"Select email account"}),W.email.map(t=>e.jsx("option",{value:t.id,children:t.name||U(T,"email",t.vendor)},t.id))]})}),e.jsx(h,{label:"From email",children:e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"form-input",list:Pt,value:p.from_email||"",onChange:t=>f({from_email:t.target.value}),placeholder:"[email protected]",disabled:!i||c}),it.length?e.jsx("datalist",{id:Pt,children:it.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}):null]})}),e.jsx(h,{label:"From name",children:e.jsx("input",{className:"form-input",value:p.from_name||"",onChange:t=>f({from_name:t.target.value}),placeholder:"Admissions team",disabled:!i||c})}),e.jsx(h,{label:"Reply-to",children:e.jsx("input",{className:"form-input",value:p.reply_to||"",onChange:t=>f({reply_to:t.target.value}),placeholder:"[email protected]",disabled:!i||c})})]}):null,g==="whatsapp"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Phone Number ID",children:e.jsx("input",{className:"form-input",value:p.phone_number_id||"",onChange:t=>f({phone_number_id:t.target.value}),placeholder:"Meta WhatsApp phone number ID",disabled:!i||c})}),e.jsx(h,{label:"Access Token",children:e.jsx("input",{className:"form-input",type:"password",value:p.api_key||"",onChange:t=>f({api_key:t.target.value}),placeholder:"Meta permanent or system user access token",disabled:!i||c})}),e.jsx(h,{label:"Business Account ID (WABA)",children:e.jsx("input",{className:"form-input",value:p.account_sid||"",onChange:t=>f({account_sid:t.target.value}),placeholder:"WhatsApp Business Account ID (optional)",disabled:!i||c})}),e.jsx(h,{label:"Sender display name",children:e.jsx("input",{className:"form-input",value:p.from_name||"",onChange:t=>f({from_name:t.target.value}),placeholder:"Founder's Office",disabled:!i||c})}),e.jsx(h,{label:"From phone (E.164)",children:e.jsx("input",{className:"form-input",value:p.from_phone||"",onChange:t=>f({from_phone:t.target.value}),placeholder:"+919876543210",disabled:!i||c})}),e.jsxs("div",{style:{fontSize:11,color:"#64748b",lineHeight:1.6,marginTop:4},children:["Uses Meta Cloud API v19.0. Get your Phone Number ID and access token from the"," ",e.jsx("a",{href:"https://developers.facebook.com/apps/",target:"_blank",rel:"noopener noreferrer",style:{color:"#1d4ed8"},children:"Meta Developer portal"}),"."]})]}):null,g==="sms"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Connected account",children:e.jsxs("select",{className:"form-input",value:p.connection_id||"",onChange:t=>pt(t.target.value),disabled:!i||c,children:[e.jsx("option",{value:"",children:"Select SMS account"}),W.sms.map(t=>e.jsx("option",{value:t.id,children:t.name||U(T,"sms",t.vendor)},t.id))]})}),e.jsx(h,{label:"From phone",children:e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"form-input",list:It,value:p.from_phone||"",onChange:t=>f({from_phone:t.target.value}),placeholder:"+1 415 555 0123",disabled:!i||c}),qe.length?e.jsx("datalist",{id:It,children:qe.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}):null]})}),e.jsx(h,{label:"Sender label",children:e.jsx("input",{className:"form-input",value:p.sender_name||p.from_name||"",onChange:t=>f({sender_name:t.target.value,from_name:t.target.value}),placeholder:"Admissions desk",disabled:!i||c})})]}):null,g==="call"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Connected account",children:e.jsxs("select",{className:"form-input",value:p.connection_id||"",onChange:t=>pt(t.target.value),disabled:!i||c,children:[e.jsx("option",{value:"",children:"Select call account"}),W.call.map(t=>e.jsx("option",{value:t.id,children:t.name||U(T,"call",t.vendor)},t.id))]})}),e.jsx(h,{label:"From phone",children:e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"form-input",list:Tt,value:p.from_phone||"",onChange:t=>f({from_phone:t.target.value}),placeholder:"+1 415 555 0123",disabled:!i||c}),lt.length?e.jsx("datalist",{id:Tt,children:lt.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}):null]})}),e.jsx(h,{label:"Sender label",children:e.jsx("input",{className:"form-input",value:p.sender_name||p.from_name||"",onChange:t=>f({sender_name:t.target.value,from_name:t.target.value}),placeholder:"Admissions desk",disabled:!i||c})}),e.jsx(h,{label:"Transfer target",children:e.jsx("input",{className:"form-input",value:p.transfer_target||"",onChange:t=>f({transfer_target:t.target.value}),placeholder:"+1 415 555 0199",disabled:!i||c})})]}):null,g==="voice"?e.jsxs(e.Fragment,{children:[e.jsx(h,{label:"Telephony account",children:e.jsxs("select",{className:"form-input",value:p.telephony_connection_id||"",onChange:t=>Ct(t.target.value),disabled:!i||c,children:[e.jsx("option",{value:"",children:"Select telephony account"}
10),W.voice_telephony.map(t=>e.jsx("option",{value:t.id,children:t.name||U(T,"voice_telephony",t.vendor)},t.id))]})}),e.jsx(h,{label:"AI account",children:e.jsxs("select",{className:"form-input",value:p.ai_connection_id||"",onChange:t=>Nt(t.target.value),disabled:!i||c,children:[e.jsx("option",{value:"",children:"Select AI account"}),W.voice_ai.map(t=>e.jsx("option",{value:t.id,children:t.name||U(T,"voice_ai",t.vendor)},t.id))]})}),e.jsx(h,{label:"From phone",children:e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"form-input",list:Lt,value:p.from_phone||"",onChange:t=>f({from_phone:t.target.value}),placeholder:"+1 415 555 0123",disabled:!i||c}),ot.length?e.jsx("datalist",{id:Lt,children:ot.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}):null]})}),e.jsx(h,{label:"Sender label",children:e.jsx("input",{className:"form-input",value:p.sender_name||p.from_name||"",onChange:t=>f({sender_name:t.target.value,from_name:t.target.value}),placeholder:"Admissions assistant",disabled:!i||c})})]}):null]}),e.jsx(B,{children:"Profile fields stay customer-facing. Vendor credentials, OAuth app secrets, LiveKit infra, and other one-time platform secrets stay outside the UI."})]}),g==="call"?e.jsx(de,{title:"Call behavior",subtitle:"Only call behavior stays editable here. Transport credentials and webhook plumbing live in the connected account or the platform-managed setup.",children:e.jsxs("div",{className:"outreach-settings-grid",children:[e.jsx(h,{label:"Call mode",children:e.jsx("select",{className:"form-input",value:p.call_mode||"live",onChange:t=>f({call_mode:t.target.value}),disabled:!i||c,children:ca.filter(t=>t.id!=="voice_agent").map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))})}),e.jsx(h,{label:"Call notes",children:e.jsx("input",{className:"form-input",value:p.call_script||"",onChange:t=>f({call_script:t.target.value}),placeholder:"Optional operator note or transfer instruction",disabled:!i||c})})]})}):null,g==="voice"?e.jsxs(e.Fragment,{children:[e.jsxs(de,{title:"Voice runtime",subtitle:"Choose the runtime behavior that should sit on top of the connected telephony and AI accounts for this profile.",children:[e.jsxs("div",{className:"outreach-settings-grid",children:[e.jsx(h,{label:"Call mode",children:e.jsxs("select",{className:"form-input",value:p.call_mode||"voice_agent",onChange:t=>f({call_mode:t.target.value}),disabled:!i||c,children:[e.jsx("option",{value:"voice_agent",children:"Voice AI"}),e.jsx("option",{value:"hybrid",children:"Hybrid"}),e.jsx("option",{value:"live",children:"Live call"})]})}),e.jsx(h,{label:"Agent name",children:e.jsx("input",{className:"form-input",value:p.voice_agent_name||"",onChange:t=>f({voice_agent_name:t.target.value}),placeholder:"e.g. Admissions assistant",disabled:!i||c})}),e.jsx(h,{label:"Caller company",children:e.jsx("input",{className:"form-input",value:p.caller_company||"",onChange:t=>f({caller_company:t.target.value}),placeholder:"e.g. Evolving Being",disabled:!i||c})}),e.jsx(h,{label:"Escalation / transfer number",children:e.jsx("input",{className:"form-input",value:p.transfer_target||"",onChange:t=>f({transfer_target:t.target.value}),placeholder:"+1 415 555 0199",disabled:!i||c})}),e.jsx(h,{label:"Voice model",children:ke==="openai_realtime"?e.jsxs("select",{className:"form-input",value:p.voice_model||"",onChange:t=>f({voice_model:t.target.value}),disabled:!i||c,children:[e.jsx("option",{value:"",children:"Select model"}),Vt.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))]}):ke==="elevenlabs"?e.jsxs("select",{className:"form-input",value:p.voice_model||"",onChange:t=>f({voice_model:t.target.value}),disabled:!i||c,children:[e.jsx("option",{value:"",children:"Select model"}),Kt.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))]}):e.jsx("input",{className:"form-input",value:p.voice_model||"",onChange:t=>f({voice_model:t.target.value}),placeholder:"Choose AI account first",disabled:!0})}),e.jsx(h,{label:"Voice",children:ke==="openai_realtime"?e.jsxs("select",{className:"form-input",value:p.voice_name||"",onChange:t=>f({voice_name:t.target.value}),disabled:!i||c,children:[e.jsx("option",{value:"",children:"Select voice"}),Ht.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))]}):e.jsx("input",{className:"form-input",value:p.voice_name||"",onChange:t=>f({voice_name:t.target.value}),placeholder:ke==="elevenlabs"?"ElevenLabs voice ID":"Choose AI account first",disabled:!i||c||!ke})}),e.jsx(h,{label:"Voice language",children:e.jsx("input",{className:"form-input",value:p.voice_language||"",onChange:t=>f({voice_language:t.target.value}),placeholder:"auto / en-US",disabled:!i||c})})]}),e.jsx(B,{children:"The AI account decides which secret key is used. Telephony and AI infrastru
10cture stay off the profile UI, but the profile still controls runtime choices like escalation number, model, voice, and language."}),e.jsxs(B,{children:[e.jsx("strong",{children:"Agent name"})," and ",e.jsx("strong",{children:"Caller company"})," here are the fallback values used when no Voice Agent library entry is assigned to this workflow. When a library agent is assigned, its name and configuration take priority."]})]}),e.jsxs(de,{title:"Conversation design",subtitle:"Set the behavior rules and knowledge the voice agent uses during calls.",children:[e.jsxs("div",{className:"outreach-settings-upload-row",children:[e.jsxs("div",{className:"outreach-settings-upload-copy",children:[e.jsx(B,{children:"Upload a PDF or text file and weâll extract readable text into the conversation context field below."}),e.jsx(B,{children:"The Normalize spacing action cleans pasted or uploaded copy before you save it. It helps with merged words, punctuation spacing, and extra whitespace, but it is still heuristic."}),ze?e.jsx(B,{children:ze}):null]}),e.jsxs("div",{className:"outreach-settings-upload-actions",children:[e.jsx("button",{type:"button",className:"btn-secondary",onClick:kt,disabled:!i||c||Pe,children:"Normalize spacing"}),e.jsx("button",{type:"button",className:"btn-secondary",onClick:()=>{var t;return(t=le.current)==null?void 0:t.click()},disabled:!i||c||Pe,children:Pe?"Processing...":"Upload PDF"})]}),e.jsx("input",{ref:le,type:"file",accept:".pdf,.txt,.md,.csv,text/plain,text/markdown,text/csv,application/pdf",style:{display:"none"},onChange:t=>{var a;return Yt((a=t.target.files)==null?void 0:a[0])}})]}),e.jsxs("div",{className:"outreach-settings-grid",children:[e.jsx(h,{label:"Agent instructions",span:2,children:e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"form-input outreach-settings-textarea",value:p.ai_guidelines||"",onChange:t=>f({ai_guidelines:t.target.value}),placeholder:"Define tone, compliance boundaries, escalation rules, and callback policy.",disabled:!i||c}),e.jsx(B,{children:"HOW the agent behaves â tone, compliance, escalation rules. Keep factual answers and call content in the FAQ field below."})]})}),e.jsx(h,{label:"FAQ and conversation context",span:2,children:e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"form-input outreach-settings-textarea",value:p.voice_prompt||"",onChange:t=>f({voice_prompt:t.target.value}),placeholder:"Approved answers, objection handling, and campaign-specific context the voice agent should know.",disabled:!i||c}),e.jsx(B,{children:"Knowledge the agent draws on during the call â answers, objections, context. Use free text or upload a PDF / text file."})]})})]})]})]}):null]}):null,g!=="voice"||H==="outbound"?e.jsxs("div",{className:"outreach-settings-main-actions",children:[e.jsx("button",{type:"button",className:"btn-secondary",onClick:n,disabled:!i||c||E.length<=1,children:"Delete profile"}),e.jsx("button",{type:"button",className:"btn-primary",onClick:At,disabled:!i||c||!ge,children:c?"Saving...":"Save settings"})]}):null]})]})]})]})]})}export{Ca 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.