PageSourceSearch

https://www.tunvo.ai/console/assets/VoiceAgentTestFlow-CUtICnwo.js

js tunvo.ai collected 2026-10-05 13:09:33 UTC 29,078 bytes, 1 lines download raw bytes

1import{i as xe}from"./rolldown-runtime-CWwJB0VF.js";import{Bn as we,Fn as ae,Mn as ve,On as ye,Si as Ce,Sn as Fe,Tn as X,Vi as ke,_i as Se,_n as De,a as me,b as Ee,fi as Te,gn as Ae,gr as Le,hr as ue,i as Me,ir as Ie,jn as _e,kr as U,mi as Re,n as Pe,pi as Be,r as Ve,sr as qe,t as fe,yi as ne,yn as Oe}from"./react-vendor-D3WPDKd6.js";import{D as N,t as He}from"./vendor-y_NAUOxy.js";import{$t as $e,B as re,Bn as M,Dt as Ue,En as ee,G as Ge,Gt as ze,In as Qe,Jt as Ke,Ln as Ze,M as We,Nt as Je,O as Ye,Qt as Xe,St as es,V as le,Vn as y,W as ss,Wt as ts,Zt as as,a as Q,an as ns,fn as $,i as K,j as rs,n as Z,pn as oe,qt as ls,r as W,rn as os,t as is,vn as _,wt as cs}from"./index-BioTxmRF.js";import{t as ie}from"./slider-BgQXInSC.js";import{t as ds}from"./Voice Agent Black Medium-DqcP0jUm.js";var l=xe(ke()),e=xe(Ce());function xs({open:s,onOpenChange:a,onSuccess:t,botCode:g}){const{t:r}=U("voiceAgent"),[m,n]=(0,l.useState)(""),[p,j]=(0,l.useState)(!1),[d,i]=(0,l.useState)(""),u=()=>m.trim()?(i(""),!0):(i(r("feedback.feedbackRequired")),!1),F=async()=>{if(!u())return!1;j(!0);try{const f=`AgentID=${g}, content=${m}`,C=await _.submitFeedback({category:"robot_test",content:m,botCode:g,notes:f});if(C.retCode==="000000")return N.success(r("feedback.sendSuccess")),n(""),i(""),t?.(),!0;throw new Error(C.retMsg||r("feedback.sendFailed"))}catch(f){console.error("Failed to send feedback",f);const C=f instanceof Error?f.message:r("feedback.sendFailed");throw N.error(C),f}finally{j(!1)}},w=()=>{n(""),i("")},k=f=>{f||w(),a(f)};return(0,e.jsx)(cs,{open:s,onOpenChange:k,title:r("feedback.title"),description:r("feedback.description"),maxWidth:"520px",cancelButtonText:r("feedback.cancel"),onCancel:()=>{w()},okButtonText:r(p?"feedback.sending":"feedback.send"),onOk:F,okButtonLoading:p,okButtonDisabled:!m||p,className:"gap-0 border border-[#f3f4f6] p-0 shadow-[0px_24px_48px_0px_rgba(26,28,36,0.12)]",footer:(0,e.jsxs)("div",{className:"flex flex-row justify-end gap-2 w-full",children:[(0,e.jsx)("button",{type:"button",onClick:()=>{w(),k(!1)},disabled:p,className:"h-9 rounded-[24px] border-[1px] border-solid border-[#d1d5dc] bg-white px-4 py-2 text-sm font-medium leading-5 text-[#19191a] shadow-[0_0.5px_2px_0_rgba(0,0,0,0.05)] hover:bg-accent hover:text-accent-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:r("feedback.cancel")}),(0,e.jsxs)("button",{type:"button",onClick:async()=>{await F()&&k(!1)},disabled:!m||p,className:"h-9 gap-2 rounded-[24px] bg-[#19191a] px-4 py-2 text-sm font-medium leading-5 text-[#fafafa] shadow-[0_0.5px_2px_0_rgba(0,0,0,0.05)] hover:bg-[#19191a]/90 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center",children:[(0,e.jsx)(De,{className:"h-4 w-4"}),r(p?"feedback.sending":"feedback.send")]})]}),children:(0,e.jsx)("div",{className:"flex flex-col gap-4",children:(0,e.jsxs)("div",{children:[(0,e.jsx)(os,{label:r("feedback.feedback"),id:"feedback",type:"textarea",value:m,onChange:n,placeholder:r("feedback.feedbackPlaceholder"),maxLength:3e3,showCounter:!1,textareaClassName:"min-h-[96px] rounded-[12px] border-[#d1d5dc] px-4 py-2 text-sm leading-5 text-[#19191a] shadow-[0px_0.5px_2px_0px_rgba(0,0,0,0.05)] placeholder:text-[#4a5565]"}),d&&(0,e.jsx)("p",{className:"mt-1.5 text-sm font-medium leading-5 text-[#e7000b]",children:d})]})})})}var ms=Me,q=l.forwardRef(({className:s,...a},t)=>(0,e.jsx)(Ve,{ref:t,className:y("border-b",s),...a}));q.displayName="AccordionItem";var O=l.forwardRef(({className:s,children:a,...t},g)=>(0,e.jsx)(Pe,{className:"flex",children:(0,e.jsxs)(me,{ref:g,className:y("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",s),...t,children:[a,(0,e.jsx)(ue,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));O.displayName=me.displayName;var H=l.forwardRef(({className:s,children:a,...t},g)=>(0,e.jsx)(fe,{ref:g,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...t,children:(0,e.jsx)("div",{className:y("pb-4 pt-0",s),children:a})}));H.displayName=fe.displayName;var us=20;function fs({locationId:s}){const{t:a}=U("voiceAgent"),t=(0,l.useRef)(null),{data:g,fetchNextPage:r,hasNextPage:m,isFetchingNextPage:n,isLoading:p,isError:j}=Se({queryKey:["location-faq-list",s],queryFn:async({pageParam:i=1})=>{if(!s)return null;const u=await ee.getLocationFAQList({locationId:s,current:i,size:us});return u.retCode!=="000000"?(N.error(u.retMsg||a("locationDrawer.faqFetchError")),null):u},getNextPageParam:i=>{if(!i?.data)return;const u=i.data.current,F=Math.ceil(i.data.total/i.data.size);return u<F?u+1:void 0},initialPageParam:1,enabled:!!s}),d=g?.pages.flatMap(i=>
1i?.data?.records||[]).filter(Boolean)||[];return(0,l.useEffect)(()=>{const i=new IntersectionObserver(F=>{F[0].isIntersecting&&m&&!n&&r()},{threshold:.1}),u=t.current;return u&&i.observe(u),()=>{u&&i.unobserve(u)}},[m,n,r]),p?(0,e.jsx)("div",{className:"flex max-h-[500px] flex-col gap-4 overflow-y-auto",children:[1,2,3].map(i=>(0,e.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,e.jsx)(M,{className:"h-4 w-3/4"}),(0,e.jsx)(M,{className:"h-5 w-full"})]},i))}):j?(0,e.jsx)("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:a("locationDrawer.faqLoadError")||"Failed to load FAQ"}):d.length===0?(0,e.jsx)("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:a("locationDrawer.faqNoData")||"No FAQ available"}):(0,e.jsxs)("div",{className:"flex max-h-[500px] flex-col gap-4 overflow-y-auto",children:[d.map(i=>(0,e.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,e.jsx)("p",{className:"text-sm font-medium leading-none text-[#4a5565]",children:i.questionTitle}),(0,e.jsx)("p",{className:"text-sm font-normal leading-5 text-[#19191a]",children:i.answerContent})]},i.id)),m&&(0,e.jsx)("div",{ref:t,className:"flex justify-center py-2",children:n&&(0,e.jsx)("div",{className:"text-sm text-muted-foreground",children:a("locationDrawer.faqLoadingMore")||"Loading more..."})})]})}var ce=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],L=s=>s&&s.trim()?s:"-",gs=s=>{if(!s)return null;if(Array.isArray(s))return s;if(typeof s=="string")try{return JSON.parse(s)}catch(a){return console.error("Failed to parse daysOfWeek:",a),null}return null},ps=s=>!s||s.length===0?ce.map(a=>({day:a,hours:"Closed"})):ce.map(a=>{const t=s.find(r=>r.week===a);if(!t||t.status==="Closed")return{day:a,hours:"Closed"};const g=t.timeRanges.map(r=>`${r.startTime} - ${r.endTime}`).join(", ");return{day:a,hours:g||"Closed"}});function hs({locationId:s}){const{t:a}=U("voiceAgent"),{data:t,isLoading:g}=ne({queryKey:["location",s],queryFn:()=>ee.getLocationById(s),enabled:!!s}),{data:r,isLoading:m}=ne({queryKey:["call-transfer",s],queryFn:async()=>{const d=await ee.getCallTransferByLocationId(s);return d.retCode!=="000000"?null:d},enabled:!!s,retry:!1}),n=t?.data,p=gs(n?.daysOfWeek),j=r?.data?.transferMessage;return(0,e.jsx)("div",{className:"w-full",children:g?(0,e.jsxs)("div",{className:"flex flex-col gap-0 w-full",children:[(0,e.jsx)("div",{className:"border-b border-border",children:(0,e.jsx)("div",{className:"flex items-center justify-between py-4",children:(0,e.jsx)(M,{className:"h-6 w-40"})})}),(0,e.jsx)("div",{className:"border-b border-border",children:(0,e.jsx)("div",{className:"flex items-center justify-between py-4",children:(0,e.jsx)(M,{className:"h-6 w-16"})})}),(0,e.jsx)("div",{className:"border-b border-border",children:(0,e.jsx)("div",{className:"flex items-center justify-between py-4",children:(0,e.jsx)(M,{className:"h-6 w-12"})})}),(0,e.jsx)("div",{className:"border-b border-border",children:(0,e.jsx)("div",{className:"flex items-center justify-between py-4",children:(0,e.jsx)(M,{className:"h-6 w-32"})})})]}):n?(0,e.jsxs)(ms,{type:"single",collapsible:!0,className:"w-full",children:[(0,e.jsxs)(q,{value:"location-settings",className:"border-border",children:[(0,e.jsx)(O,{className:"py-4 text-base font-medium leading-6 text-foreground hover:no-underline",children:a("locationDrawer.locationSettings")}),(0,e.jsxs)(H,{className:"flex flex-col gap-4 pb-4",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-[#4a5565]",children:a("locationDrawer.locationName")}),(0,e.jsx)("p",{className:"text-base font-normal leading-6 text-[#19191a]",children:L(n.displayName)})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-[#4a5565]",children:a("locationDrawer.address")}),(0,e.jsx)("p",{className:"text-base font-normal leading-6 text-[#19191a]",children:L(n.address)})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-[#4a5565]",children:a("locationDrawer.timeZone")}),(0,e.jsx)("p",{className:"text-base font-normal leading-6 text-[#19191a]",children:L(n.timeZone)})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-[#4a5565]",children:a("locationDrawer.businessHours")}),(0,e.jsx)("div",{className:"text-base font-normal leading-6 text-[#19191a]",children:p===null?(0,e.jsx)("p",{className:"mb-0",children:a("locationDrawer.allDay")}):p&&p.length>0?ps(p).map((d,i)=>(0,e.jsxs)("p",{className:"mb-0",children:[d.day,": ",L(d.hours)]},i)):(0,e.jsx)("p",{className:"mb-0",children:"-"})})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-[#4a5565]",children:a("locationDrawer.fulfillmentOptions")}),(0,e.jsx)("p",{className:"text-base font-normal leading-6 text-[#19191a]",children:L(Array.isArray(n.deliveryMethod)?n.deliveryMethod.join(", "):n.deliveryMethod)})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-[#4a5565]",children:a("locationDrawer.paymentMethods")}),(0,e.jsx)("p",{className:"text-base font-normal leading-6 text-[rgba(0,0,0,0.8)]",children:L(Array.isArray(n.paymentMethod)?n.paymentMethod.join(", "):n.paymentMethod)})]})]})]}),(0,e.jsxs)(q,{value:"menu",className:"border-border",children:[(0,e.jsx)(O,{className:"py-4 text-base font-medium leading-6 text-foreground hover:no-underline",children:a("locationDrawer.menu")}),(0,e.jsxs)(H,{className:"flex flex-col gap-2 pb-4",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-[#4a5565]",children:a("locationDrawer.menuLink")||"Menu Link"}),(0,e.jsx)("div",{className:"w-full",children:(0,e.jsx)(Ke,{className:`text-sm font-normal leading-5 text-[#19191a] ${n.menuLink&&n.menuLink!=="-"&&n.menuLink.trim()?"underline decoration-solid underline-offset-auto cursor-pointer":""}`,onClick:()=>{n.menuLink&&n.menuLink!=="-"&&n.menuLink.trim()&&window.open(n.menuLink,"_blank")},children:L(n.menuLink)})})]})]}),(0,e.jsxs)(q,{value:"faq",className:"border-border",children:[(0,e.jsx)(O,{className:"py-4 text-base font-medium leading-6 text-foreground hover:no-underline",children:a("locationDrawer.faq")}),(0,e.jsx)(H,{className:"pb-4",children:(0,e.jsx)(fs,{locationId:s})})]}),(0,e.jsxs)(q,{value:"call-transfer",className:"border-border",children:[(0,e.jsx)(O,{className:"py-4 text-base font-medium leading-6 text-foreground hover:no-underline",children:a("locationDrawer.callTransfer")}),(0,e.jsx)(H,{className:"flex flex-col gap-2 pb-4",children:m?(0,e.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,e.jsx)(M,{className:"h-4 w-28"}),(0,e.jsx)(M,{className:"h-5 w-full"})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-[#4a5565]",children:a("locationDrawer.transferMessage")}),(0,e.jsx)("p",{className:"text-sm font-normal leading-5 text-[#19191a]",children:L(j)})]})})]})]}):(0,e.jsx)("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:a("locationDrawer.noLocationData")||"No location data available"})})}function js(s={}){const{onError:a,getErrorMessage:t}=s,[g,r]=(0,l.useState)(null),m=(0,l.useRef)(null),n=(0,l.useCallback)(()=>{m.current&&(m.current.pause(),m.current.currentTime=0,m.current=null),r(null)},[]),p=(0,l.useCallback)(j=>{if(g===j&&m.current){n();return}n();const d=new Audio(rs[j]);m.current=d,d.addEventListener("ended",()=>{r(null),m.current=null}),d.addEventListener("error",()=>{const i=new Error(`Failed to play audio for voice: ${j}`);a?a(i):t&&N.error(t()),r(null),m.current=null}),d.play().then(()=>{r(j)}).catch(i=>{console.error("Error playing audio:",i);const u=new Error(`Failed to play audio for voice: ${j}`);a?a(u):t&&N.error(t()),r(null),m.current=null})},[g,n,a,t]);return(0,l.useEffect)(()=>()=>{n()},[n]),{playingVoice:g,playVoice:p,stopVoice:n}}function bs({botId:s,onBotDataLoaded:a}){const{t}=U("voiceAgent"),[g,r]=(0,l.useState)(!0),[m,n]=(0,l.useState)(!1),[p,j]=(0,l.useState)(null),[d,i]=(0,l.useState)(null),{playingVoice:u,playVoice:F}=js({getErrorMessage:()=>t("testFlow.audioPlayFailed")}),[w,k]=(0,l.useState)(!1),f=Ee({defaultValues:{voiceCode:"marin",speakingSpeed:1,volume:50,greetingMessage:""}}),C=Ye,J={.75:t("testFlow.slower"),.9:t("testFlow.slightlySlower"),1:t("testFlow.normal"),1.1:t("testFlow.slightlyFaster"),1.25:t("testFlow.faster"),1.5:t("testFlow.muchFaster")},R=o=>C.reduce((c,b)=>Math.abs(b-o)<Math.abs(c-o)?b:c);(0,l.useEffect)(()=>{(async()=>
1{if(s){r(!0);try{const[c,b]=await Promise.all([_.getBot(s),_.getBotConfig(s)]);c.retCode==="000000"?(j(c.data),a?.(c.data),f.reset({voiceCode:b.data.voiceCode||"marin",speakingSpeed:R(b.data.voiceSpeed||1),volume:b.data.voiceVolume||50,greetingMessage:c.data.welcomeText||""})):(console.error("Failed to fetch bot data:",c.retMsg),N.error(c.retMsg||t("testFlow.loadBotFailed"))),b.retCode==="000000"&&i(b.data)}catch(c){console.error("Error fetching bot data:",c),N.error(t("testFlow.loadBotFailed"))}finally{r(!1)}}})()},[s]);const T=async()=>{if(!s||!p)return;const o=f.getValues();if(!o.greetingMessage){N.error(t("testFlow.greetingRequired"));return}n(!0);try{const c=await _.updateBot(s,{welcomeText:o.greetingMessage});if(c.retCode!=="000000"){N.error(c.retMsg||t("testFlow.saveFailed"));return}const b=await _.patchBotConfig(s,{voiceCode:o.voiceCode,voiceSpeed:o.speakingSpeed,voiceVolume:o.volume});b.retCode==="000000"?(N.success(t("testFlow.saveSuccess")),j(c.data),i(b.data),f.reset(o),a?.(c.data)):N.error(b.retMsg||t("testFlow.saveFailed"))}catch(c){console.error("Error saving configuration:",c),N.error(t("testFlow.saveFailed"))}finally{n(!1)}},G=()=>{p&&d&&f.reset({voiceCode:d.voiceCode,speakingSpeed:R(d.voiceSpeed),volume:d.voiceVolume,greetingMessage:p.welcomeText||""})},D=f.formState.isDirty,v=D&&!m&&!g,I=D&&!m&&!g,P=(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mb-6",children:(0,e.jsxs)("div",{className:"flex items-start justify-between gap-1.5 h-5",children:[(0,e.jsx)("h3",{className:"text-lg font-semibold leading-none tracking-[-0.45px]",children:t("testFlow.agentConfigTitle")}),D&&(0,e.jsx)("div",{className:"inline-flex items-center justify-center gap-1 rounded-3xl bg-[#fff2ca] px-2 py-0.5",children:(0,e.jsx)("span",{className:"text-[12px] font-semibold leading-4 text-[#19191a]",children:t("testFlow.unsavedChanges")})})]})}),(0,e.jsx)("div",{className:"flex flex-col gap-8 pb-0",children:(0,e.jsxs)("form",{className:"flex flex-col gap-8",onSubmit:o=>{o.preventDefault(),T()},children:[(0,e.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,e.jsx)("div",{className:"flex flex-col gap-1",children:(0,e.jsx)("p",{className:"text-sm font-medium leading-5 text-primary",children:t("testFlow.voice")})}),(0,e.jsx)(W,{control:f.control,name:"voiceCode",render:({field:o})=>(0,e.jsxs)(K,{className:"flex flex-col gap-2",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-none text-muted-foreground",children:t("testFlow.voiceLabel")}),(0,e.jsxs)(as,{open:w,onOpenChange:k,children:[(0,e.jsx)($e,{asChild:!0,children:(0,e.jsx)(Z,{children:(0,e.jsxs)("button",{type:"button",role:"combobox","aria-expanded":w,className:y("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-xl border border-input bg-white px-3 py-2 text-sm shadow-sm ring-offset-background focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50"),children:[(0,e.jsx)("span",{className:"capitalize",children:o.value}),(0,e.jsx)(ue,{className:"h-4 w-4 opacity-50"})]})})}),(0,e.jsx)(Xe,{className:"w-[--radix-popover-trigger-width] p-1",align:"start",children:(0,e.jsx)("div",{className:"flex flex-col max-h-[350px] overflow-y-auto",children:We.map(c=>(0,e.jsxs)("div",{className:y("relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground",o.value===c&&"bg-accent"),onClick:()=>{o.onChange(c),k(!1)},children:[(0,e.jsx)("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-3xl border border-input bg-white shadow-sm hover:bg-gray-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:b=>{b.stopPropagation(),F(c)},children:u===c?(0,e.jsx)(ye,{className:"h-4 w-4"}):(0,e.jsx)(X,{className:"h-4 w-4"})}),(0,e.jsx)("span",{className:"flex-1 capitalize",children:c}),o.value===c&&(0,e.jsx)(Le,{className:"h-4 w-4"})]},c))})})]}),(0,e.jsx)(Q,{className:"text-xs"})]})}),(0,e.jsx)(W,{control:f.control,name:"speakingSpeed",render:({field:o})=>(0,e.jsxs)(K,{className:"flex flex-col gap-4",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-muted-foreground",children:t("testFlow.speakingSpeed")}),(0,e.jsxs)("p",{className:"text-sm font-medium leading-5 text-primary",children:[o.value,"× (",J[o.value]||t("testFlow.normal"),")"]})]}),(0,e.jsx)(Z,{children:(0,e.jsx)(ie,{value:[C.indexOf(o.value)],onValueChange:c=>{const b=C[c[0]];o.onChange(b)},min:0,max:C.length-1,step:1,className:"w-full"})}),(0,e.jsx)(Q,{className:"text-xs"})]})}),(0,e.jsx)(W,{control:f.control,name:"volume",render:({field:o})=>(0,e.jsxs)(K,{className:"flex flex-col gap-4",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("p",{className:"text-xs font-medium leading-4 text-muted-foreground",children:t("testFlow.volume")}),(0,e.jsxs)("p",{className:"text-sm font-medium leading-5 text-primary",children:[o.value,"/10"]})]}),(0,e.jsx)(Z,{children:(0,e.jsx)(ie,{value:[o.value],onValueChange:c=>o.onChange(c[0]),min:0,max:10,step:1,className:"w-full"})}),(0,e.jsx)(Q,{className:"text-xs"})]})})]}),(0,e.jsx)(W,{control:f.control,name:"greetingMessage",render:({field:o})=>(0,e.jsxs)(K,{className:"flex flex-col gap-3",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,e.jsx)("p",{className:"text-sm font-medium leading-5 text-primary",children:t("testFlow.greetingMessage")}),(0,e.jsx)("p",{className:"text-xs leading-4 tracking-[0.12px] text-secondary-foreground",children:t("testFlow.greetingDescription")})]}),(0,e.jsx)(Z,{children:(0,e.jsx)(ns,{placeholder:t("testFlow.greetingPlaceholder"),...o,className:"h-20 resize-y rounded-xl border-input bg-white text-sm",maxLength:1e3})}),(0,e.jsx)(Q,{className:"text-xs"})]})})]})}),(0,e.jsxs)("div",{className:"flex gap-2 mt-6",children:[(0,e.jsxs)($,{type:"button",onClick:G,variant:"ghost",className:y("flex-1 gap-2 rounded-3xl bg-background border border-transparent",!v&&"border-dashed border-input"),disabled:!v,children:[(0,e.jsx)(Fe,{className:y("h-4 w-4",v?"text-[#19191a]":"text-[#19191a]/40")}),(0,e.jsx)("span",{className:y("text-sm font-medium",v?"text-[#19191a]":"text-[#19191a]/50"),children:t("testFlow.discardChanges")}
1)]}),(0,e.jsxs)($,{type:"submit",formAction:"submit",onClick:o=>{o.preventDefault(),T()},variant:"outline",className:"flex-1 gap-2 rounded-3xl border-input bg-white",disabled:!I,children:[(0,e.jsx)(Oe,{className:y("h-4 w-4",I?"text-[#19191a]":"text-[#19191a]/40")}),(0,e.jsx)("span",{className:y("text-sm font-medium",I?"text-[#19191a]":"text-[#19191a]/50"),children:t(m?"testFlow.saving":"testFlow.saveAndApply")})]})]})]});return(0,e.jsx)(is,{...f,children:P})}var de=[26.514,17.734,38.135,27.51,29.727,10.205,16.045,10.43,10,10.527,12.861,9.365,7.793,12.227,26.875,20.938,23.203,10.869,11.465,10.664,9.99,10.986,10.313,16.328,22.568,31.094,29.492,22.471,25.625,24.365],E=null;function ks(){const{t:s}=U("voiceAgent"),a=Te(),{id:t}=Be(),[g]=Re(),r=g.get("locationId")||"",{language:m,timezone:n}=Qe(),[p,j]=(0,l.useState)(!1),[d,i]=(0,l.useState)(null),[u,F]=(0,l.useState)(!1),[w,k]=(0,l.useState)(!1),[f,C]=(0,l.useState)(!1),[J,R]=(0,l.useState)(de),[T,G]=(0,l.useState)([]),D=(0,l.useRef)(null),v=(0,l.useRef)(null),I=(0,l.useRef)(null),P=(0,l.useRef)([]),o=(0,l.useRef)(!1),c=x=>{const h=new Date(x),S=Ze[m].locale;return h.toLocaleTimeString(S,{hour:"2-digit",minute:"2-digit",second:"2-digit",timeZone:n,hour12:!1})},b=()=>{a(r?oe.LOCATION_DETAIL.replace(":id",r):oe.VOICE_AGENT_DETAIL.replace(":id",t||""))},se=(0,l.useCallback)(()=>{const x=window.location.hostname,h=d?.companyId||"",S=`wss://${x}/opensips`;console.log("config",S,`sip:${h}@public.tunvo.ai`),E=new He(S,`sip:${h}@public.tunvo.ai`,()=>{},()=>{console.log("服务器挂断电话"),o.current||(F(!1),k(!1),N.error(s("testFlow.serverDisconnected")),P.current.length>0&&C(!0)),o.current=!1},()=>{console.log("媒体建立成功"),k(!1),F(!0)})},[d?.companyId,s]),ge=()=>{j(!0)},pe=()=>{console.log("Feedback sent successfully")},he=async x=>{v.current&&v.current.abort(),v.current=await _.sseDialogue(x,h=>{console.log("SSE message received:",h);const S=h;if(S?.type==="data"&&S?.content){const A=S.content;A.dialogueRole&&A.dialogueText&&A.contentId&&G(B=>{if(B.some(V=>V.contentId===A.contentId))return B;const z=[...B,A].sort((V,Y)=>V.startTime-Y.startTime);return P.current=z,z})}},h=>{console.error("SSE error:",h),N.error(s("testFlow.sseConnectionError")||"SSE connection error")})},je=async()=>{if(E){o.current=!0;try{await E.hangup()}catch(x){console.error("Error hanging up call:",x),N.error(s("testFlow.endCallError")||"Failed to end call")}finally{F(!1),T.length>0&&C(!0)}}},te=async()=>{if(!d?.id||!E){N.error(s("testFlow.callInitError"));return}if(!u&&!w){G([]),P.current=[],C(!1),k(!0),console.log("botData?.id",d?.id);try{const x=await E.makeCall(d?.id);he(x)}catch(x){N.error(s("testFlow.startCallError")),console.error("Error starting call:",x),k(!1)}}else je()};return(0,l.useEffect)(()=>{d?.companyId&&se()},[d,se]),(0,l.useEffect)(()=>()=>{console.log("leave page",v.current,E),v.current&&(v.current.abort(),v.current=null),E&&(o.current=!0,console.log("离开页面挂断通话"),E.hangup().catch(x=>{console.error("Error hanging up call on unmount:",x)}),E=null)},[]),(0,l.useEffect)(()=>{I.current?.scrollIntoView({behavior:"smooth"})},[T]),(0,l.useEffect)(()=>{if(!u){R(de),D.current&&cancelAnimationFrame(D.current),v.current&&(v.current.abort(),v.current=null);return}let x=Date.now();const h=100,S=()=>{const A=Date.now();A-x>=h&&(R(B=>B.map(z=>{const V=(Math.random()-.5)*15,Y=8,be=45,Ne=z+V;return Math.max(Y,Math.min(be,Ne))})),x=A),D.current=requestAnimationFrame(S)};return D.current=requestAnimationFrame(S),()=>{D.current&&cancelAnimationFrame(D.current)}},[u]),(0,e.jsxs)(ts,{children:[(0,e.jsx)(ls,{title:s("testFlow.title"),showBackButton:!0,onBack:b,actions:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)($,{variant:"outline",onClick:ge,className:"h-9 gap-2 rounded-3xl border-[#d1d5dc] bg-white px-4 py-2",children:[(0,e.jsx)(_e,{className:"h-4 w-4"}),(0,e.jsx)("span",{className:"text-sm font-medium",children:s("testFlow.sendFeedback")})]}),(0,e.jsxs)($,{onClick:te,disabled:w,className:y("h-9 gap-2 rounded-3xl px-4 py-2 shadow-sm",u?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-[#19191a] text-white hover:bg-[#19191a]/90"),children:[u?(0,e.jsx)(Ie,{className:"h-4 w-4"}):(0,e.jsx)(X,{className:"h-4 w-4"}),(0,e.jsx)("span",{className:"text-sm font-medium",children:s(u?"testFlow.endSession":"testFlow.startSession")})]})]})}),(0,e.jsx)(ze,{children:(0,e.jsxs)("div",{className:"flex h-[calc(100vh-128px)] gap-6 items-start",children:[(0,e.jsxs)(re,{className:"flex flex-1 flex-col border-border h-full overflow-hidden",children:[(0,e.jsx)(ss,{className:"p-6 shrink-0",children:(0,e.jsxs)("div",{className:"flex items-start justify-between gap-1.5",children:[(0,e.jsx)(Ge,{className:"text-lg font-semibold leading-none tracking-[-0.45px]",children:s(w?"testFlow.connecting":"testFlow.liveTranscription")}),!w&&T.length>0&&(0,e.jsxs)(Je,{variant:"outline",className:"gap-1 rounded-3xl border-border px-2 py-0.5",children:[(0,e.jsx)(ve,{className:"h-3 w-3"}),(0,e.jsx)("span",{className:"text-xs font-semibold",children:s("testFlow.messages",{count:T.length})})]})]})}),(0,e.jsxs)(le,{className:"flex flex-1 flex-col gap-6 overflow-hidden pb-8 pt-3",children:[(u||w)&&!f&&(0,e.jsx)("div",{className:y("flex h-20 shrink-0 items-center justify-center gap-1 rounded-xl px-0",w?"bg-gray-100":"bg-[#e6ffce]"),children:w?(0,e.jsx)(ae,{className:"h-8 w-8 animate-spin text-gray-400"}):J.map((x,h)=>(0,e.jsx)("div",{className:"w-1 rounded-md bg-primary transition-all duration-100 ease-in-out",style:{height:`${x}px`}},h))}),(0,e.jsx)("div",{className:"flex flex-1 flex-col gap-6 overflow-auto",children:!u&&!w&&!f?(0,e.jsxs)("div",{className:"flex flex-col items-center gap-6 pt-3",children:[(0,e.jsx)("div",{className:"flex items-center justify-center py-[26px]",children:(0,e.jsx)("img",{src:ds,alt:"Voice Agent",className:"w-[166px] h-[134px]"})}),(0,e.jsxs)("div",{className:"flex flex-col items-center gap-1.5 text-center text-muted-foreground w-full",children:[(0,e.jsx)("p",{className:"text-lg font-semibold leading-none tracking-[-0.45px] w-full min-w-full",children:s("testFlow.noActiveCall")}),(0,e.jsx)("p",{className:"text-sm font-normal leading-5 w-[360px]",children:s("testFlow.noActiveCallDescription")})]}),(0,e.jsxs)($,{onClick:te,variant:"outline",className:"h-9 gap-2 rounded-3xl border-input bg-white px-4 py-2",children:[(0,e.jsx)(X,{className:"h-4 w-4"}),(0,e.jsx)("span",{className:"text-sm font-medium",children:s("testFlow.startSession")})]})]}):w?(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center gap-3 pt-20",children:[(0,e.jsx)(ae,{className:"h-8 w-8 animate-spin text-gray-400"}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground",children:s("testFlow.establishingConnection")})]}):(0,e.jsxs)("div",{className:"flex flex-col gap-6",children:[f&&(0,e.jsxs)("div",{className:"flex items-start gap-3 rounded-xl border border-border bg-[#e6ffce] p-4",children:[(0,e.jsx)("div",{className:"flex flex-col items-center justify-center pb-0 pt-0.5",children:(0,e.jsx)(qe,{className:"h-4 w-4"})}),(0,e.jsx)("p",{className:"flex-1 text-sm leading-5 text-primary",children:s("testFlow.callCompletedMessage")})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-4",children:[T.map(x=>{const h=x.dialogueRole==="USER";return(0,e.jsxs)("div",{className:y("flex flex-col gap-2",h?"items-end":"items-start"),children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("span",{className:"text-xs font-semibold text-secondary-foreground",children:s(h?"testFlow.you":"testFlow.agent")}),(0,e.jsx)("span",{className:"text-xs text-secondary-foreground tracking-[0.12px]",children:c(x.startTime)})]}),(0,e.jsxs)("div",{className:y("flex items-end gap-2",h?"flex-row-reverse":"flex-row"),children:[(0,e.jsx)("div",{className:y("roun
1ded-2xl px-4 py-2 max-w-[624px]",h?"bg-primary text-primary-foreground":"bg-muted text-primary"),children:(0,e.jsx)("p",{className:"text-sm leading-5 break-words",children:x.dialogueText})}),!h&&(0,e.jsx)(es,{data:{contentId:x.contentId,dialogueId:null,childId:null,startTimeOffset:null,startTime:x.startTime,dialogueRole:x.dialogueRole,agentType:null,dialogueText:x.dialogueText,callID:x.callID,callCode:null,dialogueStage:null,mainAgentCallDetailId:null,dialogueStartTime:null,tenantId:null,enterpriseId:null,agentId:null,agentCode:null,agentName:null,agentExt:null,agentVersion:null,ratingType:null},size:"sm",enableDislikeFeedback:!0})]})]},x.contentId)}),(0,e.jsx)("div",{ref:I})]})]})})]})]}),(0,e.jsx)(re,{className:"w-[400px] shrink-0 border-border h-full flex flex-col overflow-hidden",children:(0,e.jsx)(le,{className:"flex-1 overflow-auto p-6",children:(0,e.jsx)(Ue,{defaultActiveKey:"agentSettings",items:[{key:"agentSettings",label:s("testFlow.agentSettingsTab"),icon:Ae,children:t?(0,e.jsx)(bs,{botId:t,onBotDataLoaded:x=>i(x)}):null},{key:"locationInfo",label:s("testFlow.locationInfoTab"),icon:we,children:(0,e.jsx)(hs,{locationId:r})}],tabsListClassName:"w-full justify-start"})})})]})}),(0,e.jsx)(xs,{open:p,onOpenChange:j,onSuccess:pe,botCode:d?.botCode||""})]})}export{ks 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.