1import{a as e}from"./chunk-BNv3lrIs.js";import{t}from"./react-CMjZfere.js";import{Sn as n,Xt as r}from"./utils-DJX6_tFu.js";import{r as i}from"./uiStore-CQnwAuHX.js";import{t as a}from"./react-BX9wjTsJ.js";import{H as o,Un as s,kr as c,nr as l,t as u}from"./api-CjWme3MJ.js";import{t as d}from"./jsx-runtime-0CkuSBV-.js";import{n as f}from"./bundle-mjs-BjgjZ_1B.js";import{n as p,r as m,t as h}from"./Modal-BcfoosOD.js";import{r as g}from"./distillTeam-B_hILKBN.js";import{t as _}from"./CheckCircleIcon-CRqWSOLk.js";import{t as v}from"./XCircleIcon-B1GrEPlv.js";import{t as y}from"./ExclamationCircleIcon-C7AwVb2A.js";import{t as b}from"./Spinner-B7fWP4I5.js";var x=e(t());function S({title:e,titleId:t,...n},r){return x.createElement(`svg`,Object.assign({xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,"aria-hidden":`true`,"data-slot":`icon`,ref:r,"aria-labelledby":t},n),e?x.createElement(`title`,{id:t},e):null,x.createElement(`path`,{fillRule:`evenodd`,d:`M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm.75-11.25a.75.75 0 0 0-1.5 0v2.5h-2.5a.75.75 0 0 0 0 1.5h2.5v2.5a.75.75 0 0 0 1.5 0v-2.5h2.5a.75.75 0 0 0 0-1.5h-2.5v-2.5Z`,clipRule:`evenodd`}))}var C=x.forwardRef(S);function w(e,t){let n=e.map(e=>e.trim()).filter(Boolean),r=t.trim();if(n.length===0)return r.length===0;for(let[e,t]of n.entries()){if(!r.startsWith(t))return!1;if(r=r.slice(t.length),e<n.length-1){let e=r.match(/^\s+/)?.[0];if(!e)return!1;r=r.slice(e.length)}}return r.trim().length===0}function T(e,t){let n=t?.trim(),r=e.trim();if(!n||!r.startsWith(n))return[r];let i=r.slice(n.length);return i&&!/^\s/.test(i)?[r]:[r,i.trim()]}function E(e){let t=e.trim(),n=t.indexOf(` 2`),r=(n===-1?t:t.slice(0,n)).match(/^Subject:\s*(.+)$/i);if(r)return{subject:r[1].trim(),body:n===-1?``:t.slice(n+1).replace(/^\n+/,``)}}function D({blocks:e,messageText:t,subjectText:n}){if(e.length===0||e.some(e=>!e.text.trim()))return!1;let r=e.filter(e=>e.blockKind===`subject`),i=e.filter(e=>e.blockKind!==`subject`);if(r.length>0){if(!n)return w(e.map(e=>e.text),t);if(!w(r.map(e=>e.text),n))return!1}let a=i.map(e=>e.text),o=r.length===0?E(a[0]??``):null;if(o){if(!n||o.subject!==n.trim())return!1;a=[o.body,...a.slice(1)]}let s=T(t,n),c=E(t);return c&&c.subject===n?.trim()&&s.push(c.body),s.some(e=>w(a,e))}var O=d(),k=r(`UI:MessageTestCaseModal`);function A(e,t){let n=t?.trim(),r=n&&e.startsWith(n)?e.slice(n.length).trim():e,i=r.split(/\n\s*\n/).map(e=>e.trim()).filter(Boolean);if(i.length<=1){let e=r.trim()?[{blockKind:`fullMessage`,text:r.trim()}]:[];return n?[{blockKind:`subject`,text:n},...e]:e}let a=i.map((e,t)=>({blockId:`inferred-${t+1}`,blockKind:`other`,text:e}));return n?[{blockKind:`subject`,text:n},...a]:a}function ee(e){return e===`fullMessage`?`Full message`:e===`other`?`Message section`:l[e]??e}function j(e){return s[e]??e}function M({step:e,done:t}){return(0,O.jsx)(`span`,{"aria-hidden":!0,className:f(`mr-1 inline-flex h-5 w-5 items-center justify-center rounded-full text-xs font-semibold`,t?`bg-brand-600 text-white`:`bg-gray-200 text-gray-600`),children:e})}function N({open:e,setOpen:t,messageText:r=``,subjectText:i,blocks:a,context:s,onSubmitted:l,onError:d}){let{availableBlocks:g,hasExactBlockProvenance:y}=(0,x.useMemo)(()=>{let e=(a??[]).filter(e=>e.text.trim()),t=D({blocks:e,messageText:r,subjectText:i});return{availableBlocks:t?e:A(r,i),hasExactBlockProvenance:t}},[a,r,i]),[S,C]=(0,x.useState)(o.Bad),w=S===o.Bad,[T,E]=(0,x.useState)(null),[N,P]=(0,x.useState)(``),[F,I]=(0,x.useState)(``),[L,R]=(0,x.useState)(``),[z,B]=(0,x.useState)(!1),[V,H]=(0,x.useState)(null),U=(0,x.useRef)(null);(0,x.useEffect)(()=>{e&&(C(o.Bad),E(null),P(``),I(``),R(``),B(!1),H(null))},[g,e]);let W=(0,x.useCallback)(e=>{g[e]&&(E(e),H(null))},[g]),G=(0,x.useCallback)(e=>{W(Number(e.currentTarget.dataset.blockIndex))},[W]),K=(0,x.useCallback)(()=>t(!1),[t]),q=(0,x.useCallback)(e=>{C(e.target.value),H(null)},[]),J=(0,x.useCallback)(e=>{P(e.target.value)},[]),Y=(0,x.useCallback)(e=>{I(e.target.value)},[]),te=(0,x.useCallback)(e=>{R(e.target.value)},[]),ne=(0,x.useCallback)(async e=>{if(e.preventDefault(),z)return;let i=T===null?void 0:g[T];
2if(!i?.text.trim()){H(`Choose a generated message component.`);return}if(w&&!F.trim()){H(`Describe what was wrong.`);return}if(w&&!L.trim()){H(`Describe what could be better.`);return}if(!w&&!N.trim()){H(`Describe what makes this a good example.`);return}B(!0),H(null);try{let e={surface:s?.surface??`generatedMessage`,messageText:r,contextLabel:s?.contextLabel,contextUrl:s?.contextUrl,msgGenId:s?.msgGenId,blockId:i.blockId,blockKind:i.blockKind,openerAngle:i.openerAngle,blockText:i.text.trim(),campaignId:s?.campaignId,projectId:s?.projectId,candidateId:s?.candidateId,dispatchMessageId:s?.dispatchMessageId};S===o.Bad?await u.submitGeneratedMessageFeedback({...e,classification:o.Bad,whatWasWrong:F.trim(),whatCouldBeBetter:L.trim()}):await u.submitGeneratedMessageFeedback({...e,classification:o.Good,commentary:N.trim()||void 0}),d?.(null),l?.(S),t(!1)}catch(e){n(e)?c.sendError(e instanceof Error?e:Error(String(e)),{context:`MessageTestCaseModal.submit`}):k.warn(`Failed to create message testcase`,{error:e});let t=e instanceof Error?e.message:`Something went wrong.`;H(t),d?.(t)}finally{B(!1)}},[g,S,s,N,w,r,d,l,T,t,z,F,L]),X=T===null?void 0:g[T],Z=!!X,Q=w?!!(F.trim()&&L.trim()):!!N.trim(),$=Z&&Q;return(0,O.jsx)(h,{open:e,setOpen:t,initialFocus:U,alignment:`top`,children:(0,O.jsx)(p,{title:`Add testcase`,className:`md:w-[calc(100vw-2rem)] md:max-w-5xl lg:max-w-6xl`,buttons:(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`button`,{ref:U,type:`button`,className:`inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-xs ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:w-auto`,onClick:K,disabled:z,children:`Cancel`}),(0,O.jsx)(`span`,{className:`w-full sm:w-auto`,...$?{}:{"data-tooltip-id":`tooltip`,"data-tooltip-content":X?w?`Answer both questions to save.`:`Add commentary to save.`:`Select the block this testcase is about.`},children:(0,O.jsx)(m,{type:`submit`,form:`message-testcase-form`,disabled:z||!$,children:z?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(b,{size:16,className:`mr-2`}),` Saving`]}):`Save testcase`})})]}),children:(0,O.jsxs)(`form`,{id:`message-testcase-form`,onSubmit:ne,className:`space-y-5 text-left`,children:[y?null:(0,O.jsx)(`div`,{role:`note`,className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`Exact generation block boundaries are unavailable. These visible-message sections can still be saved, but this testcase cannot be replayed against a specific style guide.`}),(0,O.jsxs)(`fieldset`,{children:[(0,O.jsxs)(`legend`,{className:`text-sm font-semibold text-gray-900`,children:[(0,O.jsx)(M,{step:1,done:!0}),` Testcase quality`]}),(0,O.jsx)(`div`,{className:`mt-2 grid gap-3 sm:grid-cols-2`,children:[{value:o.Good,label:`Good example`,description:`Future messages should preserve what works here.`,Icon:_},{value:o.Bad,label:`Bad example`,description:`Future messages should improve on this block.`,Icon:v}].map(({value:e,label:t,description:n,Icon:r})=>(0,O.jsxs)(`label`,{className:f(`flex cursor-pointer items-start gap-3 rounded-lg border p-3`,S===e?e===o.Good?`border-emerald-300 bg-emerald-50 text-emerald-900`:`border-red-300 bg-red-50 text-red-900`:`border-gray-200 bg-white text-gray-700 hover:border-gray-300`),children:[(0,O.jsx)(`input`,{type:`radio`,name:`testcase-quality`,value:e,checked:S===e,onChange:q,required:!0,className:`sr-only`}),(0,O.jsx)(r,{className:`mt-0.5 h-5 w-5 shrink-0`}),(0,O.jsxs)(`span`,{children:[(0,O.jsx)(`span`,{className:`block text-sm font-semibold`,children:t}),(0,O.jsx)(`span`,{className:`mt-0.5 block text-xs opacity-75`,children:n})]})]},e))})]}),(0,O.jsxs)(`section`,{children:[(0,O.jsx)(`div`,{className:`mb-2 flex items-center justify-between`,children:(0,O.jsxs)(`h4`,{className:`text-sm font-semibold text-gray-900`,children:[(0,O.jsx)(M,{step:2,done:!!X}),` Generated message`]})}),(0,O.jsx)(`p`,{className:`mb-3 text-xs leading-5 text-gray-500`,children:y?`The message as it was sent, split into the exact blocks the generation run produced. Select the one block this testcase is about.`:`The visible message, split into subject and paragraph sections. Exact block attribution is unavailable â select the section this testcase is about.`}),(0,O.jsx)(`div`,{className:`max-h-[36rem] space-y-2 overflow-y-auto pr-1`,children:g.map((e,t)=>(0,O.jsxs)(`button`,{type:`button`,"data-block-index":t,onClick:G,"aria-pressed":T===t,className:f(`w-full rounded-lg border border-l-4 p-3 text-left transition-colors`,T===t?`border-brand-400 border-l-brand-500 bg-brand-50 ring-1 ring-brand-200`:`border-gray-200 border-l-gray-300 bg-white hover:border-gray-300 hover:border-l-gray-400`),children:[(0,O.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,O.jsx)(`span`,{className:`text-xs font-medium tabular-nums text-gray-400`,children:t+1}),(0,O.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-500`,children:ee(e.blockKind)}),e.openerAngle?(0,O.jsx)(`span`,{className:`rounded-full bg-brand-100 px-2 py-0.5 text-xs font-medium text-brand-700`,children:j(e.openerAngle)}):null,e.blockId&&y?(0,O.jsx)(`span`,{className:`font-mono text-micro text-gray-400`,children:e.blockId}):null]}),(0,O.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap text-sm leading-6 text-gray-800`,children:e.text})]},`${e.blockId??`block`}-${t}`))})]}),Z&&X?(0,O.jsxs)(`section`,{className:`space-y-4`,children:[(0,O.jsxs)(`h4`,{className:`text-sm font-semibold text-gray-900`,children:[(0,O.jsx)(M,{step:3,done:Q}),` `,w?`What went wrong`:`Why this works`]}),w?(0,O.jsxs)(`div`,{className:`space-y-4`,children:[(0,O.jsxs)(`label`,{className:`block text-sm font-medium text-gray-900`,children:[`What was wrong?`,(0,O.jsx)(`textarea`,{value:F,onChange:Y,rows:4,required:!0,className:`mt-1 w-full rounded-md border border-gray-300 bg-white p-3 text-sm shadow-xs focus:border-brand-500 focus:ring-brand-500`,placeholder:`Explain the problem with this generated block.`})]}),(0,O.jsxs)(`label`,{className:`block text-sm font-medium text-gray-900`,children:[`What c
2ould be better?`,(0,O.jsx)(`textarea`,{value:L,onChange:te,rows:4,required:!0,className:`mt-1 w-full rounded-md border border-gray-300 bg-white p-3 text-sm shadow-xs focus:border-brand-500 focus:ring-brand-500`,placeholder:`Provide better wording or describe the expected result.`})]})]}):(0,O.jsxs)(`label`,{className:`block text-sm font-medium text-gray-900`,children:[`Commentary`,(0,O.jsx)(`textarea`,{value:N,onChange:J,rows:6,className:`mt-1 w-full rounded-md border border-gray-300 bg-white p-3 text-sm shadow-xs focus:border-brand-500 focus:ring-brand-500`,placeholder:`Add context about what makes this a useful positive example.`})]})]}):null,V?(0,O.jsx)(`p`,{className:`text-sm font-medium text-red-600`,children:V}):null]})})})}var P={xs:`px-1.5 py-0.5 text-micro`,sm:`px-2 py-1 text-xs`,md:`px-2.5 py-1.5 text-sm`};function F({surface:e,messageText:t,subjectText:n,contextLabel:r,contextUrl:o,className:s,size:c=`sm`,msgGenId:l,campaignId:u,projectId:d,candidateId:p,dispatchMessageId:m,blocks:h}){let _=g(a(i.user)?.email??``),v=a(i.isDev),[b,S]=(0,x.useState)(!1),[w,T]=(0,x.useState)(null),E=(0,x.useCallback)(e=>{e.stopPropagation(),S(!0),T(null)},[]);return!_||!v||!t?.trim()?null:(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`span`,{className:f(`inline-flex items-center gap-1 align-middle`,s),children:[(0,O.jsxs)(`button`,{type:`button`,onClick:E,className:f(`inline-flex cursor-pointer items-center gap-1 rounded-md bg-white font-semibold text-gray-600 shadow-xs ring-1 ring-inset ring-gray-200 transition-colors hover:bg-gray-50 hover:text-brand-700`,P[c]),children:[(0,O.jsx)(C,{className:`h-3.5 w-3.5 shrink-0`}),`Add testcase`]}),w?(0,O.jsx)(`span`,{className:`inline-flex items-center text-red-500`,"data-tooltip-id":`tooltip`,"data-tooltip-content":`Couldn't save: ${w}. Click Add testcase to retry.`,role:`alert`,children:(0,O.jsx)(y,{className:`h-4 w-4`})}):null]}),(0,O.jsx)(N,{open:b,setOpen:S,messageText:t,subjectText:n??void 0,blocks:h??void 0,context:{surface:e,contextLabel:r??void 0,contextUrl:o??void 0,campaignId:u??void 0,projectId:d??void 0,candidateId:p??void 0,dispatchMessageId:m??void 0,msgGenId:l??void 0},onError:T})]})}export{F as t};
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.