PageSourceSearch

https://safetyportal.hippocraticai.com/assets/RomeRoutes-rj4F9kpO.js

js hippocraticai.com collected 2026-09-24 19:28:58 UTC 70,398 bytes, 2 lines download raw bytes

1import{t as Et,j as e,ao as Dt,r as o,bN as Be,a7 as d,I as i,P as B,an as w,bB as lt,aM as M,aL as A,a1 as at,a2 as ot,cq as Tt,aq as tt,ay as Je,ba as is,bR as st,c4 as nt,aO as ls,aP as as,aQ as os,a8 as He,aR as cs,aY as z,c3 as ds,aA as xs,az as us,aD as hs,cI as ps,b3 as At,br as zt,cN as Wt,cO as Lt,fx as ms,c5 as gs,f9 as Ot,dm as St,fs as vt,dp as Ct,y as fs,cz as js,aa as ys,j1 as bs,hk as Ss,aw as _t,j2 as vs,cc as Cs,b6 as pe,aU as Oe}from"./index-C2WJVl_t.js";import{u as _s,g as ct,a as Is,q as ws,r as It,k as O,j as Se,h as le,S as ve,l as Rs,m as ks,b as Ps,n as Es,s as $t,t as Ue,C as Ds,d as Ts,v as As,w as zs,x as Ws,y as Ls}from"./UpdateLoopView-BGlp9hbZ.js";import{i as Os,F as Fe,G as dt,g as xt,D as $s,n as Ms}from"./UseCaseProjectApi-g6ctHjbk.js";import{b as Ns,c as Us,a as wt,u as Fs}from"./useSimulateCalls-CdNgluES.js";import{T as Pe,b as Ee,c as De,d as H,e as g,f as Te,F as ut,v as Hs,M as Me,s as Mt,L as $e,j as Ve,D as Ne,t as Gs,aI as Nt,k as ht,I as Vs,J as Bs}from"./RootRoute.app-B_s1x8ur.js";import{T as pt}from"./ActionButton-gCV94Y2c.js";import{d as mt}from"./FilterDropdown-DGRJGlQk.js";import{d as qs}from"./Edit-68BGXfB3.js";import{d as gt,u as Js}from"./PlayArrow-D50Qy2On.js";import{b as Ks}from"./useCallManager-Ce8HkSWC.js";import{u as Xs}from"./DemoPatientApi-xHdEgLUz.js";import{C as Ys,m as Qs}from"./CallChat-D7DTzxY_.js";import{d as Zs}from"./Error-Ch5QpX2S.js";import{d as ft}from"./Download-eyf8ZqR_.js";import{F as en,C as ue}from"./FormControlLabel-BvMsS3hp.js";import{L as tn}from"./LinearProgress-dtrWeDkV.js";import{d as Ut}from"./SearchScriptDropdown-DOw-dDRW.js";import{c as Ft,d as sn,b as nn}from"./Add-W8C4Xlk4.js";import{bm as rn}from"./ChatPanel-DBO39OvP.js";import{o as ln,l as an}from"./KeyboardArrowDown-DzFsW3Ql.js";import{ad as on,ae as cn}from"./switch-BRIQFP0b.js";import{u as Ht}from"./useCallDetailsPath-C4eCgHO8.js";import{T as Gt,a as qe}from"./ScriptUtils-hDRpGhAb.js";import{A as Vt,a as Bt,b as qt}from"./scriptLabelUtils-k7czAEb9.js";import{L as Jt}from"./Link-BJLdNiN5.js";import"./DeleteOutline-CHCbOCMj.js";import"./AgentUtils-BrGhRKwH.js";import"./react-hotkeys-hook.esm-ib2Yc6ry.js";import"./dropdown-menu-ByworIRv.js";import"./useAudioPlayback-8Uw8a6ia.js";import"./BarShortDetailsEntry-3Q8w2ErW.js";import"./Grid-BAFDPprV.js";import"./CallDialerSetup-DnnMaXhx.js";import"./cjs-BjlvWOJc.js";import"./CodeEditor-Djk-aKC_.js";import"./PatientRecordCard-DOEUVMUg.js";import"./CallErrorDialog-BZaTLApW.js";import"./CardContent-54BmL5uC.js";import"./Warning-CWIR8DNt.js";import"./alert-dialog-mPpilYwJ.js";import"./CallDevCopyButtons-BMBjuG-L.js";import"./OpenInNew-BQhe6EG4.js";import"./CallDevSettingsDialog-BxEBUrM5.js";import"./Switch-B0Jt7WU4.js";import"./index-C7U254AI.js";import"./SearchAgentDropdown-Bfe_jPMl.js";import"./CallSettingsApi-h0YlI9zn.js";import"./AdditionalQuestionsEditor-axiRwo2E.js";import"./CallDialerFloating-CuBi1Ete.js";import"./ExpandLess-CEOChHRu.js";import"./SimpleSelect-JizwBQRT.js";import"./Slider-CVhxIR0k.js";import"./LanguageTypes-B_iKtSAt.js";import"./FormInputMultipleChoice-BbeHnFuh.js";import"./FormInputSlider-CXd50T3v.js";import"./FormInputSingleChoice-CeeghCqs.js";import"./RadioGroup-BmcvLBZb.js";import"./Radio-Mujbk6If.js";import"./FormGroup-cMorNr1e.js";import"./TodoConstants-BGFfQgC0.js";import"./Check-DyR0B_El.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},l=new Error().stack;l&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[l]="7149a829-2034-4ade-aca3-5d3fed200403",t._sentryDebugIdIdentifier="sentry-dbid-7149a829-2034-4ade-aca3-5d3fed200403")}catch{}})();const dn=Et(e.jsx("path",{d:"m12 8-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z"}),"ExpandLess"),Rt=Et(e.jsx("path",{d:"M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"}),"ExpandMore"),kt=()=>{var R,q;const t=Dt(),l=_s(),[s,c]=o.useState(0),[r,n]=o.useState(100),[u,a]=o.useState(!1),{data:h,isLoading:b}=Os({limit:r,offset:s*r}),y=(j,E)=>{c(E)},m=j=>{const E=parseInt(j.target.value,10);n(E),c(0)},S=async j=>{var C,X;let E;if(Fe(j))try{a(!0),E=((X=(C=(await dt(j.use_case_project_id)).usecaseProject)==null?void 0:C.script)==null?void 0:X.parentEntityId)??void 0}finally{a(!1)}else E=ct(j);t("/rome/session",{state:{scriptId:E,useCaseProjectId:j.use_case_project_id}})},v=j=>new Date(j).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsx(Be,{fullWidth:!0,children:e.jsxs(d,{sx:{p:2,maxWidth:1200,mx:"auto",fontSize:"0.875rem"},children:[e.jsx(i,{variant:"subtitle1",fontWeight:600,gutterBottom:!0,children:"Getting Started"}),e.jsx(i,{variant:"caption",color:"text.secondary",sx:{mb:2,display:"block"},children:"Select a use case project below to begin."}),e.jsxs(B,{sx:{p:2,mb:2,bgcolor:"primary.50",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(d,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:l&&e.jsx(w,{variant:"contained",size:"small",onClick:()=>t("/rome/scope"),sx:{bgcolor:"#7BC766","&:hover":{bgcolor:"#6ab557"},fontWeight:600},children:"✦ Guided Agent Builder"})}),e.jsx(w,{component:lt,to:"/sp/tools/script-editor",variant:"contained",color:"primary",children:"Manage Use Case Projects"})]}),e.jsxs(B,{sx:{p:2},children:[e.jsx(i,{variant:"body2",fontWeight:500,sx:{mb:1},children:"Available Projects"}),b||u?e.jsx(d,{sx:{display:"flex",justifyContent:"center",py:3},children:e.jsx(M,{size:24})}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:e.jsxs(Ee,{size:"small",children:[e.jsx(De,{children:e.jsxs(H,{
1children:[e.jsx(g,{sx:{fontSize:"0.75rem",py:1},children:"Name"}),e.jsx(g,{sx:{fontSize:"0.75rem",py:1,minWidth:320},children:"Project ID"}),e.jsx(g,{sx:{fontSize:"0.75rem",py:1},children:"Review Status"}),e.jsx(g,{sx:{fontSize:"0.75rem",py:1},children:"Version"}),e.jsx(g,{sx:{fontSize:"0.75rem",py:1},children:"Created"}),e.jsx(g,{sx:{fontSize:"0.75rem",py:1},align:"right",children:"Action"})]})}),e.jsxs(Te,{children:[(R=h==null?void 0:h.use_case_projects)==null?void 0:R.map(j=>e.jsxs(H,{hover:!0,sx:{cursor:"pointer"},onClick:()=>S(j),children:[e.jsx(g,{sx:{fontSize:"0.75rem",py:.75},children:j.name}),e.jsx(g,{sx:{py:.75},children:e.jsx(i,{variant:"body2",sx:{fontFamily:"monospace",fontSize:"0.7rem"},children:j.use_case_project_id})}),e.jsx(g,{sx:{fontSize:"0.75rem",py:.75},children:e.jsx(A,{label:Us[j.review_status||wt.DRAFT],color:Ns[j.review_status||wt.DRAFT],size:"small"})}),e.jsx(g,{sx:{fontSize:"0.75rem",py:.75},children:Fe(j)?"V2":"V1"}),e.jsx(g,{sx:{fontSize:"0.75rem",py:.75},children:j.created_at?v(j.created_at):"N/A"}),e.jsx(g,{sx:{py:.75},align:"right",children:e.jsx(w,{size:"small",variant:"text",sx:{fontSize:"0.7rem",minWidth:"auto",p:.5},onClick:E=>{E.stopPropagation(),S(j)},children:"Select"})})]},j.use_case_project_id)),((q=h==null?void 0:h.use_case_projects)==null?void 0:q.length)===0&&e.jsx(H,{children:e.jsx(g,{colSpan:6,align:"center",children:e.jsx(i,{variant:"caption",color:"text.secondary",sx:{py:1},children:"No projects found"})})})]})]})}),e.jsx(pt,{component:"div",count:(h==null?void 0:h.total_count)||0,page:s,onPageChange:y,rowsPerPage:r,onRowsPerPageChange:m,rowsPerPageOptions:[5,10,25,50],sx:{"& .MuiTablePagination-selectLabel, & .MuiTablePagination-displayedRows":{fontSize:"0.75rem"}}})]})]})]})})};var jt={},xn=at;Object.defineProperty(jt,"__esModule",{value:!0});var rt=jt.default=void 0,un=xn(ot()),hn=e,pn=(0,un.default)((0,hn.jsx)("path",{d:"M6 2v6h.01L6 8.01 10 12l-4 4 .01.01H6V22h12v-5.99h-.01L18 16l-4-4 4-3.99-.01-.01H18V2H6zm10 14.5V20H8v-3.5l4-4 4 4zm-4-5-4-4V4h8v3.5l-4 4z"}),"HourglassEmpty");rt=jt.default=pn;var yt={},mn=at;Object.defineProperty(yt,"__esModule",{value:!0});var it=yt.default=void 0,gn=mn(ot()),fn=e,jn=(0,gn.default)((0,fn.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zM9.5 16.5v-9l7 4.5-7 4.5z"}),"PlayCircle");it=yt.default=jn;var bt={},yn=at;Object.defineProperty(bt,"__esModule",{value:!0});var Kt=bt.default=void 0,bn=yn(ot()),Sn=e,vn=(0,bn.default)((0,Sn.jsx)("path",{d:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"}),"Visibility");Kt=bt.default=vn;const Cn=({results:t})=>{const[l,s]=o.useState(null),{data:c,isLoading:r}=Tt(l||void 0,{includeCallUtterances:!0},{retry:!1});if(t.length===0)return null;const n=()=>{const m={exportedAt:new Date().toISOString(),summary:{total:t.length,completed:a,inProgress:h,queued:b,failed:y},results:t.map(j=>({demoPatientId:j.demoPatientId,demoPatientName:j.demoPatientName,simProfileId:j.simProfileId,simProfileName:j.simProfileName,callId:j.callId||null,status:j.status,callStatus:j.callStatus||null,errorMessage:j.errorMessage||null}))},S=JSON.stringify(m,null,2),v=new Blob([S],{type:"application/json;charset=utf-8;"}),R=document.createElement("a"),q=URL.createObjectURL(v);R.setAttribute("href",q),R.setAttribute("download",`simulate-calls-results-${new Date().toISOString().slice(0,19).replace(/:/g,"-")}.json`),R.style.visibility="hidden",document.body.appendChild(R),R.click(),document.body.removeChild(R)},u=m=>{const{status:S,callStatus:v}=m;switch(S){case"completed":return e.jsx(A,{label:"Completed",color:"success",size:"small",icon:e.jsx(Qs,{})});case"in_progress":return e.jsx(A,{label:"In Progress",color:"info",size:"small",icon:e.jsx(it,{})});case"initiated":return e.jsx(A,{label:"Initiated",color:"warning",size:"small",icon:e.jsx(rt,{})});case"initiating":return e.jsx(A,{label:"Starting...",color:"info",size:"small",icon:e.jsx(it,{})});case"queued":return e.jsx(A,{label:"In Queue",color:"default",size:"small",icon:e.jsx(rt,{})});case"error":return e.jsx(A,{label:v?v.replace("call_",""):"Error",color:"error",size:"small",icon:e.jsx(Zs,{})})}},a=t.filter(m=>m.status==="completed").length,h=t.filter(m=>m.status==="in_progress"||m.status==="initiated"||m.status==="initiating").length,b=t.filter(m=>m.status==="queued").length,y=t.filter(m=>m.status==="error").length;return e.jsxs(e.Fragment,{children:[e.jsxs(d,{sx:{mt:3,width:"100%"},children:[e.jsxs(d,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[e.jsxs(i,{variant:"subtitle2",children:["Results (",a," completed, ",h," active,"," ",b," queued, ",y," failed)"]}),e.jsx(w,{size:"small",startIcon:e.jsx(ft,{}),onClick:n,variant:"outlined",children:"Download Status"})]}),e.jsx(Pe,{sx:{maxHeight:400,border:1,borderColor:"divider"},children:e.jsxs(Ee,{stickyHeader:!0,size:"small",children:[e.jsx(De,{children:e.jsxs(H,{
1children:[e.jsx(g,{children:"Patient Name"}),e.jsx(g,{children:"Sim Profile"}),e.jsx(g,{children:"Call ID"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Actions"}),e.jsx(g,{children:"Error"})]})}),e.jsx(Te,{children:t.map((m,S)=>e.jsxs(H,{hover:!0,children:[e.jsx(g,{children:e.jsx(i,{variant:"body2",children:m.demoPatientName})}),e.jsx(g,{children:e.jsx(i,{variant:"body2",children:m.simProfileName})}),e.jsx(g,{children:m.callId?e.jsx(i,{variant:"caption",sx:{fontFamily:"monospace",fontSize:"0.75rem"},children:m.callId}):e.jsx(i,{variant:"body2",color:"text.disabled",children:"—"})}),e.jsx(g,{children:u(m)}),e.jsx(g,{children:m.callId?e.jsx(tt,{size:"small",onClick:()=>s(m.callId),title:"View call transcript",children:e.jsx(Kt,{fontSize:"small"})}):e.jsx(i,{variant:"body2",color:"text.disabled",children:"—"})}),e.jsx(g,{children:m.errorMessage?e.jsx(i,{variant:"caption",color:"error.main",sx:{display:"block",maxWidth:300,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:m.errorMessage,children:m.errorMessage}):e.jsx(i,{variant:"body2",color:"text.disabled",children:"—"})})]},S))})]})})]}),e.jsxs(ut,{anchor:"right",open:!!l,onClose:()=>s(null),PaperProps:{sx:{width:{xs:"100%",md:"60%",lg:"50%"}}},sx:{zIndex:1400},children:[e.jsxs(d,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(i,{variant:"h6",children:["Call Transcript",c&&` - ${c.call_id.slice(0,8)}...`]}),e.jsx(tt,{onClick:()=>s(null),size:"small",children:e.jsx(Hs,{})})]}),e.jsx(d,{sx:{flex:1,overflow:"auto",px:2},children:r?e.jsx(d,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx(M,{})}):c?e.jsx(Ys,{messages:c.call_utterances||[],transcriptSettings:{showSystemPrompts:!1,showTasks:!1,showDebug:!1,showFeedback:!1,showVotes:!1,showKickouts:!1,showSchedules:!1,showErrorChecker:!1,showTelemetry:!1,showMDR:!1,hideCancelled:!1,showTimestamps:!1},setTranscriptSettings:()=>{},callId:c.call_id,callStatus:c.call_status}):e.jsx(i,{variant:"body2",color:"text.secondary",children:"No call data available"})})]})]})};function Qe(t=[]){const[l,s]=o.useState(t),c=o.useCallback(u=>{s(a=>a.includes(u)?a.filter(h=>h!==u):[...a,u])},[]),r=o.useCallback(u=>s(u),[]),n=o.useCallback(()=>s([]),[]);return[l,s,{toggle:c,selectAll:r,deselectAll:n}]}function _n(t,l=2){return t.length<=l?`${t.length} selected: ${t.join(", ")}`:`${t.length} selected: ${t.slice(0,l).join(", ")} +${t.length-l} more`}const In={overflow:"auto",flex:1,minHeight:0,border:1,borderColor:"divider",borderRadius:1},Ze={display:"flex",flexDirection:"column",minHeight:0,minWidth:0};function et({onSelectAll:t,onDeselectAll:l,selectDisabled:s,deselectDisabled:c}){return e.jsxs(d,{sx:{display:"flex",gap:1,mb:1,flexShrink:0},children:[e.jsx(w,{size:"small",onClick:t,disabled:s,children:"Select all"}),e.jsx(w,{size:"small",onClick:l,disabled:c,children:"Deselect all"})]})}function Ge({id:t,label:l,secondary:s,checked:c,onToggle:r,iconMinWidth:n=36}){return e.jsx(Ve,{disablePadding:!0,children:e.jsxs(Mt,{onClick:r,dense:!0,children:[e.jsx(Gs,{sx:{minWidth:n},children:e.jsx(ue,{edge:"start",checked:c,tabIndex:-1,disableRipple:!0})}),e.jsx($e,{primary:l,secondary:s,primaryTypographyProps:{variant:"body2"},secondaryTypographyProps:{variant:"caption"}})]})})}const wn=10,Rn=new Set(["c3d6d050-79f0-4c22-80af-4d3abe9182ab","83d214b2-5a53-4550-8883-ce76e8b5cd11"]),kn="i60",Pn=[{value:"i60",label:"i60 (default)"},{value:"patient1",label:"patient1 (experimental)"}],En=({useCaseProjectId:t,scriptId:l,originalScriptId:s})=>{const{triggerSnackbar:c}=is(),r=(s??"")!=="",[n,u]=o.useState("scriptId"),a=n==="originalScriptId"&&r?s??l:l,[h,b,y]=Qe(),[m,,S]=Qe(),[v,,R]=Qe(),[q,j]=o.useState(!1),[E,C]=o.useState(!1),[X,ae]=o.useState(!1),[N,Q]=o.useState(!1),[D,G]=o.useState(()=>new Set),[fe,J]=o.useState(kn),K=Rn.has(s??""),{data:Z,isLoading:ee,isError:Ae}=Ks(),{data:V=[],isLoading:Y,isError:he}=Xs({scriptId:a},{enabled:!!t&&!!a}),[te,se]=o.useState([]),[Ce,ne]=o.useState(!1);o.useEffect(()=>{if(!K){se([]);return}let p=!1;return(async()=>{ne(!0);try{const xe=`${xs()}/rome/v1/simulate/real-patients/sync`,Ye=await us(`${xe}?call_type=${encodeURIComponent(s??"")}`,{method:"POST"});if(!Ye.ok){console.error("[RomeSimulate] Failed to sync real patients:",await Ye.text());return}const ns=await Ye.json();if(!p){const rs=(ns.patients??[]).map(ke=>({patientId:ke.patient_id??"",partnerId:ke.partner_id??"",firstName:ke.first_name??"",lastName:ke.last_name??"",gender:ke.gender??"",phoneNumber:ke.phone_number??""}));se(rs)}}catch(xe){console.error("[RomeSimulate] Error syncing real patients:",xe)}finally{p||ne(!1)}})(),()=>{p=!0}},[K,s]);const{generateCalls:ze,cancelGeneration:We,isGenerating:$,isCancelled:re,progress:oe,results:je,statusMessage:ye,maxTotalCalls:be}=Fs(a,t,void 0,fe),ie=o.useMemo(()=>(Z==null?void 0:Z.presets)??[],[Z==null?void 0:Z.presets]),me=p=>`${p.firstName??""} ${p.lastName??""}`.trim()||p.patientId,_e=o.useMemo(()=>new Set(te.map(p=>p.patientId)),[te]),f=o.useMemo(()=>V.filter(p=>!_e.has(p.patientId)),[V,_e]),T=o.useCallback(p=>{p&&b(L=>[...new Set([...L,p])]),j(!1)},[b]),P=o.useMemo(()=>f.filter(p=>m.includes(p.patientId)),[f,m]),U=o.useMemo(()=>te.filter(p=>v.includes(p.patientId)),[te,v]),ce=o.useMemo(()=>ie.filter(p=>h.includes(p.simulatedPatientId)),[ie,h]),Ie=P.length===0?"Click to select demo patients...":_n(P.map(me)),ge=o.useMemo(()=>[...P,...U],[P,U]),F=o.useMemo(()=>{const p=[];
1for(const L of ge)for(const xe of ce)p.push({patient:L,preset:xe});return p},[ge,ce]);o.useEffect(()=>{G(new Set(F.map((p,L)=>L)))},[m,v,h,F]);const we=o.useMemo(()=>F.filter((p,L)=>D.has(L)),[F,D]),Ke=o.useCallback(p=>{G(L=>{const xe=new Set(L);return xe.has(p)?xe.delete(p):xe.add(p),xe})},[]),Xe=o.useCallback(()=>{G(new Set(F.map((p,L)=>L)))},[F]),x=o.useCallback(()=>{G(new Set)},[]),I=we.length,_=I>be,k=I>wn&&!_,W=o.useCallback(()=>C(!0),[]),de=o.useCallback(()=>C(!1),[]),Re=o.useCallback(()=>j(!0),[]),Le=o.useCallback(()=>j(!1),[]),ts=async()=>{if(!X){c({variant:"error",message:"Please confirm that you understand this will run real agent conversations"});return}Q(!0);try{await ze(we.map(({patient:p,preset:L})=>({patient:p,profile:L}))),c({variant:"success",message:`Successfully generated ${oe.completedCount} of ${I} calls`})}catch(p){c({variant:"error",message:p instanceof Error?p.message:"Failed to generate calls"})}},ss=()=>{We()};return o.useEffect(()=>{$||(Q(!1),ae(!1))},[m,v,h]),e.jsxs(d,{sx:{p:2},children:[e.jsx(i,{variant:"body2",fontWeight:500,gutterBottom:!0,children:"Simulate"}),e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"wrap",mb:2},children:[e.jsxs(i,{variant:"caption",color:"text.secondary",children:["Run simulated calls for script:"," ",e.jsx("code",{style:{fontSize:"0.7rem"},children:a})]}),e.jsx(st,{size:"small",sx:{minWidth:120},children:e.jsxs(nt,{value:n,onChange:p=>u(p.target.value),displayEmpty:!0,sx:{height:28,fontSize:"0.75rem"},children:[r&&e.jsx(Me,{value:"originalScriptId",children:"Original"}),e.jsx(Me,{value:"scriptId",children:"Current"})]})})]}),e.jsxs(d,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr 1fr"},gap:2,alignItems:"stretch",gridAutoRows:"1fr",minHeight:520},children:[e.jsxs(d,{sx:Ze,children:[e.jsx(i,{variant:"subtitle2",color:"text.secondary",sx:{mb:1},children:"Patient Data"}),e.jsxs(B,{variant:"outlined",sx:{p:2,flex:1,minHeight:0,display:"flex",flexDirection:"column",gap:1.5,overflow:"hidden"},children:[e.jsxs(d,{sx:{flex:"1 1 0",minHeight:0,display:"flex",flexDirection:"column"},children:[e.jsx(i,{variant:"caption",color:"text.secondary",fontWeight:600,sx:{display:"block",mb:.5,flexShrink:0},children:"Demo Patient"}),!t||!a?e.jsx(i,{variant:"body2",color:"text.disabled",sx:{flexShrink:0},children:"—"}):Y?e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[e.jsx(M,{size:14}),e.jsx(i,{variant:"body2",color:"text.secondary",children:"Loading..."})]}):he?e.jsx(i,{variant:"body2",color:"error.main",sx:{flexShrink:0},children:"Failed to load"}):f.length===0?e.jsx(i,{variant:"body2",color:"text.secondary",sx:{flexShrink:0},children:"No demo patients"}):e.jsx(Mt,{onClick:W,dense:!0,sx:{border:1,borderColor:"divider",borderRadius:1,flexShrink:0},children:e.jsx($e,{primary:Ie,primaryTypographyProps:{variant:"body2",color:P.length===0?"text.secondary":"text.primary"}})}),e.jsxs(ls,{open:E,onClose:de,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{maxHeight:"80vh"}},children:[e.jsx(as,{children:"Select Demo Patients"}),e.jsxs(os,{dividers:!0,children:[e.jsx(et,{onSelectAll:()=>S.selectAll(f.map(p=>p.patientId)),onDeselectAll:S.deselectAll,selectDisabled:f.length===0,deselectDisabled:m.length===0}),e.jsx(He,{dense:!0,disablePadding:!0,children:f.map(p=>e.jsx(Ge,{id:p.patientId,label:me(p),checked:m.includes(p.patientId),onToggle:()=>S.toggle(p.patientId)},p.patientId))})]}),e.jsx(cs,{children:e.jsx(w,{onClick:de,children:"Done"})})]})]}),e.jsxs(d,{sx:{flex:"1 1 0",minHeight:0,display:"flex",flexDirection:"column"},children:[e.jsx(i,{variant:"caption",color:"text.secondary",fontWeight:600,sx:{display:"block",mb:.5,flexShrink:0},children:"Real Patient (De-ID)"}),e.jsx(He,{dense:!0,disablePadding:!0,sx:In,children:Ce?e.jsx(Ve,{disablePadding:!0,children:e.jsx($e,{primary:"Loading real patients...",primaryTypographyProps:{variant:"body2",color:"text.disabled"}})}):te.length===0?e.jsx(Ve,{disablePadding:!0,children:e.jsx($e,{primary:K?"No real patients found for this scenario":"No real patients",primaryTypographyProps:{variant:"body2",color:"text.disabled"}})}):te.map(p=>e.jsx(Ge,{id:p.patientId,label:me(p),checked:v.includes(p.patientId),onToggle:()=>R.toggle(p.patientId)},p.patientId))})]})]})]}),e.jsxs(d,{sx:Ze,children:[e.jsx(i,{variant:"subtitle2",color:"text.secondary",sx:{mb:1},children:"Sim Profile"}),e.jsxs(B,{variant:"outlined",sx:{p:2,flex:1,minHeight:0,display:"flex",flexDirection:"column",overflow:"auto"},children:[Ae&&e.jsx(z,{severity:"error",sx:{mb:2},children:"Failed to load presets"}),ee?e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:1,py:2},children:[e.jsx(M,{size:20}),e.jsx(i,{variant:"body2",color:"text.secondary",children:"Loading presets..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(et,{onSelectAll:()=>y.selectAll(ie.map(p=>p.simulatedPatientId)),onDeselectAll:y.deselectAll,selectDisabled:ie.length===0,deselectDisabled:h.length===0}),e.jsx(He,{dense:!0,disablePadding:!0,sx:{mb:2},children:ie.length===0?e.jsx(Ve,{disablePadding:!0,children:e.jsx($e,{primary:"No presets yet",secondary:"Use Modify presets to add or remove presets",primaryTypographyProps:{variant:"body2",color:"text.secondary"},secondaryTypographyProps:{variant:"caption"}})}):ie.map(p=>e.jsx(Ge,{id:p.simulatedPatientId,label:p.name??p.simulatedPatientId,secondary:p.description??void 0,checked:h.includes(p.simulatedPatientId),onToggle:()=>y.toggle(p.simulatedPatientId),iconMinWidth:40},p.simulatedPatientId))}),e.jsx(w,{variant:"outlined",size:"small",startIcon:e.jsx(qs,{}),onClick:Re,children:"Modify presets"})]})]})]}),e.jsxs(d,{sx:Ze,children:[e.jsx(i,{variant:"subtitle2",color:"text.secondary",sx:{mb:1},children:"Calls to Generate"}),e.jsx(B,{variant:"outlined",sx:{p:2,flex:1,minHeight:0,display:"flex",flexDirection:"column",overflow:"auto"},children:F.length===0?e.jsx(i,{variant:"body2",color:"text.secondary",children:"Select patients and sim profiles to preview calls"}):e.jsxs(e.Fragment,{children:[e.jsx(et,{onSelectAll:Xe,onDeselectAll:x,selectDisabled:F.length===0,deselectDisabled:D.size===0}),e.jsxs(i,{variant:"body2",color:"text.secondary",sx:{mb:1},children:[I," call",I!==1?"s":""," selected to generate:"]}),e.jsx(He,{dense:!0,disablePadding:!0,sx:{flex:1,overflow:"auto",mb:2},children:F.map((p,L)=>e.jsx(Ge,{id:String(L),label:me(p.patient),secondary:`× ${p.preset.name}`,checked:D.has(L),onToggle:()=>Ke(L)},L))})]})})]})]}),F.length>0&&e.jsxs(d,{sx:{mt:3},children:[e.jsx(Ne,{sx:{mb:2}}),_&&e.jsxs(z,{severity:"error",sx:{mb:2},children:[e.jsx(i,{variant:"subtitle2",sx:{mb:1},children:"Maximum Call Limit Exceeded"}),e.jsxs(i,{variant:"body2",children:["Cannot generate ",I," calls. Maximum allowed is"," ",be," calls per batch. Please reduce your selection or run multiple batches."]})]}),k&&!N&&e.jsxs(z,{severity:"warning",sx:{mb:2},children:[e.jsx(i,{variant:"subtitle2",sx:{mb:1},children:"Large Batch Warning"}),e.jsxs(i,{variant:"body2",children:["You are about to generate ",I," calls. This may impact production models and take hours to complete. Consider running smaller batches for better manageability."]})]}),!N&&!_&&e.jsx(z,{severity:"info",sx:{mb:2},children:e.jsx(i,{variant:"body2",children:"This will create and automatically run calls where the agent (Rachel) converses with the selected simulated patient profiles. The conversations will run automatically in the background, and you can monitor progress in real-time. Proper job scheduling is coming soon."})}),!N&&!_&&e.jsxs(st,{size:"small",sx:{mb:2,minWidth:200},children:[e.jsx(ds,{id:"patient-sim-model-label",children:"Patient Sim Model"}),e.jsx(nt,{labelId:"patient-sim-model-label",value:fe,label:"Patient Sim Model",onChange:p=>J(p.target.value),disabled:$,children:Pn.map(p=>e.jsx(Me,{value:p.value,children:p.label},p.value))})]}),!N&&!_&&e.jsx(d,{sx:{mb:2},children:e.jsx(en,{control:e.jsx(ue,{checked:X,onChange:p=>ae(p.target.checked),disabled:$}),label:e.jsx(i,{variant:"body2",children:"I understand this will run real agent conversations with simulated patients using the production model"})})}),$&&e.jsxs(d,{sx:{mb:2},children:[e.jsx(i,{variant:"subtitle2",sx:{mb:1,fontSize:"0.875rem",color:"text.secondary"},children:ye}),e.jsx(tn,{variant:"determinate",value:oe.percentage,sx:{mb:1}}),e.jsxs(i,{variant:"caption",color:"text.secondary",children:[oe.completedCount," of ",oe.totalCount," calls completed (",Math.round(oe.percentage),"%)"]})]}),N&&!$&&e.jsx(z,{severity:je.every(p=>p.status!=="error")?"success":"warning",sx:{mb:2},children:e.jsxs(i,{variant:"body2",children:[ye,re&&" (Generation was cancelled)"]})}),e.jsxs(d,{sx:{display:"flex",gap:1,mb:2},children:[!N&&e.jsx(w,{variant:"contained",startIcon:e.jsx(gt,{}),onClick:ts,disabled:$||!X||_||we.length===0,children:"Start Generation"}),$&&e.jsx(w,{onClick:ss,variant:"outlined",color:"warning",disabled:re,children:re?"Cancelling...":"Cancel Generation"})]})]}),N&&e.jsx(Cn,{results:je}),e.jsx(ut,{anchor:"right",open:q,onClose:Le,PaperProps:{sx:{width:{xs:"100%",sm:420}}},children:e.jsx(Is,{simulatedPatientId:null,setSimulatedPatientId:T,onClose:Le})})]})},Dn=({useCaseProjectId:t})=>{var h,b,y,m;const{data:l,isLoading:s}=xt(t||void 0),c=l?Fe(l):!1,{data:r,isLoading:n}=Je({queryKey:["use_case_project_v2_script",t],queryFn:()=>dt(t),enabled:!!t&&c});if(s||c&&n)return e.jsx(d,{sx:{display:"flex",justifyContent:"center",p:4},children:e.jsx(M,{size:24})});const u=c?((b=(h=r==null?void 0:r.usecaseProject)==null?void 0:h.script)==null?void 0:b.entityId)??"":(l==null?void 0:l.script_id)??"",a=c?((m=(y=r==null?void 0:r.usecaseProject)==null?void 0:y.script)==null?void 0:m.parentEntityId)??null:ct(l)??null;return e.jsx(En,{useCaseProjectId:t,scriptId:u,originalScriptId:a})},Tn=async(t,l)=>{const c=new URLSearchParams().toString(),r=cn(),n=c?`${r}?${c}`:r;return Ft(n,{method:"GET"})},Xt=t=>Je({queryKey:["rome","critics","catalog",t],queryFn:()=>Tn()}),An=async t=>Ft(on(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),Yt=t=>hs({mutationFn:l=>An(l),...t}),zn=({call:t,selected:l,onSelect:s})=>{const c=Ht();return e.jsxs(H,{hover:!0,onClick:()=>s(t.call_id,!l),sx:{cursor:"pointer"},children:[e.jsx(g,{padding:"checkbox",children:e.jsx(ue,{checked:l})}),e.jsx(g,{onClick:r=>r.stopPropagation(),children:e.jsx(Jt,{component:lt,to:c(t.call_id),target:"_blank",rel:"noopener noreferrer",sx:{color:"text.primary",textDecoration:"none","&:hover":{textDecoration:"underline"}},children:e.jsx(i,{variant:"body2",component:"span",children:t.call_id})})}),e.jsx(g,{children:e.jsx(A,{label:zt(t.call_status),size:"small",variant:"outlined"})}),e.jsx(g,{sx:{maxWidth:100},children:e.jsx(i,{variant:"body2",noWrap:!0,children:t.patient_name||"-"})}),e.jsx(g,{sx:{maxWidth:80},children:e.jsx(i,{variant:"body2",noWrap:!0,children:Wt(t.started_at)})}),e.jsx(g,{align:"right",children:e.jsx(i,{variant:"body2",children:Lt(t.duration)})})]})},Qt=({type:t})=>{const l=t==="LLM_BASED";return e.jsx(A,{label:l?"LLM":"Rule",size:"small",color:l?"primary":"default",variant:"outlined",sx:{fontWeight:500,fontSize:"0.7rem"}})},Wn=t=>{const l=new Map;for(const s of t){const c=l.get(s.call_id);c?c.push(s):l.set(s.call_id,[s])}return Array.from(l.entries()).map(([s,c])=>({call_id:s,critics:c,totalFailures:c.reduce((r,n)=>r+n.number_of_failures,0),totalRuns:c.reduce((r,n)=>r+n.number_of_runs,0)}))},Zt=({outcome:t})=>e.jsx(A,{icon:t==="success"?e.jsx(rn,{sx:{fontSize:16}}):e.jsx(ms,{sx:{fontSize:16}}),label:t==="success"?"Pass":"Fail",size:"small",color:t==="success"?"success":"error",variant:"outlined",sx:{fontWeight:500,fontSize:"0.7rem"}}),Ln=({utteranceIds:t,utterances:l,isLoading:s})=>{if(t.length===0)return null;if(s)return e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:1,mt:1},children:[e.jsx(M,{size:14}),e.jsx(i,{variant:"caption",color:"text.secondary",children:"Loading utterances..."})]});const c=t.map(r=>
1l.get(r)).filter(Boolean);return c.length===0?e.jsxs(i,{variant:"caption",color:"text.secondary",sx:{mt:.5},children:["Referenced utterances:"," ",t.map(r=>r.slice(0,8)+"...").join(", ")]}):e.jsxs(d,{sx:{mt:1},children:[e.jsx(i,{variant:"caption",color:"text.secondary",fontWeight:600,sx:{mb:.5,display:"block"},children:"Referenced Utterances"}),c.map(r=>{const n=r.role.toLowerCase()==="assistant"||r.role.toLowerCase()==="agent";return e.jsxs(d,{sx:{mt:.5,p:1,pl:1.5,borderLeft:3,borderColor:n?"primary.main":"grey.400",bgcolor:n?"primary.50":"grey.100",borderRadius:"0 4px 4px 0"},children:[e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:1,mb:.25},children:[e.jsx(i,{variant:"caption",fontWeight:700,color:n?"primary.main":"text.secondary",sx:{textTransform:"uppercase"},children:r.role}),e.jsxs(i,{variant:"caption",color:"text.disabled",children:[r.utterance_id.slice(0,8),"..."]})]}),e.jsx(i,{variant:"body2",sx:{whiteSpace:"pre-wrap"},children:r.content})]},r.utterance_id)})]})},On=({run:t,index:l,totalRuns:s,utterances:c,utterancesLoading:r})=>{const[n,u]=o.useState(!1),a=t.failure_condition||t.utterance_references.length>0||t.error_message;return e.jsxs(d,{sx:{py:.75,px:1.5,bgcolor:t.outcome==="failure"?"error.50":"transparent",borderRadius:1,"&:not(:last-child)":{mb:.5}},children:[e.jsxs(d,{sx:{display:"flex",alignItems:"flex-start",gap:1,cursor:a?"pointer":"default"},onClick:()=>a&&u(h=>!h),children:[s>1&&e.jsxs(i,{variant:"caption",color:"text.secondary",sx:{mt:.25,minWidth:40,flexShrink:0},children:["Run ",l+1]}),e.jsx(Zt,{outcome:t.outcome}),e.jsx(i,{variant:"body2",sx:{flex:1,fontSize:"0.8rem",lineHeight:1.5},children:t.rationale}),a&&e.jsx(tt,{size:"small",sx:{mt:-.25,flexShrink:0},children:n?e.jsx(ln,{fontSize:"small"}):e.jsx(an,{fontSize:"small"})})]}),e.jsx(gs,{in:n,children:e.jsxs(d,{sx:{ml:s>1?"48px":"0px",mt:1},children:[t.failure_condition&&e.jsx(z,{severity:"warning",sx:{mb:1,py:0,"& .MuiAlert-message":{py:.5}},variant:"outlined",children:e.jsx(i,{variant:"body2",sx:{fontSize:"0.8rem"},children:t.failure_condition})}),e.jsx(Ln,{utteranceIds:t.utterance_references,utterances:c,isLoading:r}),t.error_message&&e.jsx(z,{severity:"error",sx:{mt:1,py:0,"& .MuiAlert-message":{py:.5}},variant:"outlined",children:e.jsx(i,{variant:"body2",sx:{fontSize:"0.8rem"},children:t.error_message})})]})})]})},$n=({critic:t,utterances:l,utterancesLoading:s})=>{const c=t.number_of_runs-t.number_of_failures;return e.jsxs(d,{sx:{border:1,borderColor:t.outcome==="failure"?"error.200":"divider",borderRadius:1,overflow:"hidden","&:not(:last-child)":{mb:1.5}},children:[e.jsxs(d,{sx:{px:2,py:1.5,display:"flex",alignItems:"center",gap:1.5,bgcolor:t.outcome==="failure"?"error.50":"grey.50"},children:[e.jsx(Zt,{outcome:t.outcome}),e.jsxs(d,{sx:{flex:1,minWidth:0},children:[e.jsx(i,{variant:"body2",fontWeight:600,children:t.critic_name}),e.jsx(i,{variant:"caption",color:"text.secondary",sx:{display:"block"},children:t.critic_description})]}),e.jsx(A,{label:`${c}/${t.number_of_runs} passed`,size:"small",color:t.outcome==="success"?"success":"error",variant:"filled",sx:{fontWeight:500,fontSize:"0.7rem",flexShrink:0}})]}),e.jsx(d,{sx:{p:1},children:t.detailed_run_results.map((r,n)=>e.jsx(On,{run:r,index:n,totalRuns:t.number_of_runs,utterances:l,utterancesLoading:s},n))})]})},Mn=({group:t})=>{const l=t.critics.some(h=>h.detailed_run_results.some(b=>b.utterance_references.length>0)),{data:s,isLoading:c}=Tt(l?t.call_id:void 0,{includeCallUtterances:!0},{retry:!1}),r=o.useMemo(()=>{const h=new Map;if(s!=null&&s.call_utterances)for(const b of s.call_utterances)h.set(b.utterance_id,b);return h},[s==null?void 0:s.call_utterances]),n=t.totalFailures,u=t.critics.length,a=n>0;return e.jsxs(Vt,{defaultExpanded:a,sx:{"&:not(:last-child)":{mb:1},"&:before":{display:"none"},border:1,borderColor:a?"error.200":"divider",borderRadius:"8px !important",overflow:"hidden"},disableGutters:!0,children:[e.jsx(Bt,{expandIcon:e.jsx(sn,{}),sx:{bgcolor:a?"error.50":"grey.50",minHeight:48},children:e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:1.5,width:"100%"},children:[e.jsx(i,{variant:"body2",fontWeight:600,sx:{fontFamily:"monospace",userSelect:"text",cursor:"text"},children:t.call_id}),e.jsxs(i,{variant:"caption",color:"text.secondary",children:[u," critic",u!==1?"s":""]}),a?e.jsx(A,{label:`${n} failure${n!==1?"s":""}`,size:"small",color:"error",variant:"filled",sx:{fontWeight:500,fontSize:"0.7rem",ml:"auto"}}):e.jsx(A,{label:"All passed",size:"small",color:"success",variant:"filled",sx:{fontWeight:500,fontSize:"0.7rem",ml:"auto"}})]})}),e.jsx(qt,{sx:{p:2},children:t.critics.map(h=>e.jsx($n,{critic:h,utterances:r,utterancesLoading:c&&l},`${h.critic_key}-${h.call_id}`))})]})},es=({results:t})=>{const l=o.useMemo(()=>Wn(t),[t]),s=l.length,c=t.length,r=t.reduce((u,a)=>u+a.number_of_failures,0),n=t.reduce((u,a)=>u+a.number_of_runs,0);return e.jsxs(d,{children:[e.jsxs(d,{sx:{display:"flex",gap:2,mb:2,p:1.5,bgcolor:"grey.50",borderRadius:1,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs(i,{variant:"body2",children:[e.jsx("strong",{children:s})," call",s!==1?"s":""]}),e.jsx(Ne,{orientation:"vertical",flexItem:!0}),e.jsxs(i,{variant:"body2",children:[e.jsx("strong",{children:c})," critic evaluation",c!==1?"s":""]}),e.jsx(Ne,{orientation:"vertical",flexItem:!0}),e.jsxs(i,{variant:"body2",children:[e.jsx("strong",{children:n-r}),"/",n," runs passed"]}),r>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ne,{orientation:"vertical",flexItem:!0}),e.jsxs(i,{variant:"body2",color:"error.main",fontWeight:600,children:[r," failure",r!==1?"s":""]})]})]}),l.map(u=>e.jsx(Mn,{group:u},u.call_id))]})},Nn=({scriptId:t,originalScriptId:l})=>
1{const[s,c]=o.useState([]),[r,n]=o.useState([]),[u,a]=o.useState(0),[h]=o.useState(10),[b,y]=o.useState(null),[m,S]=o.useState(null),[v,R]=o.useState(0),[q,j]=o.useState(!1),E=o.useRef(null),C=(l??"")!=="",[X,ae]=o.useState("scriptId"),N=X==="originalScriptId"&&C?l??t:t,Q={limit:h,offset:u*h,scriptId:N},{data:D,isLoading:G,error:fe,refetch:J}=ps(Q),K=o.useMemo(()=>(D==null?void 0:D.calls)??[],[D==null?void 0:D.calls]),Z=(D==null?void 0:D.total_count)??0,{data:ee,isLoading:Ae,isError:V}=Xt(),Y=o.useMemo(()=>(ee==null?void 0:ee.items)??[],[ee==null?void 0:ee.items]),he=Yt({onSuccess:f=>{f.error?(S(f.error),y(null)):(y(f.results??null),S(null))},onError:f=>{S(f instanceof Error?f.message:"Failed to run experiment."),y(null)}}),te=o.useCallback((f,T)=>{c(P=>T?[...new Set([...P,f])]:P.filter(U=>U!==f))},[]),se=o.useCallback(f=>{const T=K.map(P=>P.call_id);c(P=>f.target.checked?[...new Set([...P,...T])]:P.filter(U=>!T.includes(U)))},[K]),Ce=o.useCallback(()=>c([]),[]),ne=o.useCallback((f,T)=>{a(T)},[]),ze=o.useCallback((f,T)=>{n(P=>T?[...new Set([...P,f])]:P.filter(U=>U!==f))},[]),We=o.useCallback(f=>{n(f.target.checked?Y.map(T=>T.critic_key):[])},[Y]),$=o.useCallback(()=>{s.length===0||r.length===0||(y(null),S(null),j(!1),he.mutate({call_ids:s,critic_keys:r}))},[s,r,he]),re=o.useCallback(()=>{y(null),S(null),j(!1)},[]),oe=o.useCallback(()=>{if(!b)return;const f=new Date().toISOString(),T={script_id:N,created_at:f,results:b},P=new Blob([JSON.stringify(T,null,2)],{type:"application/json"}),U=URL.createObjectURL(P),ce=document.createElement("a");ce.href=U,ce.download=`rome-evaluate-${N}-${f.replace(/[:.]/g,"-")}.json`,ce.click(),URL.revokeObjectURL(U)},[b,N]),je=o.useCallback(f=>{var U;const T=(U=f.target.files)==null?void 0:U[0];if(!T)return;const P=new FileReader;P.onload=ce=>{var Ie;try{const ge=JSON.parse((Ie=ce.target)==null?void 0:Ie.result),F=ge.results??ge;if(!Array.isArray(F)){S("Invalid JSON format: expected an object with a 'results' array or a top-level array.");return}y(F),S(null),j(!0)}catch{S("Failed to parse JSON file. Please check the file format.")}},P.readAsText(T),f.target.value=""},[]),ye=K.length>0&&K.every(f=>s.includes(f.call_id)),be=K.some(f=>s.includes(f.call_id))&&!ye,ie=Y.length>0&&Y.every(f=>r.includes(f.critic_key)),me=Y.some(f=>r.includes(f.critic_key))&&!ie,_e=s.length>0&&r.length>0&&!he.isPending;return b?e.jsxs(d,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:2,mb:2,flexWrap:"wrap"},children:[e.jsx(w,{variant:"outlined",startIcon:e.jsx(mt,{}),onClick:re,children:"Back"}),e.jsx(w,{variant:"outlined",startIcon:e.jsx(ft,{}),onClick:oe,children:"Download JSON"}),e.jsx(d,{sx:{flex:1}}),e.jsxs(Gt,{value:v,onChange:(f,T)=>R(T),sx:{minHeight:32,"& .MuiTab-root":{minHeight:32,py:.5,fontSize:"0.8rem"}},children:[e.jsx(qe,{label:"Structured"}),e.jsx(qe,{label:"JSON"})]})]}),e.jsx(d,{sx:{flex:1,minHeight:0,overflow:"auto"},children:v===0?e.jsx(es,{results:b}):e.jsx(B,{variant:"outlined",sx:{p:2,bgcolor:"grey.50"},children:e.jsx(d,{component:"pre",sx:{m:0,fontSize:"0.75rem",fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(b,null,2)})})})]}):e.jsxs(d,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[e.jsx(i,{variant:"body2",fontWeight:500,gutterBottom:!0,children:"Evaluate"}),e.jsxs(d,{sx:{mb:2,display:"flex",alignItems:"center",gap:1,flexWrap:"wrap"},children:[e.jsxs(i,{variant:"caption",color:"text.secondary",children:["Script ID:"," ",e.jsx("code",{style:{fontSize:"0.7rem"},children:N})]}),e.jsx(st,{size:"small",sx:{minWidth:120},children:e.jsxs(nt,{value:X,onChange:f=>ae(f.target.value),displayEmpty:!0,sx:{height:28,fontSize:"0.75rem"},children:[C&&e.jsx(Me,{value:"originalScriptId",children:"Original"}),e.jsx(Me,{value:"scriptId",children:"Current"})]})})]}),e.jsxs(d,{sx:{display:"flex",gap:2,flex:1,minHeight:0},children:[e.jsxs(B,{variant:"outlined",sx:{flex:"1 1 60%",minWidth:0,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsxs(d,{sx:{p:2,pb:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(i,{variant:"subtitle2",children:["Calls",s.length>0&&e.jsx(A,{label:s.length,size:"small",color:"primary",sx:{ml:1,height:20,minWidth:20}})]}),e.jsx(w,{size:"small",startIcon:e.jsx(At,{}),onClick:()=>J(),disabled:G,children:"Refresh"})]}),G?e.jsx(d,{sx:{display:"flex",justifyContent:"center",p:4},children:e.jsx(M,{size:24})}):fe?e.jsx(z,{severity:"error",sx:{m:2},children:"Failed to load calls"}):Z===0?e.jsx(i,{variant:"body2",color:"text.secondary",sx:{p:2},children:"No calls found for this script."}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{sx:{flex:1,minHeight:0,overflow:"auto"},children:e.jsxs(Ee,{size:"small",stickyHeader:!0,children:[e.jsx(De,{children:e.jsxs(H,{
1children:[e.jsx(g,{padding:"checkbox",children:e.jsx(ue,{indeterminate:be,checked:ye,onChange:se})}),e.jsx(g,{children:"Call ID"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Patient"}),e.jsx(g,{children:"Date"}),e.jsx(g,{align:"right",children:"Duration"})]})}),e.jsx(Te,{children:K.map(f=>e.jsx(zn,{call:f,selected:s.includes(f.call_id),onSelect:te},f.call_id))})]})}),e.jsx(pt,{component:"div",count:Z,page:u,onPageChange:ne,rowsPerPage:h,rowsPerPageOptions:[h]})]}),s.length>0&&e.jsx(d,{sx:{p:2,pt:0},children:e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"wrap"},children:[e.jsxs(i,{variant:"body2",color:"text.secondary",children:["Selected (",s.length,"):"]}),s.slice(0,5).map(f=>e.jsx(A,{label:`${f.slice(0,8)}...`,size:"small",onDelete:()=>te(f,!1)},f)),s.length>5&&e.jsxs(i,{variant:"caption",color:"text.secondary",children:["+",s.length-5," more"]}),e.jsx(w,{size:"small",startIcon:e.jsx(Ut,{}),onClick:Ce,children:"Clear"})]})})]}),e.jsxs(B,{variant:"outlined",sx:{flex:"1 1 40%",minWidth:0,display:"flex",flexDirection:"column",minHeight:0,maxHeight:520},children:[e.jsx(d,{sx:{p:2,pb:1},children:e.jsxs(i,{variant:"subtitle2",children:["Critic Catalog",r.length>0&&e.jsx(A,{label:r.length,size:"small",color:"primary",sx:{ml:1,height:20,minWidth:20}})]})}),Ae?e.jsx(d,{sx:{display:"flex",justifyContent:"center",p:4},children:e.jsx(M,{size:24})}):V?e.jsx(z,{severity:"error",sx:{m:2},children:"Failed to load critics"}):e.jsx(Pe,{sx:{flex:1,minHeight:0,overflow:"auto"},children:e.jsxs(Ee,{size:"small",stickyHeader:!0,children:[e.jsx(De,{children:e.jsxs(H,{children:[e.jsx(g,{padding:"checkbox",children:e.jsx(ue,{indeterminate:me,checked:ie,onChange:We})}),e.jsx(g,{sx:{fontWeight:600},children:"Name"}),e.jsx(g,{sx:{fontWeight:600},children:"Type"})]})}),e.jsxs(Te,{children:[Y.map(f=>e.jsxs(H,{hover:!0,onClick:()=>ze(f.critic_key,!r.includes(f.critic_key)),sx:{cursor:"pointer"},children:[e.jsx(g,{padding:"checkbox",children:e.jsx(ue,{checked:r.includes(f.critic_key)})}),e.jsxs(g,{children:[e.jsx(i,{variant:"body2",fontWeight:500,children:f.critic_name}),e.jsx(i,{variant:"caption",color:"text.secondary",children:f.critic_description})]}),e.jsx(g,{children:e.jsx(Qt,{type:f.critic_type})})]},f.critic_key)),Y.length===0&&e.jsx(H,{children:e.jsx(g,{colSpan:3,align:"center",children:e.jsx(i,{variant:"body2",color:"text.secondary",sx:{py:2},children:"No critics available"})})})]})]})})]})]}),e.jsxs(d,{sx:{mt:2,flexShrink:0},children:[m&&e.jsx(z,{severity:"error",onClose:()=>S(null),sx:{mb:2},children:m}),e.jsxs(d,{sx:{display:"flex",gap:1},children:[e.jsx(w,{variant:"contained",sx:{flex:1},startIcon:he.isPending?e.jsx(M,{size:18,color:"inherit"}):e.jsx(gt,{}),onClick:$,disabled:!_e,children:he.isPending?"Running Critics...":s.length===0?"Select calls to run critics":r.length===0?"Select critics to run":`Run ${r.length} critic${r.length!==1?"s":""} on ${s.length} call${s.length!==1?"s":""}`}),e.jsx("input",{ref:E,type:"file",accept:".json",hidden:!0,onChange:je}),e.jsx(w,{variant:"outlined",startIcon:e.jsx(Nt,{}),onClick:()=>{var f;return(f=E.current)==null?void 0:f.click()},children:"Upload Results"})]})]})]})},Un=({useCaseProjectId:t})=>{var h,b,y,m;const{data:l,isLoading:s}=xt(t||void 0),c=l?Fe(l):!1,{data:r,isLoading:n}=Je({queryKey:["use_case_project_v2_script",t],queryFn:()=>dt(t),enabled:!!t&&c});if(s||c&&n)return e.jsx(d,{sx:{display:"flex",justifyContent:"center",p:4},children:e.jsx(M,{size:24})});const u=c?((b=(h=r==null?void 0:r.usecaseProject)==null?void 0:h.script)==null?void 0:b.entityId)??"":(l==null?void 0:l.script_id)??"",a=c?((m=(y=r==null?void 0:r.usecaseProject)==null?void 0:y.script)==null?void 0:m.parentEntityId)??null:ct(l)??null;return e.jsx(Nn,{scriptId:u,originalScriptId:a})},Fn=({useCaseProjectId:t})=>e.jsx(ws,{useCaseProjectId:t});function Hn(t=!1,l={}){const[s,c]=o.useState(t),r=o.useCallback(()=>{c(a=>{var h;return a||((h=l.onOpen)==null||h.call(l),!0)})},[l.onOpen]),n=o.useCallback(()=>{c(a=>{var h;return a&&((h=l.onClose)==null||h.call(l),!1)})},[l.onClose]),u=o.useCallback(()=>{s?n():r()},[n,r,s]);return[s,{open:r,close:n,toggle:u}]}const Gn=({issues:t,colors:l})=>{const[s,c]=o.useState(!1);if(!t||t.length===0)return null;const r=t.slice(0,s?void 0:It.MAX_ISSUES_DISPLAYED),n=t.length-It.MAX_ISSUES_DISPLAYED;return e.jsxs(e.Fragment,{children:[e.jsxs(i,{variant:"body2",sx:{mb:1,fontWeight:Se.ISSUES_HEADER_WEIGHT,color:l.text},children:[O.ISSUES_FOUND," (",t.length,"):"]}),e.jsxs(d,{sx:{ml:2,mb:2},children:[r.map((u,a)=>e.jsxs(i,{variant:"body2",sx:{mb:.5,color:le.CODE_TEXT,fontFamily:"monospace",backgroundColor:le.CODE_BG,padding:"4px 8px",borderRadius:1,fontSize:Se.CODE_FONT_SIZE},children:['• "',u,'"']},a)),n>0&&!s&&e.jsx(i,{variant:"body2",component:"button",onClick:()=>c(!0),sx:{color:le.NEUTRAL_TEXT,fontStyle:"italic",cursor:"pointer",border:"none",background:"none",padding:0,textAlign:"left","&:hover":{textDecoration:"underline"}},children:O.AND_MORE.replace("{count}",n.toString())}),n>0&&s&&e.jsx(i,{variant:"body2",component:"button",onClick:()=>c(!1),sx:{color:le.NEUTRAL_TEXT,fontStyle:"italic",cursor:"pointer",border:"none",background:"none",padding:0,textAlign:"left",mt:.5,"&:hover":{textDecoration:"underline"}},children:O.SHOW_LESS})]})]})},Vn=({fixGuidance:t})=>e.jsxs(d,{sx:{backgroundColor:le.FIX_GUIDANCE_BG,border:`1px solid ${le.FIX_GUIDANCE_BORDER}`,borderRadius:ve.CARD_BORDER_RADIUS,padding:ve.CARD_PADDING,mt:2},children:[e.jsx(i,{variant:"body2",sx:{fontWeight:Se.FIX_GUIDANCE_WEIGHT,mb:1},children:O.HOW_TO_FIX}),e.jsx(i,{variant:"body2",sx:{color:le.FIX_GUIDANCE_TEXT},children:t})]}),Bn=({checkName:t,check:l})=>{const[s,c]=o.useState(!1),r=()=>{c(!s)},n=l.enhanced_result,u=l.status==="error",a=l.status==="skipped",h=!u&&!a&&(n==null?void 0:n.has_issues)===!1,b=l.severity||"warning",y=Rs(h,b,n==null?void 0:n.suggestions,n==null?void 0:n.areas_for_improvement),m=(n==null?void 0:n.suggestions)&&n.suggestions.length>0||(n==null?void 0:n.areas_for_improvement)&&n.areas_for_improvement.length>0;return e.jsxs(d,{sx:{border:`1px solid ${y.border}`,borderRadius:ve.CARD_BORDER_RADIUS,padding:ve.CARD_PADDING,backgroundColor:y.bg},children:[e.jsxs(d,{display:"flex",alignItems:"center",gap:1,sx:{cursor:"pointer"},onClick:r,children:[u?e.jsx(ks,{sx:{color:y.icon}}):h?e.jsx(Ps,{sx:{color:y.icon}}):e.jsx(Es,{sx:{color:y.icon}}),e.jsx(i,{variant:"h6",sx:{flexGrow:1,fontWeight:Se.CHECK_NAME_WEIGHT},children:t}),!h&&!u&&!a&&e.jsxs(i,{variant:"caption",sx:{color:y.text,fontWeight:Se.SEVERITY_BADGE_WEIGHT,textTransform:"uppercase",backgroundColor:"rgba(255,255,255,0.8)",padding:"2px 6px",borderRadius:1,mr:1},children:["SEVERITY: ",b.toUpperCase()]}),e.jsx(i,{variant:"body2",sx:{color:y.text,fontWeight:Se.STATUS_WEIGHT,mr:1},children:u?"ERROR":a?"SKIPPED":h?m?O.PASS_WITH_SUGGESTIONS:O.PASS:O.FAIL}),s?e.jsx(dn,{}):e.jsx(Rt,{})]}),s&&e.jsxs(d,{sx:{mt:2,pl:4},children:[e.jsx(i,{variant:"body2",sx:{mb:2,color:le.NEUTRAL_TEXT},children:l.instruction}),l.reasoning&&e.jsxs(i,{variant:"body2",sx:{mb:2,color:le.NEUTRAL_TEXT,fontStyle:"italic"},children:[e.jsx("strong",{children:"Why we check:"})," ",l.reasoning]}),e.jsxs(Vt,{defaultExpanded:!1,disableGutters:!0,elevation:0,sx:{mb:2,backgroundColor:"transparent",border:"1px solid",borderColor:"divider",borderRadius:1,"&::before":{display:"none"},"& .MuiAccordionSummary-root":{minHeight:40}
1,"& .MuiAccordionDetails-root":{pt:0}},children:[e.jsx(Bt,{expandIcon:e.jsx(Rt,{}),children:e.jsx(i,{variant:"body2",sx:{fontWeight:600},children:"Script Review Prompt"})}),e.jsx(qt,{children:e.jsx(i,{variant:"body2",sx:{color:le.NEUTRAL_TEXT,fontFamily:"monospace",fontSize:"0.875rem",whiteSpace:"pre-wrap"},children:l.script_review_prompt})})]}),(n==null?void 0:n.rating)&&e.jsxs(i,{variant:"body2",sx:{mb:2,fontWeight:600},children:[e.jsx("strong",{children:"Rating:"})," ",n.rating,typeof n.rating=="number"?"/5":""]}),u?e.jsxs(i,{variant:"body2",sx:{mb:2,color:"error.main"},children:[e.jsx("strong",{children:"Error:"})," ",l.error||"An unknown error occurred during check execution"]}):e.jsxs(i,{variant:"body2",sx:{mb:2},children:[e.jsx("strong",{children:O.RESULT})," ",n==null?void 0:n.reasoning]}),l.documentation_link&&e.jsxs(i,{variant:"body2",sx:{mb:2},children:[e.jsx("strong",{children:O.DOCUMENTATION})," ",e.jsx("a",{href:l.documentation_link,target:"_blank",rel:"noopener noreferrer",style:{color:y.text,textDecoration:"underline"},children:O.LEARN_MORE})]}),(n==null?void 0:n.issues_found)&&n.issues_found.length>0&&e.jsx(Gn,{issues:n.issues_found,colors:y}),(n==null?void 0:n.suggestions)&&n.suggestions.length>0&&e.jsxs(d,{sx:{mb:2},children:[e.jsx(i,{variant:"body2",sx:{fontWeight:600,mb:1},children:"Suggestions for Improvement:"}),e.jsx(d,{sx:{ml:2},children:n.suggestions.map((S,v)=>e.jsxs(i,{variant:"body2",sx:{mb:.5},children:["• ",S]},v))})]}),(n==null?void 0:n.strengths)&&n.strengths.length>0&&e.jsxs(d,{sx:{mb:2},children:[e.jsx(i,{variant:"body2",sx:{fontWeight:600,mb:1},children:"Strengths:"}),e.jsx(d,{sx:{ml:2},children:n.strengths.map((S,v)=>e.jsxs(i,{variant:"body2",sx:{mb:.5},children:["• ",S]},v))})]}),(n==null?void 0:n.areas_for_improvement)&&n.areas_for_improvement.length>0&&e.jsxs(d,{sx:{mb:2},children:[e.jsx(i,{variant:"body2",sx:{fontWeight:600,mb:1},children:"Areas for Improvement:"}),e.jsx(d,{sx:{ml:2},children:n.areas_for_improvement.map((S,v)=>e.jsxs(i,{variant:"body2",sx:{mb:.5},children:["• ",S]},v))})]}),!h&&(n==null?void 0:n.fix_guidance)&&e.jsx(Vn,{fixGuidance:n.fix_guidance})]})]})},qn=({groupName:t,checksInGroup:l,isFirstGroup:s})=>e.jsxs(d,{children:[e.jsxs(i,{variant:"h6",sx:{mb:2,mt:s?0:ve.GROUP_SPACING,color:"text.primary",fontWeight:Se.GROUP_HEADER_WEIGHT,borderBottom:`2px solid ${le.GROUP_BORDER}`,pb:1},children:[t," (",l.length,")"]}),l.map(({checkName:c,check:r})=>e.jsx(d,{sx:{mb:2},children:e.jsx(Bn,{checkName:c,check:r})},c))]}),Jn=({reviewComment:t})=>{const l=$t(t),s=Object.keys(l);return e.jsx(d,{sx:{display:"flex",flexDirection:"column",gap:2,bgcolor:"background.paper",px:ve.CONTAINER_PADDING,overflowY:"auto"},children:s.map((c,r)=>e.jsx(qn,{groupName:c,checksInGroup:l[c],isFirstGroup:r===0},c))})};function Pt(t){const l=Date.now()-t,s=Math.floor(l/1e3),c=Math.floor(s/60);if(c===0)return`${s} second${s!==1?"s":""} ago`;const r=s%60;return r===0?`${c} minute${c!==1?"s":""} ago`:`${c} minute${c!==1?"s":""} ${r} second${r!==1?"s":""} ago`}function Kn({sinceTimestamp:t,children:l,prefix:s=""}){const[c,r]=o.useState(()=>Pt(t));return o.useEffect(()=>{const n=setInterval(()=>{r(Pt(t))},1e3);return()=>clearInterval(n)},[t]),e.jsx(ht,{title:`${s} ${c}`,children:l})}function Xn(t){const l=$t(t),s=["Script Review Results",""];for(const[c,r]of Object.entries(l)){s.push(`${c} (${r.length})`),s.push("");for(const{checkName:n,check:u}of r){const a=u.enhanced_result,h=u.status==="error",b=u.status==="skipped",y=!h&&!b&&(a==null?void 0:a.has_issues)===!1,m=u.severity??"warning",S=(a==null?void 0:a.suggestions)&&a.suggestions.length>0||(a==null?void 0:a.areas_for_improvement)&&a.areas_for_improvement.length>0;s.push(`--- ${n} ---`);const v=h?"ERROR":b?"SKIPPED":y?S?O.PASS_WITH_SUGGESTIONS:O.PASS:O.FAIL;if(s.push(v),!y&&!h&&!b&&s.push(`Severity: ${m.toUpperCase()}`),u.instruction&&(s.push(""),s.push(u.instruction)),u.reasoning&&(s.push(""),s.push(`Why we check: ${u.reasoning}`)),(a==null?void 0:a.rating)!==void 0&&(a==null?void 0:a.rating)!==null&&(s.push(""),s.push(`Rating: ${a.rating}${typeof a.rating=="number"?"/5":""}`)),h?(s.push(""),s.push(`Error: ${u.error??"An unknown error occurred during check execution"}`)):a!=null&&a.reasoning&&(s.push(""),s.push(`${O.RESULT} ${a.reasoning}`)),u.documentation_link&&(s.push(""),s.push(`${O.DOCUMENTATION} ${O.LEARN_MORE} - ${u.documentation_link}`)),a!=null&&a.issues_found&&a.issues_found.length>0){s.push(""),s.push(`${O.ISSUES_FOUND} (${a.issues_found.length}):`);for(const R of a.issues_found)s.push(`  • ${R}`)}if(a!=null&&a.suggestions&&a.suggestions.length>0){s.push(""),s.push("Suggestions for Improvement:");for(const R of a.suggestions)s.push(`  • ${R}`)}if(a!=null&&a.strengths&&a.strengths.length>0){s.push(""),s.push("Strengths:");for(const R of a.strengths)s.push(`  • ${R}`)}if(a!=null&&a.areas_for_improvement&&a.areas_for_improvement.length>0){s.push(""),s.push("Areas for Improvement:");for(const R of a.areas_for_improvement)s.push(`  • ${R}`)}!y&&(a!=null&&a.fix_guidance)&&(s.push(""),s.push(`${O.HOW_TO_FIX}`),s.push(a.fix_guidance)),s.push("")}}return s.join(`
2`)}function Yn({script:t}){const[l,{open:s,close:c}
2]=Hn(!1),[r,n]=o.useState(),[u,a]=o.useState(!0),[h,b]=o.useState(!1),[y,m]=o.useState(!1),{triggerSnackbar:S}=Ot();o.useEffect(()=>{u||m(!0)},[t]);const{mutate:v,isPending:R,submittedAt:q}=$s({onSuccess:C=>{b(!1),C&&n(C),St(Ct.SUCCESS,{component:"ScriptReview",tag:vt.SB_SCRIPT_REVIEWED,info:`script_id: ${t.script_id}`})},onError:C=>{b(!0),S({message:(C==null?void 0:C.message)||"Script review encountered an error, but you can still continue to publish.",variant:"warning"}),St(Ct.ERROR,{component:"ScriptReview",tag:vt.SB_SCRIPT_REVIEWED,info:`script_id: ${t.script_id}`,error_message:C==null?void 0:C.message})}}),j=o.useMemo(()=>{if(u)return"idle";if(R)return"loading";if(h)return"reviewError";if(r!==void 0)return Qn(r)},[R,r,u,h]),E=()=>{j==="reviewError"?(b(!1),v({script:t})):j==="idle"?(a(!1),v({script:t})):j!=="loading"&&s()};return e.jsxs(d,{children:[r&&e.jsx(Zn,{open:l,onClose:c,reviewContent:r}),e.jsx(er,{status:j,onClick:E,clickable:j!=="loading",submittedAt:q}),y&&e.jsx(d,{sx:Ue.HAS_CHANGED_BOX,children:e.jsx(ht,{title:"Script has changed. Click to review again.",children:e.jsx(w,{variant:"text",onClick:()=>{m(!1),v({script:t})},children:e.jsx(i,{variant:"body2",sx:Ue.SCRIPT_CHANGED_TYPOGRAPHY,children:"Script has changed."})})})})]})}function Qn(t){const l=Object.values(t),s=l.filter(n=>{var u;return(u=n.enhanced_result)==null?void 0:u.has_issues}),c=l.filter(n=>{var u,a,h,b;return((u=n.enhanced_result)==null?void 0:u.suggestions)&&((a=n.enhanced_result)==null?void 0:a.suggestions.length)>0||((h=n.enhanced_result)==null?void 0:h.areas_for_improvement)&&((b=n.enhanced_result)==null?void 0:b.areas_for_improvement.length)>0});return l.filter(n=>n.status==="error").length===l.length?"reviewError":s.filter(n=>n.severity==="critical").length>0?"error":s.filter(n=>n.severity==="warning").length>0?"warning":s.filter(n=>n.severity==="info").length>0||c.length>0?"suggestions":"success"}function Zn({open:t,onClose:l,reviewContent:s}){const{triggerSnackbar:c}=Ot(),r=fs(),{copy:n}=Js(),u=async()=>{const a=Xn(s),h=await n(a);c(h?{message:"Review feedback copied to clipboard",variant:"success"}:{message:"Failed to copy to clipboard",variant:"error"})};return e.jsx(ut,{open:t,onClose:l,sx:{zIndex:r.zIndex.modal+1001},children:e.jsxs(d,{sx:Ue.DRAWER_CONTAINER,children:[e.jsxs(d,{sx:Ue.DRAWER_HEADER,children:[e.jsx(i,{variant:"h6",children:"Script Review Results"}),e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(ht,{title:"Copy review feedback",children:e.jsx(w,{variant:"text",onClick:u,size:"small",children:e.jsx(Ds,{sx:{width:18,height:18}})})}),e.jsx(w,{variant:"text",onClick:l,children:e.jsx(Ts,{sx:{width:12,height:12}})})]})]}),e.jsx(Jn,{reviewComment:s})]})})}function er({status:t="loading",onClick:l,clickable:s=!1,submittedAt:c}){const r=e.jsx(d,{sx:{borderRadius:ve.CONTAINER_BORDER_RADIUS,...Ue.BADGE_BASE,...s&&{cursor:"pointer"},...As[t]},onClick:l,children:e.jsx(i,{variant:"body2",sx:{fontWeight:600,color:Ws[t]},children:zs[t]})});return c!==void 0&&c>0&&t==="loading"?e.jsx(Kn,{sinceTimestamp:c,prefix:"Started reviewing",children:r}):r}const tr=({useCaseProjectId:t})=>{const{data:l,isLoading:s,isError:c}=xt(t||void 0),{data:r,isLoading:n,isError:u}=Ms(t,{enabled:!!t}),a=r!=null&&r.usecaseProject?Fe(r==null?void 0:r.usecaseProject):!1,h=a?r==null?void 0:r.usecaseProject:l,b=s||n,y=Ls(h),m=y==null?void 0:y.scriptId;return u?e.jsx(z,{severity:"error",children:"Failed to load use case project. Please try again."}):!a&&c?e.jsx(z,{severity:"error",children:"Failed to load use case project. Please try again."}):t?b?e.jsxs(d,{sx:{display:"flex",justifyContent:"center",py:4},children:[e.jsx(M,{size:32}),e.jsx(i,{sx:{ml:2},color:"text.secondary",children:"Loading project…"})]}):m?e.jsx(sr,{scriptId:m}):e.jsx(z,{severity:"info",children:"This use case project does not have a generated script yet."}):e.jsx(z,{severity:"info",children:"No use case project selected. Create or select a project first."})},sr=({scriptId:t})=>{const{data:l,isLoading:s,isError:c}=js(t,!0);return s?e.jsxs(d,{sx:{display:"flex",justifyContent:"center",py:4},children:[e.jsx(M,{size:32}),e.jsx(i,{sx:{ml:2},color:"text.secondary",children:"Loading script…"})]}):c||!l?e.jsx(z,{severity:"error",children:"Failed to load script. Please try again."}):e.jsx(Yn,{script:l})},nr=()=>{const t=Dt(),{state:l}=ys(),s=l,[c]=o.useState((s==null?void 0:s.scriptId)??""),[r]=o.useState((s==null?void 0:s.useCaseProjectId)??""),[n,u]=o.useState("simulate"),a=[{id:"update",label:"Update"},{id:"review",label:"Script Review"},{id:"simulate",label:"Simulate"},{id:"evaluate",label:"Evaluate"}],h=y=>{const m=["update","review","simulate","evaluate"],S=m.indexOf(n),v=m.indexOf(y);return v<S?"completed":v===S?"active":"pending"},b=y=>{u(y)};return e.jsx(Be,{fullWidth:!0,children:e.jsxs(d,{sx:{p:2,maxWidth:1400,mx:"auto"},children:[e.jsx(w,{startIcon:e.jsx(mt,{}),onClick:()=>t("/rome"),sx:{mb:1},children:"Back"}),e.jsx(d,{sx:{display:"flex",gap:1.5,mb:2},children:a.map(y=>{const m=h(y.id);return e.jsx(B,{elevation:m==="active"?2:0,onClick:()=>b(y.id),sx:{px:3,py:1.5,flex:1,textAlign:"center",cursor:"pointer",border:"2px s
2olid",borderColor:m==="active"?"primary.main":"grey.200",bgcolor:m==="active"?"primary.50":m==="completed"?"success.50":"grey.50","&:hover":{borderColor:m==="active"?"primary.main":"grey.400"}},children:e.jsx(i,{variant:"body2",fontWeight:m==="active"?600:400,color:m==="active"?"primary.main":m==="completed"?"success.main":"text.disabled",children:y.label})},y.id)})}),(c||r)&&e.jsxs(d,{sx:{mb:2},children:[c&&e.jsxs(i,{variant:"caption",color:"text.secondary",sx:{display:"block"},children:["Script ID:"," ",e.jsx("code",{style:{fontSize:"0.7rem"},children:c})]}),r&&e.jsxs(i,{variant:"caption",color:"text.secondary",sx:{display:"block",mt:c?.5:0},children:["Use Case Project ID:"," ",e.jsx("code",{style:{fontSize:"0.7rem"},children:r})]})]}),e.jsxs(B,{sx:{p:2},children:[n==="simulate"&&e.jsx(Dn,{useCaseProjectId:r}),n==="evaluate"&&e.jsx(Un,{useCaseProjectId:r}),n==="update"&&e.jsx(Fn,{useCaseProjectId:r}),n==="review"&&e.jsx(tr,{useCaseProjectId:r})]})]})})},rr=({call:t,selected:l,onSelect:s})=>{const c=Ht();return e.jsxs(H,{hover:!0,onClick:()=>s(t.call_id,!l),sx:{cursor:"pointer"},children:[e.jsx(g,{padding:"checkbox",children:e.jsx(ue,{checked:l})}),e.jsx(g,{onClick:r=>r.stopPropagation(),children:e.jsx(Jt,{component:lt,to:c(t.call_id),target:"_blank",rel:"noopener noreferrer",sx:{color:"text.primary",textDecoration:"none","&:hover":{textDecoration:"underline"}},children:e.jsx(i,{variant:"body2",component:"span",children:t.call_id})})}),e.jsx(g,{children:e.jsx(A,{label:zt(t.call_status),size:"small",variant:"outlined"})}),e.jsx(g,{sx:{maxWidth:100},children:e.jsx(i,{variant:"body2",noWrap:!0,children:t.patient_name||"-"})}),e.jsx(g,{sx:{maxWidth:80},children:e.jsx(i,{variant:"body2",noWrap:!0,children:Wt(t.started_at)})}),e.jsx(g,{align:"right",children:e.jsx(i,{variant:"body2",children:Lt(t.duration)})})]})},ir=()=>{const[t,l]=o.useState(""),[s,c]=o.useState(""),[r,n]=o.useState(""),[u,a]=o.useState([]),[h,b]=o.useState(!1),[y,m]=o.useState(null),[S,v]=o.useState(!1),[R,q]=o.useState(null),[j,E]=o.useState([]),[C,X]=o.useState([]),[ae,N]=o.useState(0),[Q]=o.useState(10),[D,G]=o.useState(null),[fe,J]=o.useState(null),[K,Z]=o.useState(0),ee=o.useRef(null),Ae=o.useMemo(()=>({limit:Q,offset:ae*Q,scriptId:s}),[Q,ae,s]),{data:V,isLoading:Y,error:he,refetch:te}=Je({queryKey:["calls","open-evaluate",s,ae,Q],queryFn:()=>vs(Ae),enabled:!!s}),se=o.useMemo(()=>(V==null?void 0:V.calls)??[],[V==null?void 0:V.calls]),Ce=(V==null?void 0:V.total_count)??0,{data:ne,isLoading:ze,isError:We}=Xt(),$=o.useMemo(()=>(ne==null?void 0:ne.items)??[],[ne==null?void 0:ne.items]),re=Yt({onSuccess:x=>{x.error?(J(x.error),G(null)):(G(x.results??null),J(null))},onError:x=>{J(x instanceof Error?x.message:"Failed to run experiment."),G(null)}}),oe=o.useCallback(async()=>{const x=t.trim();if(x){b(!0),m(null);try{await bs(x),c(x),N(0)}catch{m(`Script "${x}" not found.`)}finally{b(!1)}}},[t]),je=o.useCallback(async()=>{const x=r.split(/[,\s\n]+/).map(W=>W.trim()).filter(Boolean);if(x.length===0)return;v(!0),q(null);const I=await Promise.allSettled(x.map(W=>Ss(W))),_=[],k=[];if(I.forEach((W,de)=>{W.status==="fulfilled"?_.push(x[de]):k.push(x[de])}),_.length>0&&(a(W=>[...new Set([...W,..._])]),E(W=>[...new Set([...W,..._])])),k.length>0){const W=k.slice(0,3).map(Re=>`"${Re.slice(0,12)}..."`).join(", "),de=k.length>3?` and ${k.length-3} more`:"";q(`${k.length} call ID${k.length!==1?"s":""} not found: ${W}${de}`)}_.length>0&&k.length===0?n(""):k.length>0&&n(k.join(", ")),v(!1)},[r]),ye=o.useCallback(x=>{a(I=>I.filter(_=>_!==x)),E(I=>I.filter(_=>_!==x))},[]),be=o.useCallback((x,I)=>{E(_=>I?[...new Set([..._,x])]:_.filter(k=>k!==x))},[]),ie=o.useCallback(x=>{const I=se.map(_=>_.call_id);E(_=>x.target.checked?[...new Set([..._,...I])]:_.filter(k=>!I.includes(k)))},[se]),me=o.useCallback(()=>{E([]),a([])},[]),_e=o.useCallback((x,I)=>{N(I)},[]),f=o.useCallback((x,I)=>{X(_=>I?[...new Set([..._,x])]:_.filter(k=>k!==x))},[]),T=o.useCallback(x=>{X(x.target.checked?$.map(I=>I.critic_key):[])},[$]),P=o.useCallback(()=>{j.length===0||C.length===0||(G(null),J(null),re.mutate({call_ids:j,critic_keys:C}))},[j,C,re]),U=o.useCallback(()=>{G(null),J(null)},[]),ce=o.useCallback(()=>
2{if(!D)return;const x=new Date().toISOString(),I={script_id:s||"manual",created_at:x,results:D},_=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),k=URL.createObjectURL(_),W=document.createElement("a");W.href=k,W.download=`rome-evaluate-open-${x.replace(/[:.]/g,"-")}.json`,W.click(),URL.revokeObjectURL(k)},[D,s]),Ie=o.useCallback(x=>{var k;const I=(k=x.target.files)==null?void 0:k[0];if(!I)return;const _=new FileReader;_.onload=W=>{var de;try{const Re=JSON.parse((de=W.target)==null?void 0:de.result),Le=Re.results??Re;if(!Array.isArray(Le)){J("Invalid JSON format: expected an object with a 'results' array or a top-level array.");return}G(Le),J(null)}catch{J("Failed to parse JSON file. Please check the file format.")}},_.readAsText(I),x.target.value=""},[]),ge=se.length>0&&se.every(x=>j.includes(x.call_id)),F=se.some(x=>j.includes(x.call_id))&&!ge,we=$.length>0&&$.every(x=>C.includes(x.critic_key)),Ke=$.some(x=>C.includes(x.critic_key))&&!we,Xe=j.length>0&&C.length>0&&!re.isPending;return D?e.jsx(Be,{fullWidth:!0,children:e.jsxs(d,{sx:{p:3,maxWidth:1400,mx:"auto"},children:[e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:2,mb:2,flexWrap:"wrap"},children:[e.jsx(w,{variant:"outlined",startIcon:e.jsx(mt,{}),onClick:U,children:"Back"}),e.jsx(w,{variant:"outlined",startIcon:e.jsx(ft,{}),onClick:ce,children:"Download JSON"}),e.jsx(d,{sx:{flex:1}}),e.jsxs(Gt,{value:K,onChange:(x,I)=>Z(I),sx:{minHeight:32,"& .MuiTab-root":{minHeight:32,py:.5,fontSize:"0.8rem"}},children:[e.jsx(qe,{label:"Structured"}),e.jsx(qe,{label:"JSON"})]})]}),e.jsx(d,{sx:{overflow:"auto"},children:K===0?e.jsx(es,{results:D}):e.jsx(B,{variant:"outlined",sx:{p:2,bgcolor:"grey.50"},children:e.jsx(d,{component:"pre",sx:{m:0,fontSize:"0.75rem",fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(D,null,2)})})})]})}):e.jsx(Be,{fullWidth:!0,children:e.jsxs(d,{sx:{p:3,maxWidth:1400,mx:"auto"},children:[e.jsx(i,{variant:"h6",fontWeight:600,gutterBottom:!0,children:"Evaluate"}),e.jsx(i,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Run critics against calls. Load calls by Script ID, or enter Call IDs directly."}),e.jsx(B,{variant:"outlined",sx:{p:2,mb:2},children:e.jsxs(d,{sx:{display:"flex",gap:2,flexWrap:"wrap"},children:[e.jsxs(d,{sx:{flex:"1 1 45%",minWidth:280},children:[e.jsx(i,{variant:"caption",fontWeight:600,color:"text.secondary",sx:{mb:.5,display:"block"},children:"Load calls by Script ID"}),e.jsxs(d,{sx:{display:"flex",gap:1},children:[e.jsx(_t,{size:"small",fullWidth:!0,placeholder:"Enter a script UUID...",value:t,onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&oe(),InputProps:{startAdornment:e.jsx(Vs,{position:"start",children:e.jsx(Bs,{fontSize:"small",color:"action"})}),sx:{fontFamily:"monospace",fontSize:"0.85rem"}}}),e.jsx(w,{variant:"contained",size:"small",onClick:oe,disabled:!t.trim()||h,startIcon:h?e.jsx(M,{size:14,color:"inherit"}):void 0,sx:{whiteSpace:"nowrap"},children:h?"Verifying...":"Load Calls"})]}),y&&e.jsx(z,{severity:"error",onClose:()=>m(null),sx:{mt:1,py:0,"& .MuiAlert-message":{py:.5}},children:y}),s&&e.jsxs(i,{variant:"caption",color:"text.secondary",sx:{mt:.5,display:"block"},children:["Active:"," ",e.jsx("code",{style:{fontSize:"0.7rem"},children:s})]})]}),e.jsx(Ne,{orientation:"vertical",flexItem:!0}),e.jsxs(d,{sx:{flex:"1 1 45%",minWidth:280},children:[e.jsx(i,{variant:"caption",fontWeight:600,color:"text.secondary",sx:{mb:.5,display:"block"},children:"Add Call IDs directly"}),e.jsxs(d,{sx:{display:"flex",gap:1},children:[e.jsx(_t,{size:"small",fullWidth:!0,placeholder:"Paste call UUIDs (comma or newline separated). Ctrl+Enter to add.",value:r,onChange:x=>n(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.ctrlKey||x.metaKey)&&(x.preventDefault(),je())},multiline:!0,maxRows:3,InputProps:{sx:{fontFamily:"monospace",fontSize:"0.85rem"}}}),e.jsx(w,{variant:"outlined",size:"small",startIcon:S?e.jsx(M,{size:14}):e.jsx(nn,{}),onClick:je,disabled:!r.trim()||S,sx:{whiteSpace:"nowrap",alignSelf:"flex-start"},children:S?"Verifying...":"Add"})]}),R&&e.jsx(z,{severity:"warning",onClose:()=>q(null),sx:{mt:1,py:0,"& .MuiAlert-message":{py:.5}},children:R}),u.length>0&&e.jsxs(d,{sx:{mt:1,display:"flex",gap:.5,flexWrap:"wrap",alignItems:"center"},children:[e.jsxs(i,{variant:"caption",color:"text.secondary",children:["Manual (",u.length,"):"]}),u.slice(0,8).map(x=>e.jsx(A,{label:`${x.slice(0,8)}...`,size:"small",onDelete:()=>ye(x),sx:{fontFamily:"monospace",fontSize:"0.7rem"}},x)),u.length>8&&e.jsxs(i,{variant:"caption",color:"text.secondary",children:["+",u.length-8," more"]})]})]})]})}),e.jsxs(d,{sx:{display:"flex",gap:2,minHeight:0},children:[e.jsxs(B,{variant:"outlined",sx:{flex:"1 1 60%",minWidth:0,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsxs(d,{sx:{p:2,pb:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(i,{variant:"subtitle2",children:["Calls",j.length>0&&e.jsx(A,{label:j.length,size:"small",color:"primary",sx:{ml:1,height:20,minWidth:20}})]}),s&&e.jsx(w,{size:"small",startIcon:e.jsx(At,{}),onClick:()=>te(),disabled:Y,children:"Refresh"})]}),!s&&u.length===0?e.jsx(i,{variant:"body2",color:"text.secondary",sx:{p:2,pt:0},children:"Enter a Script ID to load calls, or add Call IDs directly above."}):!s&&u.length>0?e.jsx(d,{sx:{p:2,pt:0},children:e.jsxs(i,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:[u.length," call",u.length!==1?"s":""," added manually."]})}):Y?e.jsx(d,{sx:{display:"flex",justifyContent:"center",p:4},children:e.jsx(M,{size:24})}):he?e.jsx(z,{severity:"error",sx:{m:2},children:"Failed to load calls"}):Ce===0?e.jsxs(i,{variant:"body2",color:"text.secondary",sx:{p:2,pt:0},children:["No calls found for this script.",u.length>0&&` ${u.length} manual call(s) still selected.`]}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{sx:{flex:1,minHeight:0,overflow:"auto"},children:e.jsxs(Ee,{size:"small",stickyHeader:!0,children:[e.jsx(De,{children:e.jsxs(H,{
2children:[e.jsx(g,{padding:"checkbox",children:e.jsx(ue,{indeterminate:F,checked:ge,onChange:ie})}),e.jsx(g,{children:"Call ID"}),e.jsx(g,{children:"Status"}),e.jsx(g,{children:"Patient"}),e.jsx(g,{children:"Date"}),e.jsx(g,{align:"right",children:"Duration"})]})}),e.jsx(Te,{children:se.map(x=>e.jsx(rr,{call:x,selected:j.includes(x.call_id),onSelect:be},x.call_id))})]})}),e.jsx(pt,{component:"div",count:Ce,page:ae,onPageChange:_e,rowsPerPage:Q,rowsPerPageOptions:[Q]})]}),j.length>0&&e.jsx(d,{sx:{p:2,pt:0},children:e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"wrap"},children:[e.jsxs(i,{variant:"body2",color:"text.secondary",children:["Selected (",j.length,"):"]}),j.slice(0,5).map(x=>e.jsx(A,{label:`${x.slice(0,8)}...`,size:"small",onDelete:()=>be(x,!1)},x)),j.length>5&&e.jsxs(i,{variant:"caption",color:"text.secondary",children:["+",j.length-5," more"]}),e.jsx(w,{size:"small",startIcon:e.jsx(Ut,{}),onClick:me,children:"Clear"})]})})]}),e.jsxs(B,{variant:"outlined",sx:{flex:"1 1 40%",minWidth:0,display:"flex",flexDirection:"column",minHeight:0,maxHeight:520},children:[e.jsx(d,{sx:{p:2,pb:1},children:e.jsxs(i,{variant:"subtitle2",children:["Critic Catalog",C.length>0&&e.jsx(A,{label:C.length,size:"small",color:"primary",sx:{ml:1,height:20,minWidth:20}})]})}),ze?e.jsx(d,{sx:{display:"flex",justifyContent:"center",p:4},children:e.jsx(M,{size:24})}):We?e.jsx(z,{severity:"error",sx:{m:2},children:"Failed to load critics"}):e.jsx(Pe,{sx:{flex:1,minHeight:0,overflow:"auto"},children:e.jsxs(Ee,{size:"small",stickyHeader:!0,children:[e.jsx(De,{children:e.jsxs(H,{children:[e.jsx(g,{padding:"checkbox",children:e.jsx(ue,{indeterminate:Ke,checked:we,onChange:T})}),e.jsx(g,{sx:{fontWeight:600},children:"Name"}),e.jsx(g,{sx:{fontWeight:600},children:"Type"})]})}),e.jsxs(Te,{children:[$.map(x=>e.jsxs(H,{hover:!0,onClick:()=>f(x.critic_key,!C.includes(x.critic_key)),sx:{cursor:"pointer"},children:[e.jsx(g,{padding:"checkbox",children:e.jsx(ue,{checked:C.includes(x.critic_key)})}),e.jsxs(g,{children:[e.jsx(i,{variant:"body2",fontWeight:500,children:x.critic_name}),e.jsx(i,{variant:"caption",color:"text.secondary",children:x.critic_description})]}),e.jsx(g,{children:e.jsx(Qt,{type:x.critic_type})})]},x.critic_key)),$.length===0&&e.jsx(H,{children:e.jsx(g,{colSpan:3,align:"center",children:e.jsx(i,{variant:"body2",color:"text.secondary",sx:{py:2},children:"No critics available"})})})]})]})})]})]}),e.jsxs(d,{sx:{mt:2},children:[fe&&e.jsx(z,{severity:"error",onClose:()=>J(null),sx:{mb:2},children:fe}),e.jsxs(d,{sx:{display:"flex",gap:1},children:[e.jsx(w,{variant:"contained",sx:{flex:1},startIcon:re.isPending?e.jsx(M,{size:18,color:"inherit"}):e.jsx(gt,{}),onClick:P,disabled:!Xe,children:re.isPending?"Running Critics...":j.length===0?"Select calls to run critics":C.length===0?"Select critics to run":`Run ${C.length} critic${C.length!==1?"s":""} on ${j.length} call${j.length!==1?"s":""}`}),e.jsx("input",{ref:ee,type:"file",accept:".json",hidden:!0,onChange:Ie}),e.jsx(w,{variant:"outlined",startIcon:e.jsx(Nt,{}),onClick:()=>{var x;return(x=ee.current)==null?void 0:x.click()},children:"Upload Results"})]})]})]})})},hi=()=>e.jsxs(Cs,{children:[e.jsx(pe,{path:"/",element:e.jsx(kt,{})}),e.jsx(pe,{path:"/getting-started",element:e.jsx(kt,{})}),e.jsx(pe,{path:"/session",element:e.jsx(nr,{})}),e.jsx(pe,{path:"/evaluate",element:e.jsx(ir,{})}),e.jsx(pe,{path:"/critic-run-configs",element:e.jsx(Oe,{to:"/critics/run",replace:!0})}),e.jsx(pe,{path:"/critics",element:e.jsx(Oe,{to:"/critics/run",replace:!0})}),e.jsx(pe,{path:"/critic-results",element:e.jsx(Oe,{to:"/critics/results",replace:!0})}),e.jsx(pe,{path:"/analyze",element:e.jsx(Oe,{to:"/critics/analyze",replace:!0})}),e.jsx(pe,{path:"/scope/*",element:e.jsx(Oe,{to:"/self-service/scope",replace:!0})})]});export{hi 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.