1import{r as l,j as e,a7 as x,I as g,f3 as pt,aw as I,aq as en,a_ as U,an as N,cb as kt,aQ as Je,aR as Ze,aS as Ve,bU as tn,c1 as Ut,aM as ct,aO as mt,hO as dn,aT as et,bV as un,bb as pn,a3 as mn,cj as fn,bz as gn,bQ as _n,c7 as hn,aN as tt,P as xn}from"./index-BB9zIF0e.js";import{d as vn}from"./KeyboardArrowDown-CLBvn_-u.js";import{M as bn}from"./CallSettingsApi-BsebCS0R.js";import{S as yn}from"./SectionHeader-C0ot8i4_.js";import{O as L,v as nn,w as jn,x as Cn,y as Sn,z as wn,B as Pn,E as In,F as En,G as kn}from"./RequireValidCallId-CiFrEaDa.js";import{H as Ce,M as Q,a as Rn,L as qt,T as An,b as Tn,c as Mn,d as zt,e as w,f as Dn,k as Ln,ai as Wt}from"./RootRoute.app-L3TaSlVb.js";import{R as bt,d as On}from"./ReviewQueueConfigApi-DUQXC_rj.js";import{S as ft}from"./AgentUtils-njy3Sx04.js";import{g as Rt}from"./scriptLabelUtils-BE3VwbCi.js";import{a2 as Nn}from"./switch-DFTrMl4D.js";import{b as Un}from"./Add-CKUE0xUV.js";import{C as qn}from"./Grid-CNox8AfI.js";import{C as zn}from"./CardContent-9ktYs0gW.js";import{R as Wn}from"./RadioGroup-ChUbcXFz.js";import{F as je}from"./FormControlLabel-BFRZTghq.js";import{R as Ft}from"./Radio-UDRpwIhD.js";import{S as pe}from"./Switch-BfFRshBv.js";import{P as Fn}from"./Pagination-BdphJqZ1.js";import{L as $t}from"./Link-D0kJiXvC.js";import"./index-D7DospT7.js";import"./useProps-C-9XgY24.js";import"./ActionButton-MAZAsZ58.js";import"./LinearProgress-BuKEurAE.js";import"./PlayArrow-C15e9tiW.js";import"./ScriptUtils-Bup7X2Om.js";import"./dropdown-menu-DzZ8egTM.js";import"./useCallPlayback-NAQdWjI8.js";import"./CallChat-DcJhKbFq.js";import"./alert-dialog-D3CcRw3a.js";import"./CodeEditor-D2ai3Smk.js";import"./SimpleSelect-DJPL2ndE.js";import"./Slider-BCPBlpel.js";import"./LanguageTypes-B_iKtSAt.js";import"./BarShortDetailsEntry-C62EpU_F.js";import"./CallDialerSetup-CC6nQy-T.js";import"./CallDevConfigViewer--VwypO6F.js";import"./PatientRecordCard-BxgFKMFv.js";import"./DemoPatientApi-DqvVgYqu.js";import"./CallErrorDialog-D9oqVVuq.js";import"./react-hotkeys-hook.esm-DH3789-y.js";import"./Warning--pz-2WJh.js";import"./AudioPlayer-_aCt-pRS.js";import"./label-Ddj_7XnV.js";import"./SearchScriptDropdown-DeFFCxH4.js";import"./EditOutlined-W3cjA5yM.js";import"./ExpandLess-BD_hcQNB.js";import"./OpenInNew-B6jFXBGU.js";import"./useCallManager-Dixsyquf.js";import"./ClickToEditPopover-OYZzE8u5.js";import"./FormGroup-Cv3PpDNK.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},n=new Error().stack;
1n&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[n]="7a248853-b23d-4a05-88c0-1f221baa9593",t._sentryDebugIdIdentifier="sentry-dbid-7a248853-b23d-4a05-88c0-1f221baa9593")}catch{}})();function $n(t,n,s={leading:!1}){const[d,r]=l.useState(t),S=l.useRef(!1),P=l.useRef(null),G=l.useRef(!1),E=l.useCallback(()=>window.clearTimeout(P.current),[]);return l.useEffect(()=>{S.current&&(!G.current&&s.leading?(G.current=!0,r(t)):(E(),P.current=window.setTimeout(()=>{G.current=!1,r(t)},n)))},[t,s.leading,n]),l.useEffect(()=>(S.current=!0,E),[]),[d,E]}function Hn({criticScriptIds:t,reviewScriptIds:n}){if(n.length===0)return!0;if(t.length===0)return!1;const s=new Set(n);return t.every(d=>s.has(d))}const Bn=[{value:"generate_todo",label:"Create todo"},{value:"slack_message",label:"Slack message"}],Kn=[{value:"patient_call_review",label:"Call Review"},{value:"patient_escalation",label:"Nurse / Escalation"},{value:"clinical_review",label:"Clinical Review"},{value:"patient_callback",label:"Callback"},{value:"patient_escalation_failure",label:"Escalation Failure"},{value:"client_follow_up",label:"Client Follow-up"},{value:"escalation_case_review",label:"Case Review"},{value:"data_annotation",label:"Data Annotation"},{value:"rule_based_review",label:"Rule-based Review"}],Qn=[{value:L.alwaysCreate,label:"Always create another todo"},{value:L.mergeOpen,label:"Merge open todos; create a new one if completed"},{value:L.mergeOpenSkipCompleted,label:"Merge open todos; do nothing if completed"}],Gn={[L.alwaysCreate]:"Never merge. Existing pending, draft, completed, or archived todos are left alone.",[L.mergeOpen]:"Pending or draft: append this message and leave the todo pending. Completed or archived: create a new todo.",[L.mergeOpenSkipCompleted]:"Pending or draft: append and leave pending. Completed: do nothing. Archived or none: create a new todo."},rn=t=>t==="patient_escalation"?L.mergeOpen:t==="clinical_review"?L.mergeOpenSkipCompleted:L.alwaysCreate,gt=(t,n)=>t==="skip_if_exists"||t===L.mergeOpen?L.mergeOpen:t==="skip_if_completed"||t===L.mergeOpenSkipCompleted?L.mergeOpenSkipCompleted:t===L.alwaysCreate?L.alwaysCreate:rn(n),_t=t=>t.optional_todo_application_policy??t.if_exists,At=500,Yn=[{value:"urgent",label:"Urgent"},{value:"high",label:"High"},{value:"medium",label:"Medium"},{value:"low",label:"Low"}],Xn=[{value:"minutes",label:"Minutes"},{value:"hours",label:"Hours"},{value:"days",label:"Days"}],Jn=/^[a-z0-9][a-z0-9_-]*$/,Dt=()=>({_uiKey:pt(),action_type:"generate_todo",todo_type:"patient_call_review",optional_todo_application_policy:L.alwaysCreate,priority:"high",due_in:{hours:24}}),Zn=(t,n)=>n==="slack_message"?{_uiKey:t._uiKey,action_type:"slack_message",channel:""}:{...Dt(),_uiKey:t._uiKey},Vn=(t,n)=>{if(n==="rule_based_review")return{_uiKey:t._uiKey,action_type:"generate_todo",todo_type:"rule_based_review"};const s=rn(n),d=t.action_type==="generate_todo"&&t.todo_type!=="rule_based_review"?t:null;return d?{...d,todo_type:n,optional_todo_application_policy:s}:{...Dt(),_uiKey:t._uiKey,todo_type:n,optional_todo_application_policy:s}};function Tt(t){return t==null?void 0:t.map(n=>n.action_type!=="generate_todo"?{...n,_uiKey:pt()}:n.todo_type==="rule_based_review"?{...n,_uiKey:pt()}:{...n,optional_todo_application_policy:gt(_t(n),n.todo_type),_uiKey:pt()})}const Mt=t=>t.map(n=>{var d;if(n.action_type==="slack_message")return{action_type:"slack_message",channel:n.channel.trim()};if(n.todo_type==="rule_based_review"){if(!n.review_queue_config_id)throw new Error("Rule-based Review actions require a Review Config");return{action_type:"generate_todo",todo_type:"rule_based_review",review_queue_config_id:n.review_queue_config_id}}const s=(d=n.note)==null?void 0:d.trim();return{action_type:"generate_todo",todo_type:n.todo_type,optional_todo_application_policy:gt(_t(n),n.todo_type),priority:n.priority,due_in:{...n.due_in},...s?{note:s}:{}}}),er=(t,n)=>JSON.stringify(Mt(t))===JSON.stringify(Mt(n)),tr=t=>{var s;const n=new Set;for(const d of t)if(d.action_type==="generate_todo"&&d.todo_type==="rule_based_review"){const{review_queue_config_id:r}=d;if(r){if(n.has(r))return"Each Rule-based Review action must use a different Review Config.";n.add(r)}}for(const d of t){if(d.action_type==="slack_message"){const S=d.channel.trim();if(!S)return"Enter a Slack channel for every Slack action.";if(S.length>255||!Jn.test(S))return"Slack channels must start with a lowercase letter or number and contain only lowercase letters, numbers, hyphens, or underscores. Do not include #.";continue}if(d.todo_type==="rule_based_review"){if(!d.review_queue_config_id)return"Select a Review Config for every Rule-based Review action.";continue}const r=Object.entries(d.due_in).filter(([,S])=>S!=null);if(r.length!==1||!Number.isInteger(r[0][1])||Number(r[0][1])<=0)return"Todo due time must be a positive whole number with exactly one unit.";if((((s=d.note)==null?void 0:s.trim().length)??0)>At)return`Todo note must be ${At} characters or fewer.`}return null},nr=t=>{for(const n of["minutes","hours","days"]){const s=t.due_in[n];if(s!=null)return{unit:n,value:s}}return{unit:"hours",value:24}},sn=({actions:t,onChange:n,readOnly:s=!1,reviewQueueConfigs:d,prioritySlas:r,criticScriptIds:S,reviewQueueConfigsLoading:P=!1,reviewQueueConfigsError:G})=>{const E=(_,b)=>{const y=[...t];y[_]=b,n==null||n(y)},te=l.useMemo(()=>{const _=[];for(const b of t)b.action_type==="generate_todo"&&b.todo_type==="rule_based_review"&&b.review_queue_config_id&&_.push(b.review_queue_config_id);return _},[t]);return e.jsxs(x,{children:[e.jsx(g,{variant:"subtitle2",children:"Actions on critic failure"}),e.jsx(g,{variant:"caption",color:"text.secondary",component:"p",children:"Optional. Each action runs on critic failure. For todos, pick a queue and what to do if a todo already exists."}),e.jsx(Ce,{spacing:1.5,sx:{mt:1.5},children:t.map((_,b)=>{const y=_.action_type==="generate_todo"&&_.todo_type==="rule_based_review"?_:null,ne=_.action_type==="generate_todo"&&_.todo_type!=="rule_based_review"?_:null,O=ne?nr(ne):null,$=new Set(te.filter(c=>c!==(y==null?void 0:y.review_queue_config_id))),j=y?(d==null?void 0:d.find(c=>c.configId===y.review_queue_config_id))??(y.review_queue_config&&y.review_queue_config_id?{c
1onfigId:y.review_queue_config_id,displayName:y.review_queue_config.display_name,status:y.review_queue_config.status,defaultPriority:y.review_queue_config.default_priority,sampleRate:y.review_queue_config.sample_rate,dueInHours:y.review_queue_config.due_in_hours}:void 0):void 0,k=(j==null?void 0:j.status)===bt.disabled,H=j?(r??[]).find(c=>c.priority===j.defaultPriority)??("dueInHours"in j?{priority:j.defaultPriority,durationHours:j.dueInHours}:void 0):void 0,a=j!=null&&"scriptIds"in j&&!Hn({criticScriptIds:S??[],reviewScriptIds:j.scriptIds}),D=(d??[]).filter(c=>c.status!==bt.disabled||c.configId===(y==null?void 0:y.review_queue_config_id)),Te=j&&!D.some(c=>c.configId===j.configId)?[...D,j]:D;return e.jsx(qn,{variant:"outlined",children:e.jsx(zn,{sx:{pb:"16px !important"},children:e.jsxs(Ce,{spacing:1.5,children:[e.jsxs(x,{sx:{display:"flex",gap:1,alignItems:"center"},children:[e.jsx(I,{select:!0,fullWidth:!0,size:"small",label:"Action type",value:_.action_type,SelectProps:{readOnly:s},onChange:s?void 0:c=>{const Y=c.target.value;E(b,Zn(_,Y))},children:Bn.map(c=>e.jsx(Q,{value:c.value,children:c.label},c.value))}),!s&&e.jsx(en,{"aria-label":"Remove critic action",onClick:()=>n==null?void 0:n(t.filter((c,Y)=>Y!==b)),children:e.jsx(Nn,{})})]}),_.action_type==="slack_message"?e.jsx(I,{fullWidth:!0,size:"small",required:!0,label:"Slack channel",placeholder:"clinical-alerts",value:_.channel,inputProps:{maxLength:255},InputProps:{readOnly:s},helperText:s?void 0:"Lowercase channel name without #. Snow validates access when you save.",onChange:s?void 0:c=>E(b,{..._,channel:c.target.value})}):e.jsxs(e.Fragment,{children:[e.jsx(g,{variant:"subtitle2",children:_.todo_type==="rule_based_review"?"Rule-based Review":"Todo"}),e.jsx(I,{select:!0,fullWidth:!0,size:"small",label:"Queue",value:_.todo_type,helperText:"Which todo list this lands on.",SelectProps:{readOnly:s},onChange:s?void 0:c=>E(b,Vn(_,c.target.value)),children:Kn.map(c=>e.jsx(Q,{value:c.value,children:c.label},c.value))}),_.todo_type==="rule_based_review"?e.jsxs(e.Fragment,{children:[e.jsx(I,{select:!0,fullWidth:!0,size:"small",label:"Review Config",value:_.review_queue_config_id??"",disabled:P,SelectProps:{readOnly:s},helperText:P?"Loading Review Configsâ¦":"Select the Review Queue Config to use.",onChange:s?void 0:c=>E(b,{..._,review_queue_config_id:c.target.value}),children:Te.map(c=>e.jsx(Q,{value:c.configId,disabled:c.status===bt.disabled||$.has(c.configId),children:c.displayName},c.configId))}),G&&e.jsx(U,{severity:"error",children:"Unable to load Review Configs. You may not be authorized to select one."}),k&&e.jsx(U,{severity:"warning",children:"The selected Review Config is currently disabled. It will not create review todos until re-enabled."}),a&&e.jsx(U,{severity:"warning",children:"This Review Config does not cover all scripts the critic runs on. Some critic failures may have no review created."}),j&&e.jsxs(x,{sx:{display:"flex",gap:2,flexWrap:"wrap",pt:.5},children:[e.jsxs(g,{variant:"body2",children:[e.jsx("strong",{children:"Priority:"})," ",j.defaultPriority]}),e.jsxs(g,{variant:"body2",children:[e.jsx("strong",{children:"Due in:"})," ",H!=null?`${H.durationHours}h`:"â"]}),e.jsxs(g,{variant:"body2",children:[e.jsx("strong",{children:"Status:"})," ",j.status]}),e.jsxs(g,{variant:"body2",children:[e.jsx("strong",{children:"Sample rate:"})," ",j.sampleRate.toFixed(0),"%"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{select:!0,fullWidth:!0,size:"small",label:"If this call already has a todo in this queue",value:gt(_t(_),_.todo_type),helperText:Gn[gt(_t(_),_.todo_type)],SelectProps:{readOnly:s},onChange:s?void 0:c=>E(b,{..._,optional_todo_application_policy:c.target.value}),children:Qn.map(c=>e.jsx(Q,{value:c.value,children:c.label},c.value))}),e.jsx(I,{select:!0,fullWidth:!0,size:"small",label:"Priority",value:_.priority,SelectProps:{readOnly:s},onChange:s?void 0:c=>E(b,{..._,priority:c.target.value}),children:Yn.map(c=>e.jsx(Q,{value:c.value,children:c.label},c.value))}),e.jsxs(x,{sx:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:1.5},children:[e.jsx(I,{size:"small",required:!0,label:"Due in",type:"number",value:O.value,inputProps:{min:1,step:1},InputProps:{readOnly:s},onChange:s?void 0:c=>E(b,{..._,due_in:{[O.unit]:Number(c.target.value)}})}),e.jsx(I,{select:!0,size:"small",label:"Due unit",value:O.unit,SelectProps:{readOnly:s},onChange:s?void 0:c=>E(b,{..._,due_in:{[c.target.value]:O.value}}),children:Xn.map(c=>e.jsx(Q,{value:c.value,children:c.label},c.value))})]}),e.jsx(I,{fullWidth:!0,size:"small",label:"Note",placeholder:"Optional note shown on the todo",value:_.note??"",inputProps:{maxLength:At},InputProps:{readOnly:s},multiline:!0,minRows:2,helperText:s?void 0:"Appears in the todo Action column.",onCh
1ange:s?void 0:c=>E(b,{..._,note:c.target.value})})]})]})]})})},_._uiKey)})}),s&&t.length===0&&e.jsx(g,{variant:"body2",sx:{mt:1.5},children:"No actions configured."}),!s&&e.jsx(N,{startIcon:e.jsx(Un,{}),variant:"outlined",size:"small",sx:{mt:1.5},onClick:()=>n==null?void 0:n([...t,Dt()]),children:"Add action"})]})},rr=({actions:t})=>{const n=l.useMemo(()=>Tt(t),[t]);return n===void 0?e.jsxs(x,{children:[e.jsx(g,{variant:"subtitle2",children:"Actions on critic failure"}),e.jsx(g,{variant:"body2",sx:{mt:1.5},children:"Critic actions were not loaded."})]}):e.jsx(sn,{actions:n,readOnly:!0})},ir=({actions:t})=>{let n;if(t===void 0)n=["Actions not loaded"];else if(t.length===0)n=["No actions"];else{const s=t.filter(r=>r.action_type==="generate_todo").length,d=t.length-s;n=[],s>0&&n.push(`Todo (${s})`),d>0&&n.push(`Slack (${d})`)}return e.jsx(g,{variant:"caption",color:"text.secondary",component:"div",children:n.map(s=>e.jsx(x,{component:"span",display:"block",children:s},s))})},sr=3e3,Ht=[{label:"Inbound",value:"inbound"},{label:"Outbound",value:"outbound"}],or=[{label:"Low",value:"low"},{label:"Medium",value:"medium"},{label:"High",value:"high"}],ar={onMouseDown:t=>{t.preventDefault()}},lr=dn({stringify:t=>`${t.partner_name??""} ${t.partner_id??""}`.trim()}),cr=["tag_id","uuid","tag_uuid","critic_tag_id","criticTagId","tagUUID","tagId","id","pk","tag"];function dr(t){return t==null?null:typeof t=="string"&&t.trim()!==""?t.trim():typeof t=="number"&&Number.isFinite(t)?String(t):null}function ur(t){for(const n of cr){const s=dr(t[n]);if(s)return s}return""}function pr(t){for(const n of["tag_label","label","name","display_name","title","tag"]){const s=t[n];if(typeof s=="string"&&s.trim()!=="")return s.trim()}return""}function mr(t){const n=[],s=new Set;for(const d of t){const r=ur(d);if(!r||s.has(r))continue;s.add(r);const S=pr(d);n.push({id:r,label:S||r})}return n.sort((d,r)=>d.label.localeCompare(r.label,void 0,{sensitivity:"base"})),n}function Bt(t){var n;if(t instanceof un){const s=(n=t.jsonResponse)==null?void 0:n.error;if(s&&typeof s.message=="string")return s.message;if(typeof t.message=="string"&&t.message&&t.message!=="[object Object]")return t.message}return t instanceof Error?t.message:"Request failed."}function dt(t){return t==null?"":String(t)}function Xe(t,n){return t!=null&&Object.prototype.hasOwnProperty.call(t,n)}function Kt(t){const n=t.trim();if(!/^[1-9]\d*$/.test(n))return null;const s=Number(n);return Number.isSafeInteger(s)?s:null}function Qt(t){const n=t.trim();if(!/^\d+$/.test(n))return null;const s=Number(n);return Number.isSafeInteger(s)?s:null}const Gt=({open:t,onClose:n,onCreated:s,editConfigId:d,initialValues:r,queuePriorityAvailability:S})=>{var Ot;const P=!!d,G=()=>r!=null&&r.critic_version_id?"critic_version_id":"tag_id",E=()=>(r==null?void 0:r.tag_id)??(r==null?void 0:r.critic_version_id)??"",[te,_]=l.useState((Ot=r==null?void 0:r.partner_ids)!=null&&Ot.length?r.partner_ids:r!=null&&r.partner_id?[r.partner_id]:[]),[b,y]=l.useState(G),[ne,O]=l.useState(E),[$,j]=l.useState((r==null?void 0:r.is_global)??!1),[k,H]=l.useState((r==null?void 0:r.script_ids)??[]),[a,D]=l.useState(""),[Te]=$n(a,300),[c,Y]=l.useState(r!=null&&r.call_types?r.call_types.split(";").filter(Boolean):[]),[me,Ne]=l.useState((r==null?void 0:r.name)??""),[M,X]=l.useState((r==null?void 0:r.description)??""),[fe,ht]=l.useState((r==null?void 0:r.queue_priority)??"low"),Ue=(S==null?void 0:S[fe])??!0,nt=Xe(r,"use_script_sampling_rate"),ge=Xe(r,"min_num_utterances"),Se=Xe(r,"max_num_utterances"),qe=Xe(r,"min_call_duration_seconds"),re=Xe(r,"max_call_duration_seconds"),[J,Z]=l.useState((r==null?void 0:r.use_script_sampling_rate)??!1),[C,we]=l.useState((r==null?void 0:r.min_num_utterances)!=null),[B,ze]=l.useState((r==null?void 0:r.max_num_utterances)!=null),[oe,ae]=l.useState(dt(r==null?void 0:r.min_num_utterances)),[We,q]=l.useState(dt(r==null?void 0:r.max_num_utterances)),[V,_e]=l.useState((r==null?void 0:r.min_call_duration_seconds)!=null),[ee,Fe]=l.useState((r==null?void 0:r.max_call_duration_seconds)!=null),[ie,rt]=l.useState(dt(r==null?void 0:r.min_call_duration_seconds)),[Pe,it]=l.useState(dt(r==null?void 0:r.max_call_duration_seconds)),[le,Me]=l.useState(()=>(r==null?void 0:r.critic_actions)===void 0?P?void 0:[]:Tt(r.critic_actions)),[De,$e]=l.useState(r==null?void 0:r.critic_actions),[He,he]=l.useState(null),[Be,T]=l.useState(null),[Ie,Ke]=l.useState(""),xt=t&&P&&(r==null?void 0:r.critic_actions)===void 0,{data:Qe,isPending:ce}=nn(xt?d??null:null),Le=Qe==null?void 0:Qe.critic_run_config.critic_actions;l.useEffect(()=>{De!==void 0||Le===void 0||($e(Le),Me(Tt(Le)))},[De,Le]);const Ge=l.useMemo(()=>({offset:0,limit:sr}),[]),{data:z,isPending:K}=Rn(Ge,5*60*1e3,t),xe=l.useMemo(()=>(z==null?void 0:z.partners)??[],[z]),{data:de,isPending:Ee,isError:Oe,error:Ye}=jn(t),ve=l.useMemo(()=>mr((de==null?void 0:de.tags)??[]),[de==null?void 0:de.tags]),st=l.useMemo(()=>{const o=ne.trim();return o?ve.find(u=>u.id===o)??null:null},[ve,ne]),{data:ke,isPending:i}=kt({scriptStatuses:[ft.ACTIVE,ft.DEMO],search:Te||void 0,limit:25,onlyIgloo:!0},{enabled:t}),{data:p,isLoading:m,error:f}=On({enabled:t}),{data:h}=kt({scriptIds:k,limit:Math.max(k.length,1)},{enabled:t&&k.length>0}),v=l.useMemo(()=>{const o=((ke==null?void 0:ke.scripts)??[]).map(A=>({label:Rt(A),value:A.script_id})),u=new Map(((h==null?void 0:h.scripts)??[]).map(A=>[A.script_id,Rt(A)])),R=k.filter(A=>!o.some(ye=>ye.value===A)&&u.has(A)).map(A=>({label:u.get(A)??A,value:A}));return[...o,...R]},[ke,h,k]),F=l.useMemo(()=>k.map(o=>v.find(u=>u.value===o)??{label:o,value:o}),[k,v]),be=Cn(),Re=Sn(),ot=P?Re:be;l.useEffect(()=>{t&&T(null)},[t]);const at=()=>{ot.isPending||(be.reset(),Re.reset(),_([]),Ke(""),y("tag_id"),O(""),j(!1),Z(!1),we(!1),ze(!1),ae(""),q
1(""),_e(!1),Fe(!1),rt(""),it(""),Me([]),$e(void 0),he(null),H([]),D(""),Y([]),Ne(""),X(""),T(null),n())},Lt=o=>{d&&Re.mutate({configId:d,body:o},{onSuccess:u=>{s==null||s(u.critic_run_config),at()},onError:u=>{T(Bt(u))}})},an=()=>{var Nt;T(null);const o=ne.trim();if(!o){T(b==="tag_id"?"Select a critic tag.":"Enter a critic version id.");return}if(!$&&te.length===0){T("Turn on All Partners, or choose at least one partner. Script is optional.");return}if(me.trim()===""){T("Name is required.");return}const u=C?Qt(oe):null;if(C&&u===null){T("Enter a non-negative integer for the minimum number of utterances.");return}const R=B?Qt(We):null;if(B&&R===null){T("Enter a non-negative integer for the maximum number of utterances.");return}if(u!==null&&R!==null&&u>R){T("Minimum number of utterances must be less than or equal to maximum number of utterances.");return}const A=V?Kt(ie):null;if(V&&A===null){T("Enter a positive integer for the minimum call duration.");return}const ye=ee?Kt(Pe):null;if(ee&&ye===null){T("Enter a positive integer for the maximum call duration.");return}if(A!==null&&ye!==null&&A>ye){T("Minimum call duration must be less than or equal to maximum call duration.");return}const vt=P&&De!==void 0&&le!==void 0&&!er(De,le),ln=!P||vt;let lt;if(ln){if(le===void 0){T("Critic actions have not finished loading.");return}const W=tr(le);if(W){T(W);return}lt=Mt(le)}if(P&&d){const W={enabled:(r==null?void 0:r.enabled)??!1,is_global:$,...b==="tag_id"?{tag_id:o,critic_version_id:null}:{critic_version_id:o,tag_id:null},partner_ids:$?[]:te,script_ids:k,call_types:c.length>0?c.join(";"):null,queue_priority:fe,name:me.trim()!==""?me.trim():null,description:M.trim()!==""?M.trim():null,...vt&<!==void 0?{critic_actions:lt}:{}};(nt||J)&&(W.use_script_sampling_rate=J),(ge||C)&&(W.min_num_utterances=C?u:null),(Se||B)&&(W.max_num_utterances=B?R:null),(qe||V)&&(W.min_call_duration_seconds=V?A:null),(re||ee)&&(W.max_call_duration_seconds=ee?ye:null);const cn=(r==null?void 0:r.enabled)===!0&&((Nt=r.approval_status)==null?void 0:Nt.trim().toLowerCase())==="approved";if(vt&&cn){he(W);return}Lt(W);return}const ue={enabled:!1,is_global:$,use_script_sampling_rate:J,queue_priority:fe,name:me.trim(),critic_actions:lt??[],...b==="tag_id"?{tag_id:o}:{critic_version_id:o}};!$&&te.length>0&&(ue.partner_ids=te),k.length>0&&(ue.script_ids=k),c.length>0&&(ue.call_types=c.join(";")),C&&u!==null&&(ue.min_num_utterances=u),B&&R!==null&&(ue.max_num_utterances=R),V&&A!==null&&(ue.min_call_duration_seconds=A),ee&&ye!==null&&(ue.max_call_duration_seconds=ye),M.trim()!==""&&(ue.description=M.trim()),be.mutate(ue,{onSuccess:W=>{s==null||s(W.critic_run_config),at()},onError:W=>{T(Bt(W))}})};return e.jsxs(Je,{open:t,onClose:at,maxWidth:"sm",fullWidth:!0,BackdropProps:ar,children:[e.jsx(Ze,{children:P?"Edit Critic Run Config":"Create Critic Run Config"}),e.jsx(Ve,{children:e.jsxs(x,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[e.jsx(g,{variant:"caption",color:"text.secondary",component:"p",sx:{m:0},children:"A critic tag or critic version ID is required. Either turn on All Partners (partner is cleared and disabled; script optional), or with All Partners off choose a partner. Script is optional."}),Be&&e.jsx(U,{severity:"error",children:Be}),e.jsx(I,{label:"Name",value:me,onChange:o=>Ne(o.target.value),variant:"outlined",fullWidth:!0,inputProps:{maxLength:255}}),e.jsx(I,{label:"Description",value:M,onChange:o=>X(o.target.value),variant:"outlined",fullWidth:!0,multiline:!0,minRows:2}),e.jsxs(tn,{children:[e.jsx(Ut,{id:"critic-config-select-critic-label",focused:!1,sx:{mb:1.5,display:"block"},children:"Select Critic"}),e.jsxs(Wn,{"aria-labelledby":"critic-config-select-critic-label",row:!0,value:b,onChange:(o,u)=>{y(u),O("")},children:[e.jsx(je,{value:"tag_id",control:e.jsx(Ft,{size:"small"}),label:"Critic tag"}),e.jsx(je,{value:"critic_version_id",control:e.jsx(Ft,{size:"small"}),label:"Critic version ID"})]})]}),b==="tag_id"?e.jsxs(e.Fragment,{children:[Oe&&e.jsx(U,{severity:"warning",children:Ye instanceof Error?Ye.message:"Could not load critic tags."}),e.jsx(ct,{options:ve,loading:Ee,value:st,onChange:(o,u)=>O((u==null?void 0:u.id)??""),getOptionLabel:o=>o.label,isOptionEqualToValue:(o,u)=>o.id===u.id,renderInput:o=>e.jsx(I,{...o,label:"Critic tag",placeholder:"Search critic tags",variant:"outlined",required:!0,helperText:!Ee&&!Oe&&ve.length===0?"N
1o critic tags returned from the catalog.":void 0,InputProps:{...o.InputProps,endAdornment:e.jsxs(e.Fragment,{children:[Ee?e.jsx(mt,{color:"inherit",size:18}):null,o.InputProps.endAdornment]})}})})]}):e.jsx(I,{label:"Critic version ID",value:ne,onChange:o=>O(o.target.value),variant:"outlined",fullWidth:!0,required:!0,helperText:"Critic version UUID."}),e.jsx(I,{select:!0,label:"Evaluation priority",value:fe,onChange:o=>ht(o.target.value),helperText:"Priority controls queue ordering, not guaranteed completion time.",fullWidth:!0,children:or.map(o=>e.jsx(Q,{value:o.value,children:e.jsx(qt,{primary:o.label,secondary:(S==null?void 0:S[o.value])===!1?"Unavailable in this environment":void 0})},o.value))}),e.jsxs(x,{sx:{display:"grid",gap:.25,mt:-1,ml:1.75},children:[e.jsxs(g,{variant:"caption",color:"text.secondary",children:[e.jsx("strong",{children:"Low (default):"})," routine evaluations, batch runs, and backfills."]}),e.jsxs(g,{variant:"caption",color:"text.secondary",children:[e.jsx("strong",{children:"Medium:"})," results that need to arrive sooner than routine work."]}),e.jsxs(g,{variant:"caption",color:"text.secondary",children:[e.jsx("strong",{children:"High:"})," time-sensitive evaluations such as clinical-safety checks."]}),e.jsx(g,{variant:"caption",color:"text.secondary",children:"Medium and High require approval from [email protected]."})]}),!Ue&&e.jsxs(U,{severity:"warning",children:[fe.toUpperCase()," evaluation priority is unavailable in this environment. You can save this config as a draft, but it cannot be approved until the queue is configured."]}),e.jsx(Ut,{component:"div",id:"critic-config-select-filters-label",sx:{mt:3},children:"Select Filters"}),e.jsx(g,{variant:"caption",color:"text.secondary",component:"p",sx:{m:0},children:"Critics can be scoped to all partners or one partner, with an optional script filter."}),e.jsx(ct,{multiple:!0,size:"small",options:Ht,value:Ht.filter(o=>c.includes(o.value)),onChange:(o,u)=>Y(u.map(R=>R.value)),getOptionLabel:o=>o.label,isOptionEqualToValue:(o,u)=>o.value===u.value,renderInput:o=>e.jsx(I,{...o,label:"Call Types"})}),e.jsx(je,{control:e.jsx(pe,{checked:J,onChange:(o,u)=>Z(u),color:"primary"}),label:"Use script sampling rate"}),e.jsxs(g,{variant:"caption",color:"text.secondary",component:"p",sx:{m:0,mt:-1},children:["On: sample at the script's ",e.jsx("code",{children:"critic_sampling_rate"})," (or"," ",e.jsx("code",{children:"review_sampling_rate"})," if unset). Off: fire on every eligible call."]}),e.jsxs(x,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"1fr 180px"},gap:1,alignItems:"center"},children:[e.jsx(je,{control:e.jsx(pe,{checked:C,onChange:(o,u)=>{we(u),u&&oe.trim()===""&&ae("1")},color:"primary"}),label:"Don't run on calls with fewer than"}),e.jsx(I,{label:"Utterances",value:oe,onChange:o=>ae(o.target.value),variant:"outlined",size:"small",type:"number",disabled:!C,helperText:C?"Use 1 to skip empty calls.":void 0,inputProps:{min:0,step:1}})]}),e.jsxs(x,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"1fr 180px"},gap:1,alignItems:"center"},children:[e.jsx(je,{control:e.jsx(pe,{checked:B,onChange:(o,u)=>ze(u),color:"primary"}),label:"Don't run on calls with more than"}),e.jsx(I,{label:"Utterances",value:We,onChange:o=>q(o.target.value),variant:"outlined",size:"small",type:"number",disabled:!B,inputProps:{min:0,step:1}})]}),e.jsxs(g,{variant:"caption",color:"text.secondary",component:"p",sx:{m:0,mt:-1},children:["For utterance filters, null ",e.jsx("code",{children:"num_utterances"})," is treated as 0."]}),e.jsxs(x,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"1fr 180px"},gap:1,alignItems:"center"},children:[e.jsx(je,{control:e.jsx(pe,{checked:V,onChange:(o,u)=>_e(u),color:"primary"}),label:"Don't run on calls shorter than"}),e.jsx(I,{label:"Seconds",value:ie,onChange:o=>rt(o.target.value),variant:"outlined",size:"small",type:"number",disabled:!V,inputProps:{min:1,step:1}})]}),e.jsxs(x,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"1fr 180px"},gap:1,alignItems:"center"},children:[e.jsx(je,{control:e.jsx(pe,{checked:ee,onChange:(o,u)=>Fe(u),color:"primary"}),label:"Don't run on calls longer than"}),e.jsx(I,{label:"Seconds",value:Pe,onChange:o=>it(o.target.value),variant:"outlined",size:"small",type:"number",disabled:!ee,inputProps:{min:1,step:1}})]}),e.jsx(je,{control:e.jsx(pe,{checked:$,onChange:(o,u)=>{j(u),u&&(_([]),Ke(""))},color:"primary"}),label:"All Partners"}),e.jsx(ct,{multiple:!0,fullWidth:!0,disabled:$,options:xe,loading:K,value:xe.filter(o=>te.includes(o.partner_id)),inputValue:Ie,onInputChange:(o,u,R)=>{R!=="reset"&&Ke(u)},onChange:(o,u)=>{_(u.map(R=>R.partner_id))},filterOptions:lr,getOptionLabel:o=>{var u;return((u=o.partner_name)==null?void 0:u.trim())||o.partner_id||""},isOptionEqualToValue:(o,u)=>o.partner_id===u.partner_id,renderInput:o=>e.jsx(I,{...o,label:"Partners",placeholder:"Search by partner name",variant:"outlined",InputProps:{...o.InputProps,endAdornment:e.jsxs(e.Fragment,{children:[K?e.jsx(mt,{color:"inherit",size:18}):null,o.InputProps.endAdornment]})}})}),e.jsx(ct,{multiple:!0,size:"medium",options:v,value:F,onChange:(o,u)=>H(u.map(R=>R.value)),inputValue:a,onInputChange:(o,u,R)=>{R==="input"?D(u):R==="clear"&&D("")},getOptionLabel:o=>o.label,filterOptions:o=>o,isOptionEqualToValue:(o,u)=>o.value===u.value,loading:i,renderOption:(o,u)=>l.createElement(Q,{...o,key:u.value},e.jsx(qt,{primary:u.label,secondary:u.value,secondaryTypographyProps:{sx:{fontFamily:"monospace",fontSize:"0.7rem"}}})),renderInput:o=>e.jsx(I,{...o,label:"Scripts","data-testid":"create-critic-run-config-scripts",InputProps:{...o.InputProps,endAdornment:e.jsxs(e.Fragment,{children:[i?e.jsx(mt,{color:"inherit",size:18}):null,o.InputProps.endAdornment]})}})}),e.jsx(x,{sx:{mt:2},children:le===void 0?e.jsx(U,{severity:ce?"info":"warning",children:ce?"Loading configured critic actionsâ¦":"Critic actions could not be loaded. Existing actions will be preserved when you save."}):e.jsx(sn,{actions:le,onChange:Me,reviewQueueConfigs:p==null?void 0:p.configs,prioritySlas:p==null?void 0:p.prioritySlas,criticScriptIds:k,reviewQueueConfigsLoading:m,reviewQueueConfigsError:f})})]})}),e.jsxs(et,{children:[e.jsx(N,{onClick:at,disabled:ot.isPending,children:"Cancel"}),e.jsx(N,{onClick:an,variant:"contained",disabled:ot.isPending,children:ot.isPending?"Savingâ¦":P?"Save":"Save as Draft"})]}),e.jsxs(Je,{open:He!==null,onClose:()=>he(null),maxWidth:"xs",fullWidth:!0,children:[e.jsx(Ze,{children:"Replace actions on live config?"}),e.jsx(Ve,{children:e.jsx(U,{severity:"warning",children:"This run config is live. Saving will replace its actions immediately, and critic results already in flight may use the new actions."})}),e.jsxs(et,{children:[e.jsx(N,{onClick:()=>he(null),children:"Cancel"}),e.jsx(N,{color:"warning",variant:"contained",onClick:()=>{const o=He;he(null),o&&Lt(o)},children:"Replace actions and save"})]})]})]})},yt=25,jt={onMouseDown:t=>{t.preventDefault()}},fr={disablePortal:!0,disableScrollLock:!0,PaperProps:{sx:t=>({zIndex:t.zIndex.modal+10})}},Yt=t=>({height:t.spacing(4),minHeight:t.spacing(4),boxSizing:"border-box"}),gr={width:"100%",maxWidth:{xs:"100%",sm:960,md:1180},mx:"auto"},on={borderRadius:"999px",height:22,minHeight:22,minWidth:"44px",justifyContent:"center",maxWidth:260,"& .MuiChip-label":{px:.75,py:0,pt:0,pb:0,fontSize:"0.75rem",fontWeight:400,lineHeight:1.15,overflow:"hidden",textOverflow:"ellipsis"}},_r={bgcolor:"rgb(227, 242, 253)",color:"rgb(21, 101, 192)"},hr={bgcolor:"rgb(243, 229, 245)",color:"rgb(106, 27, 154)"}
1,xr={approved:{bgcolor:"rgb(232, 245, 233)",color:"rgb(27, 94, 32)"},draft:{bgcolor:"rgb(245, 245, 245)",color:"rgb(97, 97, 97)"},pending_review:{bgcolor:"rgb(227, 242, 253)",color:"rgb(13, 71, 161)"},not_approved:{bgcolor:"rgb(255, 235, 238)",color:"rgb(198, 40, 40)"}},vr={bgcolor:"rgb(245, 245, 245)",color:"rgb(97, 97, 97)"};function Ct(t){var d,r;const n=(d=t.tag_id)==null?void 0:d.trim();if(n)return{targetValue:n,typeLabel:"Tag"};const s=(r=t.critic_version_id)==null?void 0:r.trim();return s?{targetValue:s,typeLabel:"Critic Version"}:{targetValue:null,typeLabel:null}}const St={wordBreak:"break-word"};function wt({targetValue:t,typeLabel:n}){const s=t==null?void 0:t.trim();if(!s)return e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",children:"â"});if(n==="Critic Version"){const d=Wt(`/owl/curation/critic-versions/${encodeURIComponent(s)}`);return e.jsx($t,{href:d,target:"_blank",rel:"noopener noreferrer",variant:"body2",sx:{...St,color:"primary.main"},children:s})}if(n==="Tag"){const d=Wt(`/owl/curation?tag=${encodeURIComponent(s)}`);return e.jsx($t,{href:d,target:"_blank",rel:"noopener noreferrer",variant:"body2",sx:{...St,color:"primary.main"},children:s})}return e.jsx(g,{component:"span",variant:"body2",sx:St,children:s})}function Pt({typeLabel:t}){if(!t)return e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",children:"â"});const n=t==="Tag"?_r:hr;return e.jsx(tt,{label:t,size:"small",sx:{...on,...n}})}function Xt(t){var S;if(t.is_global===!0)return"All Partners";const n=t.partner_names&&t.partner_names.length>0?t.partner_names:(S=t.partner_name)!=null&&S.trim()?[t.partner_name.trim()]:t.partner_id?[t.partner_id]:[];if(n.length===0)return"â";const s=n.length>1?`(${n.length}) `:"",d=n.map(P=>P.length>16?`${P.slice(0,16)}â¦`:P).join(", "),r=`${s}${d}`;return r.length>80?`${r.slice(0,80)}â¦`:r}function br(t){const{data:n}=kt({scriptStatuses:[ft.ACTIVE,ft.DEMO],onlyIgloo:!0,scriptIds:t,limit:Math.min(500,Math.max(t.length,1)),offset:0},{enabled:t.length>0});return l.useMemo(()=>{const s=new Map;for(const d of(n==null?void 0:n.scripts)??[])s.set(d.script_id,Rt(d));return s},[n==null?void 0:n.scripts])}function Jt(t){if(!t)return"â";const n=new Date(t);return Number.isNaN(n.getTime())?t:n.toLocaleString()}function ut(t){if(t instanceof Error&&t.message==="Failed to fetch")return"Failed to update";if(t instanceof Error&&typeof t.message=="string"){const n=t.message.trim();return n.length>0?n:"Failed to update"}return"Failed to update"}function yr(t){const n=t==null?void 0:t.trim();return n?n.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase()):"â"}function jr(t){const n=[];return t.min_num_utterances!=null&&n.push(`Skip < ${t.min_num_utterances} utterances`),t.max_num_utterances!=null&&n.push(`Skip > ${t.max_num_utterances} utterances`),t.min_call_duration_seconds!=null&&n.push(`Skip < ${t.min_call_duration_seconds}s`),t.max_call_duration_seconds!=null&&n.push(`Skip > ${t.max_call_duration_seconds}s`),n.length>0?n.join(", "):"â"}function Cr(t){const n=(t==null?void 0:t.trim().toLowerCase())??"";return xr[n]??vr}function Ae(t){const n=(t==null?void 0:t.trim().toLowerCase())??"";return n==="approved"||n==="not_approved"||n==="draft"||n==="pending_review"?n:"draft"}function Zt(t){const n=(t==null?void 0:t.trim().toLowerCase())??"";return n==="draft"||n==="pending"||n==="pending_review"||n==="not_approved"}function Vt({approvalStatus:t}){const n=t==null?void 0:t.trim();return n?e.jsx(tt,{label:yr(n),size:"small",sx:{...on,...Cr(n)}}):e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",children:"â"})}function se({label:t,value:n,monospaceValue:s=!0}){return e.jsxs(x,{sx:{display:"flex",gap:1,py:.25},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:t}),e.jsx(g,{component:"span",variant:"body2",sx:{wordBreak:"break-word",...s?{fontFamily:"monospace",fontSize:"0.8rem"}:{}},children:n!=null&&n.trim()?n:"â"})]})}const It="config",Et="[email protected]",bi=()=>{var st,ke;pn("Run Configs");const t=mn(),[n,s]=fn(),d=((st=t.user_metadata)==null?void 0:st.is_critic_reviewer)===!0,r=t.email.trim().toLowerCase()===Et,[S,P]=l.useState(!1),[G,E]=l.useState(null),[te,_]=l.useState(null),[b,y]=l.useState(null),[ne,O]=l.useState(null),[$,j]=l.useState(null),[k,H]=l.useState({}),[a,D]=l.useState(null),[Te,c]=l.useState(!1),[Y,me]=l.useState("draft"),[Ne,M]=l.useState(null),[X,fe]=l.useState(null),[ht,Ue]=l.useState(!1),[nt,ge]=l.useState(null),[Se,qe]=l.useState(1),re=gn(),J=l.useMemo(()=>{const i=(Se-1)*yt;return{limit:yt,offset:i}},[Se]),Z=l.useMemo(()=>["rome","critics","critic_run_configs",J.limit,J.offset],[J]),{data:C,isLoading:we,isError:B,error:ze}=wn(J),oe=(C==null?void 0:C.total_count)??0,ae=oe===0?1:Math.ceil(oe/yt);l.useEffect(()=>{C!==void 0&&Se>ae&&qe(ae)},[Se,ae,C]);const We=Pn(),q=In(),V=En(),_e=kn(),ee=l.useCallback(i=>{_(i),window.setTimeout(()=>{_(p=>p===i?null:p)},5e3)},[]),Fe=l.useCallback(i=>{D(i),c(!0),s(p=>{const m=new URLSearchParams(p);return m.set(It,i.config_id),m},{replace:!0})},[s]),ie=l.useCallback(()=>{M(null),c(!1),s(i=>{const p=new URLSearchParams(i);return p.delete(It),p},{replace:!0})},[s]),rt=n.get(It),{data:Pe}=nn(Te?null:rt);l.useEffect(()=>{const i=Pe==null?void 0:Pe.critic_run_config;i&&(D(i),c(!0))},[Pe]);const it=l.useCallback(()=>{D(null),M(null)},[]),le=l.useCallback(i=>{ge(null),fe(i),Ue(!0)},[]),Me=l.useCallback(()=>{_e.isPending||(ge(null),Ue(!1))},[_e.isPending]),De=l.useCallback(()=>{fe(null),ge(null)},[]),$e=l.useCallback(()=>{q.isPending||(O(null),y(null))},[q.isPending]),He=a==null?void 0:a.config_id,he=a==null?void 0:a.approval_status;l.useEffect(()=>{He!=null&&(me(Ae(he)),M(null))},[he,He]);const Be=l.useCallback((i,p)=>{j(null),H(m=>({...m,[i]:p})),We.mutate({configId:i,enabled:p},{onSuccess:m=>{const f=m==null?void 0:m.critic_run_config;if(!(f!=null&&f.config_id)){H(h=>{const v={...h};return delete v[i],v}),j("Failed to update");return}re.setQueryData(Z,h=>h&&{...h,critic_run_configs:h.critic_run_configs.map(v=>v.config_id===f.config_id?{...v,...f}:v)}),H(h=>{const v={...h};return delete v[i],v}),D(h=>(h==null?void 0:h.config_id)===i?{...h,...f}:h)},onError:m=>{H(f=>{const h={...f};return delete h[i],h}),j(ut(m))}})},[Z,We,re]),T=l.useCallback(()=>
1{if(!a)return;const i=Y;Ae(i)!==Ae(a.approval_status)&&(M(null),q.mutate({configId:a.config_id,approval_status:i},{onSuccess:p=>{const m=p==null?void 0:p.critic_run_config;if(!(m!=null&&m.config_id)){M("Failed to update approval");return}re.setQueryData(Z,f=>f&&{...f,critic_run_configs:f.critic_run_configs.map(h=>h.config_id===m.config_id?{...h,...m}:h)}),D(f=>(f==null?void 0:f.config_id)===m.config_id?{...f,...m}:f)},onError:p=>{M(ut(p))}}))},[a,Z,q,re,Y]),Ie=l.useCallback((i,p)=>{q.mutate({configId:i,approval_status:"pending_review"},{onSuccess:m=>{var h;const f=m==null?void 0:m.critic_run_config;f!=null&&f.config_id&&(re.setQueryData(Z,v=>v&&{...v,critic_run_configs:v.critic_run_configs.map(F=>F.config_id===f.config_id?{...F,...f}:F)}),D(v=>(v==null?void 0:v.config_id)===f.config_id?{...v,...f}:v),y(v=>(v==null?void 0:v.config_id)===f.config_id?{...v,...f}:v),(h=p==null?void 0:p.onSuccess)==null||h.call(p,f))},onError:m=>{const f=ut(m);p!=null&&p.onError?p.onError(f):M(f)}})},[Z,q,re]),Ke=l.useCallback(()=>{a&&(Ie(a.config_id),ie())},[ie,a,Ie]),xt=l.useCallback(()=>{b&&(O(null),Ie(b.config_id,{onSuccess:()=>{y(null),ee("Critic run config submitted for review.")},onError:O}))},[b,ee,Ie]),Qe=l.useCallback(()=>{if(!a)return;const i=a.config_id;M(null),V.mutate({configId:i},{onSuccess:p=>{const m=p==null?void 0:p.critic_run_config;if(!(m!=null&&m.config_id)){M("Failed to approve and enable");return}re.setQueryData(Z,f=>f&&{...f,critic_run_configs:f.critic_run_configs.map(h=>h.config_id===m.config_id?{...h,...m}:h)}),H(f=>{const h={...f};return delete h[i],h}),D(f=>(f==null?void 0:f.config_id)===m.config_id?{...f,...m}:f),ie()},onError:p=>{M(ut(p))}})},[ie,a,Z,V,re]),ce=l.useMemo(()=>(C==null?void 0:C.critic_run_configs)??[],[C]),Le=l.useMemo(()=>{const i=new Set;for(const p of ce)for(const m of p.script_ids??[])m.trim()&&i.add(m.trim());return Array.from(i).sort()},[ce]),Ge=br(Le),z=l.useMemo(()=>a?Ct(a):null,[a]),K=l.useMemo(()=>X?Ct(X):null,[X]),xe=l.useMemo(()=>a?k[a.config_id]!==void 0?k[a.config_id]:a.enabled:!1,[a,k]),de=l.useMemo(()=>{var i;return a==null?!1:!!(Zt(a.approval_status)&&!xe||((i=a.approval_status)==null?void 0:i.trim().toLowerCase())==="approved"&&!d&&!xe)},[a,xe,d]),Ee=(a==null?void 0:a.queue_priority)==="medium"||(a==null?void 0:a.queue_priority)==="high",Oe=(a==null?void 0:a.queue_priority_available)??!Ee,Ye=(!Ee||r)&&Oe,ve=l.useCallback(i=>{if(i.approval_status!=="approved")return!0;if(!d)return!1;const p=i.queue_priority==="medium"||i.queue_priority==="high",m=i.queue_priority_available??!p;return!p||r&&m},[d,r]);return e.jsx(_n,{children:e.jsxs(x,{sx:gr,children:[e.jsxs(x,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:2,mb:1},children:[e.jsxs(x,{sx:{flex:1,minWidth:0},children:[e.jsx(yn,{title:"Run Configs",sx:{mb:0}}),e.jsx(g,{variant:"body2",color:"text.secondary",sx:{mt:.5,mb:2},children:"Configure critics to run on specified partners, scripts, or globally on all calls"})]}),e.jsx(N,{variant:"contained",onClick:()=>P(!0),sx:{flexShrink:0},children:"Create run config"})]}),S?e.jsx(Gt,{open:!0,onClose:()=>P(!1),onCreated:i=>{qe(1),O(null),y(i),ee("Critic run config created.")},queuePriorityAvailability:C==null?void 0:C.queue_priority_availability}):null,G?e.jsx(Gt,{open:!0,onClose:()=>E(null),onCreated:()=>E(null),editConfigId:G.config_id,initialValues:G,queuePriorityAvailability:C==null?void 0:C.queue_priority_availability}):null,e.jsxs(Je,{open:b!==null,onClose:$e,maxWidth:"xs",fullWidth:!0,BackdropProps:jt,children:[e.jsx(Ze,{children:"Submit run config for review?"}),e.jsxs(Ve,{children:[ne?e.jsx(U,{severity:"error",sx:{mb:2},onClose:()=>O(null),children:ne}):null,e.jsx(g,{variant:"body2",children:"New run configs are saved as draft and stay disabled until they are approved. Submit this critic config for review now, or keep it as a draft."})]}),e.jsxs(et,{children:[e.jsx(N,{onClick:$e,disabled:q.isPending,children:"Keep as Draft Critic Config"}),e.jsx(N,{variant:"contained",onClick:xt,disabled:q.isPending,children:q.isPending?"Submittingâ¦":"Submit for Review"})]})]}),e.jsxs(Je,{open:Te,onClose:ie,TransitionProps:{onExited:it},maxWidth:"sm",fullWidth:!0,BackdropProps:jt,PaperProps:{sx:{maxHeight:"90vh",display:"flex",flexDirection:"column"}},children:[e.jsxs(Ze,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:["Critic run config",e.jsx(N,{size:"small",disabled:!a||!ve(a),title:a&&!ve(a)?a.queue_priority_available===!1?`${(a.queue_priority??"low").toUpperCase()} evaluation priority is not configured in this environment.`:`Approved Medium and High priority configs can only be edited by ${Et}.`:void 0,onClick:()=>{const i=a;ie(),i&&E(i)},children:"Edit"})]}),e.jsx(Ve,{dividers:!0,sx:{overflowY:"auto"},children:a&&e.jsxs(Ce,{spacing:.5,children:[Ne&&d?e.jsx(U,{severity:"error",sx:{mb:1},onClose:()=>M(null),children:Ne}):null,e.jsx(se,{label:"Name",monospaceValue:!1,value:a.name}),e.jsx(se,{label:"Description",monospaceValue:!1,value:a.description}),e.jsxs(x,{sx:{display:"flex",gap:1,py:.25,alignItems:"center"},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:"Type"}),e.jsx(Pt,{typeLabel:(z==null?void 0:z.typeLabel)??null})]}),e.jsxs(x,{sx:{display:"flex",gap:1,py:.25,alignItems:"baseline"},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:"Target"}),e.jsx(wt,{targetValue:z==null?void 0:z.targetValue,typeLabel:(z==null?void 0:z.typeLabel)??null})]}),e.jsxs(x,{sx:{display:"flex",gap:1,py:.25,alignItems:"center"},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:"Enabled"}),e.jsx(pe,{checked:xe,disabled:de,size:"small",title:de?"Approve this run config before enabling.":void 0,onChange:(i,p)=>{Be(a.config_id,p)},inputProps:{"aria-label":`Enabled for critic run config ${a.config_id}`}})]}),e.jsx(se,{label:"Evaluation priority",monospaceValue:!1,value:(a.queue_priority??"low").toUpperCase()}),Ee&&e.jsx(U,{severity:Oe?"info":"warning",sx:{my:1},children:Oe?`Medium and High evaluation priorities require approval from ${Et}.`:`${(a.queue_priority??"low").toUpperCase()} evaluation priority is not configured in this environment.`}),e.jsxs(x,{sx:{display:"flex",gap:1,py:.25,alignItems:"center"},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:"Script Sampling"}),e.jsx(pe,{checked:a.use_script_sampling_rate??!1,disabled:!0,size:"small",sx:{pointerEvents:"none",cursor:"default","& *":{cursor:"default"}},inputProps:{"aria-label":`Script sampling for critic run config ${a.config_id}`}})]}),e.jsxs(x,{sx:{display:"flex",gap:1,py:.25,alignItems:"center",flexWrap:"wrap"},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:"Approval status"}),d?e.jsxs(e.Fragment,{children:[e.jsx(tn,{size:"small",sx:i=>({minWidth:160,position:"relative",zIndex:1,"& .MuiOutlinedInput-root":Yt(i),"& .MuiSelect-select":{py:0,display:"flex",alignItems:"center"}}),children:e.jsxs(hn,{value:Y,MenuProps:fr,onChange:i=>{me(Ae(String(i.target.value)))},inputProps:{"aria-label":"Approval status"},children:[e.jsx(Q,{value:"draft",children:"Draft"}),e.jsx(Q,{value:"pending_review",children:"Pending Review"}),e.jsx(Q,{value:"approved",disabled:!Ye,children:"Approved"}),e.jsx(Q,{value:"not_approved",children:"Not Approved"})]})}),e.jsx(N,{variant:"outlined",size:"small",sx:i=>Yt(i),disabled:q.isPending||Ae(Y)===Ae(a.approval_status),onClick:T,children:"Update"})]}):e.jsx(Vt,{approvalStatus:a.approval_status})]}),e.jsx(x,{sx:{pt:1.5},children:e.jsx(g,{variant:"overline",color:"text.secondary",children:"Filters"})}),e.jsxs(x,{sx:{display:"flex",gap:1,py:.25},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:"Call Types"}),a.call_types?e.jsx(Ce,{direction:"row",flexWrap:"wrap",gap:.5,children:a.call_types.split(";").map(i=>e.jsx(tt,{label:i,size:"small"},i))}):e.jsx(g,{component:"span",variant:"body2",children:"â"})]}),e.jsx(se,{label:"Call Eligibility",monospaceValue:!1,value:jr(a)}),e.jsxs(x,{sx:{display:"flex",gap:1,py:.25,pt:1.5},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:"Partners"}),a.is_global?e.jsx(g,{component:"span",variant:"body2",children:"All Partners"}):(a.partner_ids??[]).length>0?e.jsx(Ce,{spacing:.75,sx:{pl:0},children:(a.partner_ids??[]).map((i,p)=>{var m;return e.jsxs(x,{children:[e.jsx(g,{variant:"body2",children:((m=a.partner_names)==null?void 0:m[p])??i}),e.jsx(g,{variant:"caption",color:"text.secondary",sx:{fontFamily:"monospace"},children:i})]},i)})}):e.jsx(g,{component:"span",variant:"body2",children:((ke=a.partner_name)==null?void 0:ke.trim())||a.partner_id||"â"})]}),e.jsxs(x,{sx:{display:"flex",gap:1,py:.25,pt:1.5},children:[e.jsx(g,{component:"span",variant:"body2",color:"text.secondary",sx:{flexShrink:0,minWidth:140},children:"Scripts"}),(a.script_ids??[]).length>0?e.jsx(Ce,{spacing:.75,children:(a.script_ids??[]).map(i=>e.jsxs(x,{children:[e.jsx(g,{variant:"body2",children:Ge.get(i.trim())??i}),e.jsx(g,{variant:"caption",color:"text.secondary",sx:{fontFamily:"monospace"},children:i})]},i))}):e.jsx(g,{component:"span",variant:"body2",children:"â"})]}),e.jsx(x,{sx:{pt:1.5},children:e.jsx(rr,{actions:a.critic_actions})}),e.jsx(x,{sx:{pt:1.5},children:e.jsx(g,{variant:"overline",color:"text.secondary",children:"Metadata"})}),e.jsx(se,{label:"Run config ID",value:a.config_id}),e.jsx(se,{label:"Approved by",monospaceValue:!1,value:a.approved_by_name??a.approved_by??void 0}),e.jsx(se,{label:"Created by",monospaceValue:!1,value:a.created_by_name??a.created_by_id}),e.jsx(se,{label:"Created by ID",monospaceValue:!1,value:a.created_by_id}),e.jsx(se,{label:"Created at",monospaceValue:!1,value:Jt(a.created_at)}),e.jsx(se,{label:"Updated at",monospaceValue:!1,value:Jt(a.updated_at)})]})}),e.jsxs(et,{sx:{px:3,py:2,flexDirection:"row",justifyContent:!d&&(a==null?void 0:a.approval_status)!=="draft"&&(a==null?void 0:a.approval_status)!=="not_approved"?"flex-end":"space-between",alignItems:"center"},children:[e.jsx(N,{onClick:ie,children:"Close"}),e.jsxs(x,{sx:{display:"flex",gap:1},children:[a&&(a.approval_status==="draft"||a.approval_status==="not_approved")&&e.jsx(N,{variant:"outlined",size:"small",disabled:q.isPending,onClick:Ke,children:"Submit for Review"}),d&&e.jsx(N,{variant:"contained",color:"primary",size:"small",disabled:!a||!Ye||V.isPending||Ae(a.approval_status)==="approved"&&xe,onClick:Qe,children:"Approve & Enable"})]})]})]}),e.jsxs(Je,{open:ht,onClose:Me,TransitionProps:{onExited:De},maxWidth:"xs",fullWidth:!0,BackdropProps:jt,children:[e.jsx(Ze,{children:"Delete critic run config?"}),e.jsxs(Ve,{children:[nt&&e.jsx(U,{severity:"error",sx:{mb:2},onClose:()=>ge(null),children:nt}),e.jsx(g,{variant:"body2",sx:{mb:2},children:"Are you sure you want to delete this critic run config?"}),X&&e.jsxs(Ce,{spacing:1.5,children:[e.jsxs(x,{children:[e.jsx(g,{variant:"caption",color:"text.secondary",display:"block",children:"Partner"}),e.jsx(g,{variant:"body2",children:Xt(X)})]}),e.jsxs(x,{children:[e.jsx(g,{variant:"caption",color:"text.secondary",display:"block",children:"Type"}),e.jsx(Pt,{typeLabel:(K==null?void 0:K.typeLabel)??null})]}),e.jsxs(x,{children:[e.jsx(g,{variant:"caption",color:"text.secondary",display:"block",children:"Target"}),e.jsx(wt,{targetValue:K==null?void 0:K.targetValue,typeLabel:(K==null?void 0:K.typeLabel)??null})]}),(X.script_ids??[]).length>0?e.jsxs(x,{children:[e.jsx(g,{variant:"caption",color:"text.secondary",display:"block",children:"Scripts"}),e.jsx(g,{variant:"body2",children:(X.script_ids??[]).map(i=>Ge.get(i.trim())??i).join(", ")})]}):null]})]}),e.jsxs(et,{children:[e.jsx(N,{onClick:Me,disabled:_e.isPending,children:"Cancel"}),e.jsx(N,{color:"error",variant:"contained",disabled:_e.isPending,onClick:()=>{const i=X;if(!i)return;const p=i.config_id;ge(null),_e.mutate(p,{onSuccess:()=>{Ue(!1),H(m=>{const f={...m};return delete f[p],f}),D(m=>((m==null?void 0:m.config_id)===p&&c(!1),m))},onError:m=>{ge(m instanceof Error?m.message:"Could not delete critic run config.")}})},children:"Delete"})]})]}),te&&e.jsx(U,{severity:"success",sx:{mb:2},onClose:()=>_(null),children:te}),$&&e.jsx(U,{severity:"error",sx:{mb:2},onClose:()=>j(null),children:$}),we&&e.jsx(x,{display:"flex",justifyContent:"center",py:4,children:e.jsx(mt,{})}),B&&e.jsx(U,{severity:"error",sx:{mb:2},children:ze instanceof Error?ze.message:"Failed to load critic run configs"}),!we&&!B&&oe===0&&e.jsx(g,{color:"text.secondary",children:"No critic run configs yet."}),!we&&!B&&ce.length>0&&e.jsx(An,{component:xn,variant:"outlined",children:e.jsxs(Tn,{size:"small",children:[e.jsx(Mn,{children:e.jsxs(zt,{children:[e.jsx(w,{width:200,children:"Name"}),e.jsx(w,{width:150,children:"Partner"}),e.jsx(w,{children:"Type"}),e.jsx(w,{sx:{minWidth:160},children:"Target"}),e.jsx(w,{width:200,children:"Script"}),e.jsx(w,{width:110,children:"Call Types"}),e.jsx(w,{width:130,align:"center",title:"On: sample at the script's critic_sampling_rate (or review_sampling_rate if unset). Off: fire on every eligible call.",children:"Script Sampling"}),e.jsx(w,{width:110,align:"center",children:"Priority"}),e.jsx(w,{width:110,align:"center",children:"Approved"}),e.jsx(w,{width:120,children:"Enabled"}),e.jsx(w,{width:180,children:"Actions"}),e.jsx(w,{width:56,padding:"checkbox"})]})}),e.jsx(Dn,{children:ce.map(i=>{var v;const{targetValue:p,typeLabel:m}=Ct(i),f=k[i.config_id]!==void 0?k[i.config_id]:i.enabled,h=(Zt(i.approval_status)||((v=i.approval_status)==null?void 0:v.trim().toLowerCase())==="approved"&&!d)&&!f;return e.jsxs(zt,{children:[e.jsx(w,{children:e.jsxs(x,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx("span",{children:i.name??"â"}),i.description&&e.jsx(Ln,{title:i.description,arrow:!0,children:e.jsx(en,{size:"small",sx:{p:.25},children:e.jsx(vn,{sx:{fontSize:16}})})})]})}),e.jsx(w,{children:Xt(i)}),e.jsx(w,{sx:{overflow:"visible",py:1.25},children:e.jsx(Pt,{typeLabel:m})}),e.jsx(w,{sx:{maxWidth:320},title:p??void 0,children:e.jsx(wt,{targetValue:p,typeLabel:m})}),e.jsx(w,{sx:{fontSize:"0.875rem",wordBreak:"break-word"},children:(i.script_ids??[]).length>0?(()=>{const F=`(${i.script_ids.length}) ${i.script_ids.map(be=>{const Re=Ge.get(be.trim())??be;return Re.length>16?`${Re.slice(0,16)}â¦`:Re}).join(", ")}`;return F.length>80?`${F.slice(0,80)}â¦`:F})():"â"}),e.jsx(w,{children:i.call_types?e.jsx(Ce,{direction:"row",flexWrap:"wrap",gap:.5,children:i.call_types.split(";").map(F=>e.jsx(tt,{label:F,size:"small"},F))}):"â"}),e.jsx(w,{align:"center",title:i.use_script_sampling_rate?"Sampled at the script's critic_sampling_rate (or review_sampling_rate if unset)":"Fires on every eligible call",children:i.use_script_sampling_rate?"On":"Off"}),e.jsx(w,{align:"center",children:e.jsx(tt,{label:(i.queue_priority??"low").toUpperCase(),size:"small",color:i.queue_priority==="high"?"error":i.queue_priority==="medium"?"warning":"default"})}),e.jsx(w,{align:"center",sx:{overflow:"visible",py:1.25},title:i.approval_status??void 0,children:e.jsx(Vt,{approvalStatus:i.approval_status})}),e.jsx(w,{children:e.jsx(pe,{checked:f,disabled:h,size:"small",title:h?"Approve this run config before enabling.":void 0,onChange:(F,be)=>{Be(i.config_id,be)},inputProps:{"aria-label":`Enabled for critic run config ${i.config_id}`}})}),e.jsx(w,{sx:{minWidth:180},children:e.jsx(ir,{actions:i.critic_actions})}),e.jsx(w,{align:"right",padding:"checkbox",sx:{pr:1},children:e.jsx(bn,{id:i.config_id,size:"small",tooltip:"More Options",actions:[...i.approval_status==="draft"||i.approval_status==="not_approved"?[{title:"Submit for Review",onClick:()=>Ie(i.config_id)}]:[],...d&&i.approval_status!=="approved"?[{title:"Review",onClick:()=>Fe(i)}]:[],{title:"View info",onClick:()=>Fe(i)},...ve(i)?[{title:"Edit",onClick:()=>E(i)}]:[],{title:"Delete",color:"error",onClick:()=>{le(i)}}]})})]},i.config_id)})})]})}),!we&&!B&&C&&oe>0&&ce.length>0&&e.jsxs(x,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:1,mt:2},children:[e.jsxs(g,{variant:"body2",color:"text.secondary",children:["Showing ",J.offset+1,"â
1",J.offset+ce.length," of ",oe]}),ae>1?e.jsx(Fn,{count:ae,page:Se,onChange:(i,p)=>{qe(p)},color:"primary",size:"small"}):null]})]})})};export{bi 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.