@capagents/forgeqe 2.10.2 → 2.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/forgeqe.js +1687 -1680
  2. package/dist/web/assets/{Agent-CTa1NV2r.js → Agent-DaA5WhAY.js} +7 -7
  3. package/dist/web/assets/ApiTests-B7xsTGyo.js +10 -0
  4. package/dist/web/assets/Browse-ByYCyAwd.js +2 -0
  5. package/dist/web/assets/{Chat-CTM0o79z.js → Chat-D1-cYNBr.js} +3 -3
  6. package/dist/web/assets/{CommandPalette-Btn4nn-X.js → CommandPalette-DbxKJJJB.js} +1 -1
  7. package/dist/web/assets/{Compare-CDUYhx9t.js → Compare-CYLFEtJl.js} +1 -1
  8. package/dist/web/assets/{Cost-CNMDGRFw.js → Cost-Csz0jMHo.js} +1 -1
  9. package/dist/web/assets/{Data-BMNUhONs.js → Data-BWTme_Yw.js} +1 -1
  10. package/dist/web/assets/Desktop-rZ0vB6Ie.js +1 -0
  11. package/dist/web/assets/{DesktopReview-C2XKQ1ci.js → DesktopReview-_Xha22_d.js} +1 -1
  12. package/dist/web/assets/{Evidence-C52DZo6K.js → Evidence-DmUyZy9F.js} +1 -1
  13. package/dist/web/assets/{Explore-B8oOi-Y3.js → Explore-2wzgwz3J.js} +2 -2
  14. package/dist/web/assets/{Features-Cv7fC5_f.js → Features-DazEWqYu.js} +1 -1
  15. package/dist/web/assets/Flags-BTt0-pqd.js +2 -0
  16. package/dist/web/assets/{Flaky-CWp3Mk2A.js → Flaky-CjkQp73T.js} +1 -1
  17. package/dist/web/assets/Impact-De87sv5J.js +3 -0
  18. package/dist/web/assets/Jobs-aiNGBVHL.js +5 -0
  19. package/dist/web/assets/{KindPage-3dMvQuEE.js → KindPage-CrGoFeSa.js} +4 -4
  20. package/dist/web/assets/Migration-BAhQ1DZO.js +2 -0
  21. package/dist/web/assets/{Product-BD9yuHYw.js → Product-DpK-PIxV.js} +2 -2
  22. package/dist/web/assets/{Production-DkNaydSw.js → Production-D6A89rZZ.js} +1 -1
  23. package/dist/web/assets/{Quality-B6PbFqMj.js → Quality-Bc5wCsog.js} +1 -1
  24. package/dist/web/assets/{Readiness-DB8pt7If.js → Readiness-CoVgZw2X.js} +1 -1
  25. package/dist/web/assets/Record-DcgBatJJ.js +2 -0
  26. package/dist/web/assets/Regression-BJLYrqST.js +5 -0
  27. package/dist/web/assets/{Reports-a_CffJt-.js → Reports-DYfyfEDy.js} +2 -2
  28. package/dist/web/assets/{Response-DzfPu2JF.js → Response-CNLi9Dqu.js} +2 -2
  29. package/dist/web/assets/{RunDiff-D5gKeDXi.js → RunDiff-BMTdRhii.js} +1 -1
  30. package/dist/web/assets/{Runs-Dm5ANo6L.js → Runs-lb78rvPV.js} +2 -2
  31. package/dist/web/assets/{TestCases-BerwP4i-.js → TestCases-CfUwd67O.js} +1 -1
  32. package/dist/web/assets/TestData-DP7cvW48.js +2 -0
  33. package/dist/web/assets/{TestDebt-nOu8lr8e.js → TestDebt-CqARxL7k.js} +1 -1
  34. package/dist/web/assets/Tosca-CLAz9tWT.js +3 -0
  35. package/dist/web/assets/{WhatsNew-DhfMzlEe.js → WhatsNew-1lhTRE5Z.js} +1 -1
  36. package/dist/web/assets/{dataParts-C45wq7v3.js → dataParts-DI_OJhy5.js} +1 -1
  37. package/dist/web/assets/{fold-Dwt3UNdL.js → fold-pOBiaSlF.js} +1 -1
  38. package/dist/web/assets/frame-CYYiRu5P.js +4 -0
  39. package/dist/web/assets/index-CNDoTeRV.css +2 -0
  40. package/dist/web/assets/index-D4a0w3Vl.js +67 -0
  41. package/dist/web/assets/{logos-DioTVxSG.js → logos-DfCytw3-.js} +1 -1
  42. package/dist/web/assets/{palette-NCegHokQ.js → palette-Cj4CUs0K.js} +1 -1
  43. package/dist/web/assets/{qualityParts-Dz6WY4Dd.js → qualityParts-C9FItsTg.js} +1 -1
  44. package/dist/web/assets/{rows-CEQ3pIjG.js → rows-D6rPRkHl.js} +1 -1
  45. package/dist/web/assets/{thread-Bv6FCIE3.js → thread-DQdyL3Sv.js} +2 -2
  46. package/dist/web/assets/{usePageChat-DJh3XRM-.js → usePageChat-Dl2aUtHP.js} +1 -1
  47. package/dist/web/index.html +3 -3
  48. package/package.json +1 -1
  49. package/py/forgeqe_engine/memory.py +10 -2
  50. package/py/forgeqe_engine/recordsession.py +58 -1
  51. package/py/forgeqe_engine/varying.py +120 -0
  52. package/py/forgeqe_engine/webrecord.py +19 -1
  53. package/py/forgeqe_engine/webrecord_page.py +7 -1
  54. package/py/forgeqe_engine/workflow_yaml.py +18 -1
  55. package/dist/web/assets/ApiTests-myBc8YrX.js +0 -10
  56. package/dist/web/assets/Browse-DtPtOuC5.js +0 -2
  57. package/dist/web/assets/Desktop-D--13188.js +0 -1
  58. package/dist/web/assets/Flags-_NaTDiaX.js +0 -2
  59. package/dist/web/assets/Impact-B3gXURFJ.js +0 -3
  60. package/dist/web/assets/Jobs-CdPyMQOp.js +0 -5
  61. package/dist/web/assets/Migration-CKBYH-pq.js +0 -2
  62. package/dist/web/assets/Record-CrdwIExv.js +0 -2
  63. package/dist/web/assets/Regression-CqQzw20T.js +0 -5
  64. package/dist/web/assets/TestData-BsIjvM8N.js +0 -2
  65. package/dist/web/assets/Tosca-fyYkjQXv.js +0 -3
  66. package/dist/web/assets/frame-ssoXyr9G.js +0 -4
  67. package/dist/web/assets/index-CnfjkjcU.css +0 -2
  68. package/dist/web/assets/index-LKB05P1m.js +0 -67
@@ -1 +1 @@
1
- import{An as e,Ar as t,C as n,Dn as r,Ir as i,Nr as a,Tn as o,a as s,fn as c,it as l,j as u,kr as d,ln as f,pr as p,wr as m,wt as h}from"./line-icons-CQ-3V8ax.js";import{B as g,R as _,V as v,Zt as y,a as b,c as x,f as ee,ft as S,i as C,l as te,o as w,st as ne,t as T}from"./filters-CflRmNDz.js";import{yt as E}from"./frame-ssoXyr9G.js";import{n as D}from"./markdown-nTIj9lyp.js";import{O as re,r as O}from"./index-LKB05P1m.js";import{i as k,r as ie}from"./segmented-CAf_qz5Z.js";import{a as A}from"./dataParts-C45wq7v3.js";var j=i(a(),1),M=y();function N(e){return(e.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||``).replace(/\.(exe|app)$/i,``).toLowerCase().replace(/[^a-z0-9_.-]+/g,`-`).replace(/^[^a-z]+/,``).replace(/-+$/,``).slice(0,40)||`app`}function P({value:e,onChange:t,onPicked:n,onError:r,className:i}){let[a,o]=(0,j.useState)(!1),s=async()=>{o(!0),r(``);try{let e=await S.browse();`path`in e?(t(e.path),n?.(e.path,e.name)):`unavailable`in e&&r(e.unavailable)}catch(e){r(e.message)}finally{o(!1)}};return(0,M.jsxs)(`div`,{className:g(`flex min-w-0 gap-2`,i),children:[(0,M.jsx)(b,{"aria-label":`App's path`,value:e,spellCheck:!1,placeholder:`C:\\Program Files\\Contoso\\Billing.exe`,onChange:e=>t(e.target.value),className:`min-w-0 flex-1 font-mono text-[13px]`}),(0,M.jsxs)(_,{type:`button`,disabled:a,onClick:()=>void s(),"data-tip":`Choose the app's .exe on this computer`,children:[(0,M.jsx)(h,{"aria-hidden":`true`}),a?`Choosing…`:`Browse…`]})]})}var F={click:[`target`,`timeout`,`note`],double_click:[`target`,`timeout`,`note`],type:[`target`,`text`,`timeout`,`note`],select:[`target`,`value`,`timeout`,`note`],keys:[`keys`,`note`],expect:[`target`,`text`,`timeout`,`note`],wait:[`seconds`,`note`],wait_for:[`target`,`text`,`timeout`,`note`],launch:[`timeout`,`note`],close:[`note`],expect_image:[`timeout`,`note`]};function I({p:e}){return(0,M.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,M.jsx)(`ul`,{className:`m-0 flex flex-col gap-0.5 pl-5 text-[13px] text-ink-2`,children:e.summary.map((e,t)=>(0,M.jsx)(`li`,{className:`[overflow-wrap:anywhere]`,children:e},t))}),(0,M.jsx)(`pre`,{className:`m-0 max-h-[200px] overflow-auto rounded-[10px] bg-surface-muted p-2.5 font-mono text-[12px] leading-relaxed whitespace-pre-wrap`,children:e.diff.map((e,t)=>(0,M.jsx)(`span`,{className:g(`block`,e.startsWith(`+`)?`text-pass`:e.startsWith(`-`)?`text-fail`:`text-muted`),children:e},t))})]})}function L({label:e,children:t}){return(0,M.jsxs)(`label`,{className:`flex min-w-0 flex-col gap-1 text-[13px] font-medium`,children:[e,t]})}function ae({workflow:e,step:r,mode:i,onDone:a,onCancel:s}){let c=F[r.op]??[`note`],l=r.fields??{},[u,d]=(0,j.useState)({automation_id:l.target?.automation_id??``,name:l.target?.name??``,control_type:l.target?.control_type??``}),[f,m]=(0,j.useState)(l.text??``),[h,g]=(0,j.useState)(l.value??``),[v,y]=(0,j.useState)(l.keys??``),[x,ee]=(0,j.useState)(l.seconds===void 0?``:String(l.seconds)),[C,te]=(0,j.useState)(l.timeout===void 0?``:String(l.timeout)),[w,ne]=(0,j.useState)(l.note??``),[T,E]=(0,j.useState)(null),[D,re]=(0,j.useState)(``),[O,k]=(0,j.useState)(!1),ie=()=>{let e={};return c.includes(`target`)&&(u.automation_id!==(l.target?.automation_id??``)||u.name!==(l.target?.name??``)||u.control_type!==(l.target?.control_type??``))&&(e.target=u),c.includes(`text`)&&f!==(l.text??``)&&(e.text=f),c.includes(`value`)&&h!==(l.value??``)&&(e.value=h),c.includes(`keys`)&&v!==(l.keys??``)&&(e.keys=v),c.includes(`seconds`)&&x!==(l.seconds===void 0?``:String(l.seconds))&&(e.seconds=Number(x)),c.includes(`timeout`)&&C!==(l.timeout===void 0?``:String(l.timeout))&&C.trim()&&(e.timeout=Number(C)),c.includes(`note`)&&w!==(l.note??``)&&(e.note=w),e},A=async t=>{k(!0),re(``);try{let n=await S.editStep({workflow:e,step:r.n,action:i,...i===`edit`?{fields:ie()}:{},...t?{version:t}:{}});n.written?a():E(n)}catch(e){re(e.message)}finally{k(!1)}};(0,j.useEffect)(()=>{i===`remove`&&A()},[]);let N=()=>E(null);return(0,M.jsxs)(`div`,{className:`mb-2 ml-9 flex flex-col gap-3 rounded-[12px] bg-surface-muted p-3`,children:[i===`edit`&&!T&&(0,M.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,180px),1fr))] gap-2.5`,children:[c.includes(`target`)&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(L,{label:`Control's name`,children:(0,M.jsx)(b,{size:`sm`,value:u.name,maxLength:300,onChange:e=>(d({...u,name:e.target.value}),N()),className:`bg-bg`})}),(0,M.jsx)(L,{label:`Automation id`,children:(0,M.jsx)(b,{size:`sm`,value:u.automation_id,maxLength:300,spellCheck:!1,onChange:e=>(d({...u,automation_id:e.target.value}),N()),className:`bg-bg font-mono text-[12.5px]`})}),(0,M.jsx)(L,{label:`Control type`,children:(0,M.jsx)(b,{size:`sm`,value:u.control_type,maxLength:60,spellCheck:!1,placeholder:`Button`,onChange:e=>(d({...u,control_type:e.target.value}),N()),className:`bg-bg`})})]}),c.includes(`text`)&&(0,M.jsx)(L,{label:r.op===`type`?`Text to type`:`Text it shows`,children:(0,M.jsx)(b,{size:`sm`,value:f,maxLength:500,onChange:e=>m(e.target.value),className:`bg-bg`})}),c.includes(`value`)&&(0,M.jsx)(L,{label:`Item to choose`,children:(0,M.jsx)(b,{size:`sm`,value:h,maxLength:500,onChange:e=>g(e.target.value),className:`bg-bg`})}),c.includes(`keys`)&&(0,M.jsx)(L,{label:`Keys`,children:(0,M.jsx)(b,{size:`sm`,value:v,maxLength:100,spellCheck:!1,placeholder:`ctrl+s`,onChange:e=>y(e.target.value),className:`bg-bg font-mono text-[12.5px]`})}),c.includes(`seconds`)&&(0,M.jsx)(L,{label:`Wait (seconds)`,children:(0,M.jsx)(b,{size:`sm`,type:`number`,min:0,max:600,value:x,onChange:e=>ee(e.target.value),className:`bg-bg`})}),c.includes(`timeout`)&&(0,M.jsx)(L,{label:`Timeout (seconds)`,children:(0,M.jsx)(b,{size:`sm`,type:`number`,min:0,max:600,value:C,placeholder:`default`,onChange:e=>te(e.target.value),className:`bg-bg`})}),c.includes(`note`)&&(0,M.jsx)(L,{label:`Note`,children:(0,M.jsx)(b,{size:`sm`,value:w,maxLength:200,onChange:e=>ne(e.target.value),className:`bg-bg`})})]}),i===`remove`&&!T&&!D&&(0,M.jsx)(`p`,{role:`status`,className:`m-0 text-[13px] text-muted`,children:`Working out the change…`}),T&&(0,M.jsx)(I,{p:T}),D&&(0,M.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[10px] bg-fail-soft px-3 py-2 text-[13px] text-fail [overflow-wrap:anywhere]`,children:D}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[T?(0,M.jsxs)(_,{size:`sm`,variant:i===`remove`?`destructive`:`primary`,disabled:O,onClick:()=>void A(T.version),children:[i===`remove`?(0,M.jsx)(p,{"aria-hidden":`true`}):(0,M.jsx)(n,{"aria-hidden":`true`}),O?`Saving…`:i===`remove`?`Delete step ${r.n}`:`Save the change`]}):i===`edit`&&(0,M.jsx)(_,{size:`sm`,variant:`primary`,disabled:O||!Object.keys(ie()).length,onClick:()=>void A(),children:O?`Checking…`:`Preview the change`}),T&&i===`edit`&&(0,M.jsxs)(_,{size:`sm`,onClick:()=>E(null),children:[(0,M.jsx)(o,{"aria-hidden":`true`}),`Change it more`]}),(0,M.jsxs)(_,{size:`sm`,variant:`ghost`,onClick:s,children:[(0,M.jsx)(t,{"aria-hidden":`true`}),`Cancel`]})]})]})}var R=[{id:`typed`,label:`As typed`,note:`The workflow types exactly this.`},{id:`data`,label:`Test data`,note:`A named value the replay fills in: its own value, a row of a data file, or one you give when it runs.`},{id:`secret`,label:`Secret`,note:`Read from an environment variable when it replays; what was typed leaves the workflow.`}],z={replay:[`Replaying the workflow`,`Replayed the workflow`,`working`],validate:[`Checking the workflow`,`Checked the workflow`,`searching`]};async function oe(e){let t=await S.editStep(e);await S.editStep({...e,version:t.version})}var B=[{id:`check_text`,label:`Check a control shows a text`,control:!0,text:`need`},{id:`check_present`,label:`Check a control is there`,control:!0},{id:`wait_for`,label:`Wait for a control`,control:!0,text:`may`},{id:`wait_gone`,label:`Wait until a control is gone`,control:!0},{id:`wait`,label:`Wait some seconds`,control:!1},{id:`keys`,label:`Press keys`,control:!1}];function se({step:t,onAdd:n}){let[r,i]=(0,j.useState)(`check_text`),a=t.fields?.target,[o,s]=(0,j.useState)({name:a?.name??``,automation_id:a?.automation_id??``,control_type:a?.control_type??``}),[c,l]=(0,j.useState)(``),[u,d]=(0,j.useState)(`2`),[f,p]=(0,j.useState)(``),m=B.find(e=>e.id===r),h=m.control?!!(o.name.trim()||o.automation_id.trim())&&(m.text!==`need`||!!c.trim()):r===`wait`?Number(u)>0:!!f.trim();return(0,M.jsxs)(`form`,{className:`flex flex-col gap-2.5 p-3`,onSubmit:e=>{e.preventDefault(),h&&n({kind:r,...m.control?{target:o}:{},...m.text&&c.trim()?{text:c}:{},...r===`wait`?{seconds:Number(u)}:{},...r===`keys`?{keys:f}:{}})},children:[(0,M.jsxs)(`p`,{className:`m-0 text-[13px] font-semibold`,children:[`After step `,t.n]}),(0,M.jsx)(w,{size:`sm`,"aria-label":`What to add`,value:r,onChange:e=>i(e.target.value),children:B.map(e=>(0,M.jsx)(`option`,{value:e.id,children:e.label},e.id))}),m.control&&(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[`Control's name`,(0,M.jsx)(b,{size:`sm`,value:o.name,maxLength:300,onChange:e=>s({...o,name:e.target.value})})]}),(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[`Automation id`,(0,M.jsx)(b,{size:`sm`,value:o.automation_id,maxLength:300,spellCheck:!1,onChange:e=>s({...o,automation_id:e.target.value}),className:`font-mono text-[12.5px]`})]})]}),m.text&&(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[m.text===`need`?`The text it shows`:`Showing the text (optional)`,(0,M.jsx)(b,{size:`sm`,value:c,maxLength:500,placeholder:`Invoice saved`,onChange:e=>l(e.target.value)})]}),r===`wait`&&(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[`Seconds`,(0,M.jsx)(b,{size:`sm`,type:`number`,min:1,max:600,value:u,onChange:e=>d(e.target.value)})]}),r===`keys`&&(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[`Keys`,(0,M.jsx)(b,{size:`sm`,value:f,maxLength:100,spellCheck:!1,placeholder:`ctrl+s`,onChange:e=>p(e.target.value),className:`font-mono text-[12.5px]`})]}),(0,M.jsx)(`p`,{className:`m-0 text-[12px] text-muted`,children:`The control is filled from this step's; change it for another. A wait for a control is better than a fixed wait.`}),(0,M.jsxs)(_,{type:`submit`,size:`sm`,variant:`primary`,disabled:!h,className:`self-start`,children:[(0,M.jsx)(e,{"aria-hidden":`true`}),`Add`]})]})}var V=e=>e.name||e.automation_id||`the control`;function ce({pictures:e,step:t,busy:n,onPick:r}){let[i,a]=(0,j.useState)(0),o=e[Math.min(i,e.length-1)],[s,c]=(0,j.useState)(``),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(null);(0,j.useEffect)(()=>{let e=!1;return c(``),u(``),f(null),S.shot(o.run,o.n).then(t=>!e&&c(t),t=>!e&&u(t.message)),S.controls(o.run,o.n).then(t=>!e&&f(t),()=>{}),()=>{e=!0}},[o.run,o.n]);let p=(e,t)=>`${Math.max(0,Math.min(100,e/t*100))}%`,m=d&&d.w>0?[...d.controls].sort((e,t)=>t.w*t.h-e.w*e.h):[];return(0,M.jsxs)(`div`,{className:`flex flex-col gap-2 pr-3 pb-3 pl-3 sm:pl-[76px]`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.length>1&&(0,M.jsx)(`div`,{role:`radiogroup`,"aria-label":`Pictures of step ${t}`,className:`flex w-fit max-w-full flex-wrap gap-1 rounded-[10px] bg-surface-strong p-1`,children:e.map((e,t)=>(0,M.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===i,onClick:()=>a(t),className:k(t===i),children:e.label},e.label))}),(0,M.jsxs)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:[o.note,m.length>0?` Click a control to check that it shows its text, or that it is there.`:``]})]}),l&&(0,M.jsx)(`p`,{className:`m-0 text-sm text-fail`,children:l}),!s&&!l&&(0,M.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`Loading the picture…`}),s&&(0,M.jsxs)(`div`,{className:`relative w-full max-w-[720px] overflow-hidden rounded-[10px] border border-line-soft`,style:m.length?{aspectRatio:`${d.w} / ${d.h}`}:void 0,children:[(0,M.jsx)(`img`,{src:s,alt:`The app after step ${t}, ${o.label.toLowerCase()}`,className:m.length?`absolute inset-0 size-full object-fill`:`block w-full`}),m.map((e,t)=>{let i=e.text?`Check ${V(e)} shows "${e.text}"`:`Check ${V(e)} is there`;return(0,M.jsx)(`button`,{type:`button`,disabled:n,"aria-label":i,"data-tip":i,onClick:()=>r({target:{...e.automation_id?{automation_id:e.automation_id}:{},...e.name?{name:e.name}:{},...e.control_type?{control_type:e.control_type}:{}},...e.text?{text:e.text}:{}}),className:`absolute cursor-pointer rounded-[3px] border-0 bg-transparent p-0 outline-none hover:bg-accent/15 hover:ring-2 hover:ring-accent focus-visible:bg-accent/15 focus-visible:ring-2 focus-visible:ring-accent`,style:{left:p(e.x,d.w),top:p(e.y,d.h),width:p(e.w,d.w),height:p(e.h,d.h)}},`${t}-${e.automation_id||e.name}`)})]})]})}function le({v:e,secrets:t,onSave:r,busy:i}){let[a,o]=(0,j.useState)(e.as),[s,c]=(0,j.useState)(e.name??``),[l,u]=(0,j.useState)(e.value??``);(0,j.useEffect)(()=>{o(e.as),c(e.name??``),u(e.value??``)},[e]);let d=R.filter(t=>e.op===`type`||t.id!==`secret`),f=a!==e.as||s!==(e.name??``)||l!==(e.value??``),p=a===`typed`?!0:a===`data`?/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(s):/^[A-Z_][A-Z0-9_]{0,63}$/.test(s);return(0,M.jsxs)(`li`,{className:`flex flex-wrap items-start gap-x-4 gap-y-2 border-t border-line-soft px-3 py-2.5 first:border-t-0`,children:[(0,M.jsx)(`span`,{className:`w-6 flex-none pt-2 text-right font-mono text-[12px] text-muted tabular-nums`,children:e.n}),(0,M.jsxs)(`span`,{className:`flex min-w-0 flex-[1_1_220px] flex-col pt-1.5`,children:[(0,M.jsx)(`span`,{className:`text-[14px] text-ink [overflow-wrap:anywhere]`,children:e.line}),(0,M.jsx)(`span`,{className:`text-[12.5px] text-ink-2`,children:R.find(e=>e.id===a)?.note})]}),(0,M.jsxs)(`span`,{className:`flex flex-[1_1_360px] flex-wrap items-center gap-2`,children:[(0,M.jsx)(w,{"aria-label":`Where the value of step ${e.n} comes from`,value:a,disabled:i,onChange:e=>o(e.target.value),className:`w-[150px] flex-none`,children:d.map(e=>(0,M.jsx)(`option`,{value:e.id,children:e.label},e.id))}),a!==`typed`&&(0,M.jsx)(b,{"aria-label":a===`secret`?`The secret's environment variable`:`The test data's name`,value:s,maxLength:64,spellCheck:!1,list:a===`secret`?`desktop-secrets`:void 0,placeholder:a===`secret`?`BILLING_PASSWORD`:`customer`,onChange:e=>c(a===`secret`?e.target.value.toUpperCase():e.target.value),className:`w-[170px] flex-none font-mono text-[13px]`}),a!==`secret`&&(0,M.jsx)(b,{"aria-label":a===`data`?`Its value`:`The value`,value:l,maxLength:500,onChange:e=>u(e.target.value),className:`min-w-[140px] flex-1`}),a===`secret`&&!t.includes(s)&&s&&(0,M.jsx)(`span`,{className:`text-[12px] text-warn`,children:`Not in desktop.secrets yet`}),(0,M.jsxs)(_,{size:`sm`,variant:`primary`,disabled:i||!f||!p,onClick:()=>r(a,a===`typed`?void 0:s,a===`secret`?void 0:l),children:[(0,M.jsx)(n,{"aria-hidden":`true`}),`Save`]})]}),(0,M.jsx)(`datalist`,{id:`desktop-secrets`,children:t.map(e=>(0,M.jsx)(`option`,{value:e},e))})]})}function ue({view:e,job:t,rows:n,onRun:i,busy:a,heal:o}){let[s,c]=(0,j.useState)(()=>Object.fromEntries(e.variables.map(e=>[e.name,e.value]))),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(o),[p,m]=(0,j.useState)(!1),h=e.lastRun,g=l.startsWith(`file:`)?{file:l.slice(5)}:l.startsWith(`request:`)?{request:l.slice(8)}:void 0,y=t&&t.kind===`replay`&&t.target===e.workflow.path;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`p`,{className:`m-0 text-sm text-ink-2`,children:`Replay plays the steps in the app with no model, as a scheduled run or CI will, and takes over the mouse and keyboard while it runs: use a test machine and a test account.`}),(0,M.jsxs)(`form`,{className:`flex flex-col gap-3 rounded-[12px] card border p-3`,onSubmit:e=>{e.preventDefault(),i({variables:s,...g?{rows:g}:{},heal:d,updateBaselines:p})},children:[e.variables.length>0&&(0,M.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,180px),1fr))] gap-3`,children:e.variables.map(e=>(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[13px] font-medium text-ink-2`,children:[e.name,(0,M.jsx)(b,{value:s[e.name]??``,onChange:t=>c({...s,[e.name]:t.target.value})})]},e.name))}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,M.jsxs)(`label`,{className:`flex min-w-[220px] flex-col gap-1 text-[13px] font-medium text-ink-2`,children:[`Test data`,(0,M.jsxs)(w,{value:l,onChange:e=>u(e.target.value),children:[(0,M.jsx)(`option`,{value:``,children:`Once, with the values above`}),n.files.map(e=>(0,M.jsxs)(`option`,{value:`file:${e}`,children:[`Each row of `,e]},e)),n.requests.map(e=>(0,M.jsxs)(`option`,{value:`request:${e}`,children:[`Each row of request `,e]},e))]})]}),(0,M.jsxs)(`label`,{className:`flex min-h-10 items-center gap-2.5 text-sm text-ink-2`,children:[(0,M.jsx)(E,{checked:d,onChange:f,label:`Heal a step whose control moved`}),`Heal a moved control`]}),(0,M.jsxs)(`label`,{className:`flex min-h-10 items-center gap-2.5 text-sm text-ink-2`,children:[(0,M.jsx)(E,{checked:p,onChange:m,label:`Take new image baselines`}),`New image baselines`]}),(0,M.jsx)(`span`,{className:`flex-1`}),(0,M.jsxs)(_,{type:`submit`,variant:`primary`,disabled:a,children:[(0,M.jsx)(r,{"aria-hidden":`true`}),`Replay`]})]})]}),y&&(0,M.jsx)(A,{job:t,onStop:()=>void S.stop(),words:z}),h?(0,M.jsxs)(`section`,{"aria-labelledby":`desktop-last-run`,className:`flex flex-col gap-2`,children:[(0,M.jsx)(`h3`,{id:`desktop-last-run`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Last replay`}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-[12px] card border px-3 py-2.5 text-sm`,children:[(0,M.jsx)(x,{tone:h.ok?`pass`:`fail`,children:h.many?`${h.many.passed} of ${h.many.total} passed`:h.ok?`Passed`:`Failed`}),(0,M.jsxs)(`span`,{className:`text-muted`,children:[O(h.at),` · `,v(e.replays,`replay`),` in all`]}),h.failed&&(0,M.jsxs)(`span`,{className:`min-w-0 flex-[1_1_240px] text-[13px] text-fail [overflow-wrap:anywhere]`,children:[`Step `,h.failed.index,`: `,h.failed.error]}),(0,M.jsx)(`span`,{className:`flex-1`}),h.report&&(0,M.jsx)(D,{path:h.report,children:`Report`})]})]}):(0,M.jsx)(te,{className:`py-3`,children:`Not replayed yet.`})]})}function de({workflow:i,onClose:a,backLabel:h=`Back`,notices:y}){let[b,w]=(0,j.useState)(null),[E,D]=(0,j.useState)(``),[O,A]=(0,j.useState)(!1),[N,P]=(0,j.useState)(`steps`),[F,I]=(0,j.useState)(``),[L,R]=(0,j.useState)(`all`),[z,B]=(0,j.useState)(null),[V,de]=(0,j.useState)(null),[H,U]=(0,j.useState)(null),[fe,W]=(0,j.useState)(``),[G,pe]=(0,j.useState)(null),[me,he]=(0,j.useState)({files:[],requests:[]}),[ge,_e]=(0,j.useState)(!0),K=(0,j.useCallback)(()=>{S.review(i).then(e=>{w(e),D(``)},e=>D(e.message))},[i]);(0,j.useEffect)(K,[K]);let q=(0,j.useCallback)(()=>{S.view().then(e=>{pe(e.job),he(e.rows),_e(e.heal)},()=>{})},[]);(0,j.useEffect)(q,[q]);let J=!!G?.running;(0,j.useEffect)(()=>{if(!J)return;let e=setInterval(q,1e3);return()=>clearInterval(e)},[J,q]);let ve=G&&!G.running?G.endedAt:``;(0,j.useEffect)(()=>{ve&&K()},[ve,K]);let Y=async(e,t)=>{A(!0),D(``),W(``);try{await e(),K(),t&&W(t)}catch(e){D(e.message)}finally{A(!1)}},ye=e=>void ne.start(e,{}).then(({id:e})=>location.hash=ee(`chats`,e),e=>D(e.message));if(!b)return E?(0,M.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:E}):(0,M.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Opening the workflow…`});let X=b.lastRun,be=new Map((X?.results??[]).map(e=>[e.n,e])),xe=!!X&&Date.parse(b.workflow.modified)>Date.parse(X.at),Z=b.steps.filter(e=>e.op.startsWith(`expect`)).length,Q=X&&!X.ok?X.failed?.index??0:0,$=Q?b.steps[Q-1]:void 0,Se=(X?.results??[]).filter(e=>!e.ok).length,Ce=F.toLowerCase().split(/\s+/).filter(Boolean),we=b.steps.filter(e=>Ce.every(t=>`${e.n} ${e.text} ${e.fields?.note||``}`.toLowerCase().includes(t))&&(L===`all`||(L===`checks`?e.op.startsWith(`expect`):be.get(e.n)?.ok===!1))),Te=e=>{P(`steps`),R(`all`),I(``),requestAnimationFrame(()=>document.getElementById(`dstep-${e}`)?.scrollIntoView({block:`center`,behavior:`smooth`}))},Ee=e=>void Y(async()=>{await S.replay({workflow:b.workflow.path,...e}),q()},`Replaying: the app opens on this computer.`),De=[{id:`steps`,label:`Steps`,n:b.steps.length},{id:`data`,label:`Test data`,n:b.values.length},{id:`run`,label:`Last run`}];return(0,M.jsxs)(`section`,{"aria-labelledby":`dreview-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,M.jsxs)(`div`,{className:`sticky top-0 z-20 -mx-1 flex flex-col gap-3 border-b border-line bg-bg px-1 py-3`,children:[a&&(0,M.jsx)(`div`,{children:(0,M.jsxs)(_,{size:`sm`,variant:`ghost`,onClick:a,className:`-ml-2 text-ink-2`,children:[(0,M.jsx)(s,{"aria-hidden":`true`}),h]})}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-[1_1_320px] flex-col gap-1`,children:[(0,M.jsx)(`h2`,{id:`dreview-title`,className:`m-0 min-w-0 truncate text-lg font-semibold`,"data-tip":b.workflow.name,children:b.workflow.name}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[13px] text-muted`,children:[(0,M.jsxs)(`span`,{children:[b.workflow.app||`no app`,` · `,v(b.steps.length,`step`),` · `,v(Z,`check`)]}),J&&G?.target===b.workflow.path?(0,M.jsx)(x,{tone:`running`,children:`Replaying…`}):X?(0,M.jsx)(x,{tone:X.ok?`pass`:`fail`,children:X.ok?`Last replay passed`:Q?`Last replay failed at step ${Q}`:`Last replay did not get through`}):(0,M.jsx)(x,{tone:`neutral`,icon:!1,children:`Not replayed yet`}),xe&&(0,M.jsx)(`span`,{children:`· you changed it since`})]})]}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsxs)(_,{onClick:()=>ye(`Desktop agent: look at the desktop workflow ${b.workflow.path} and tell me what to fix or add (a wait, a timeout, a dialog to dismiss, checks of the outcome); change it with desktop_edit_workflow only after showing me the change.`),"data-tip":`Ask the Desktop agent to improve it`,children:[(0,M.jsx)(m,{"aria-hidden":`true`}),`Improve`]}),(0,M.jsxs)(_,{variant:`primary`,disabled:J,onClick:()=>P(`run`),"data-tip":J?`A replay is going`:`Replay it with no model`,children:[(0,M.jsx)(r,{"aria-hidden":`true`}),`Replay`]})]})]})]}),y,E&&(0,M.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:E}),fe&&(0,M.jsx)(`p`,{role:`status`,className:`m-0 rounded-[10px] bg-pass-soft px-3 py-1.5 text-[13px] text-pass`,children:fe}),X&&!X.ok&&(0,M.jsxs)(`div`,{role:`alert`,className:`flex flex-col gap-2 rounded-[12px] border border-fail/30 bg-fail-soft px-4 py-3 text-sm`,children:[(0,M.jsxs)(`p`,{className:`m-0 font-semibold text-fail`,children:[Q?`Step ${Q} failed`:`The replay did not get through`,xe&&(0,M.jsx)(`span`,{className:`font-normal text-ink-2`,children:` · before your last change`})]}),$&&(0,M.jsx)(`p`,{className:`m-0 font-medium text-ink [overflow-wrap:anywhere]`,children:$.text}),(0,M.jsx)(`p`,{className:`m-0 line-clamp-3 text-[13px] text-ink-2 [overflow-wrap:anywhere]`,children:X.failed?.error||X.error||`It failed.`}),(0,M.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[$&&(0,M.jsxs)(_,{size:`sm`,onClick:()=>Te(Q),children:[(0,M.jsx)(l,{"aria-hidden":`true`}),`Show`]}),$&&Q>1&&(0,M.jsxs)(_,{size:`sm`,onClick:()=>(Te(Q),U({n:Q,mode:`edit`})),"data-tip":`Change the failed step: its control, text or timeout`,children:[(0,M.jsx)(o,{"aria-hidden":`true`}),`Change`]}),(0,M.jsxs)(_,{size:`sm`,variant:`ghost`,onClick:()=>ye(`Desktop agent: the last replay of ${b.workflow.path} failed${Q?` at step ${Q}`:``}. Read its report (${X.dir}), tell me why, and offer a fix.`),children:[(0,M.jsx)(f,{"aria-hidden":`true`}),`Ask why`]})]})]}),X&&X.ok&&X.heals>0&&!X.healsAccepted&&(0,M.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-3 rounded-[12px] bg-accent-soft px-3 py-2.5 text-sm`,children:[(0,M.jsxs)(`span`,{className:`min-w-0 flex-[1_1_240px]`,children:[`The last replay found `,v(X.heals,`moved control`),` and healed `,X.heals===1?`it`:`them`,`: write the new locators into the workflow?`]}),(0,M.jsxs)(_,{size:`sm`,disabled:O,onClick:()=>void Y(()=>S.acceptHeals(X.dir),`The healed locators are in the workflow.`),children:[(0,M.jsx)(d,{"aria-hidden":`true`}),`Accept`]})]}),(0,M.jsx)(`div`,{role:`tablist`,"aria-label":`This workflow`,className:ie,children:De.map(e=>(0,M.jsxs)(`button`,{type:`button`,role:`tab`,id:`dreview-tab-${e.id}`,"aria-selected":N===e.id,"aria-controls":`dreview-panel-${e.id}`,onClick:()=>P(e.id),className:k(N===e.id),children:[e.label,e.n!==void 0&&(0,M.jsx)(`span`,{className:`text-[12px] text-muted tabular-nums`,children:e.n}),e.id===`run`&&X&&(0,M.jsx)(`span`,{"aria-label":X.ok?`passed`:`failed`,className:g(`size-2 rounded-full`,X.ok?`bg-pass`:`bg-fail`)})]},e.id))}),(0,M.jsxs)(`div`,{role:`tabpanel`,id:`dreview-panel-${N}`,"aria-labelledby":`dreview-tab-${N}`,className:`flex min-w-0 flex-col gap-4`,children:[N===`steps`&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(C,{id:`dreview-step-search`,label:`Find a step`,value:F,onChange:I}),(0,M.jsx)(T,{items:[{id:`all`,label:`All`,n:b.steps.length},{id:`checks`,label:`Checks`,n:Z},...Se?[{id:`failed`,label:`Failed`,n:Se,alert:!0}]:[]],value:L,onChange:R})]}),Z===0&&(0,M.jsx)(`p`,{className:`m-0 rounded-[10px] bg-warn-soft px-3 py-2 text-[13px] text-warn`,children:`No checks of the outcome: a replay passes when its steps run. Add one with + after the step whose result matters.`}),we.length===0?(0,M.jsx)(`p`,{className:`m-0 rounded-[12px] card border px-4 py-4 text-sm text-muted`,children:`No step matches.`}):(0,M.jsx)(`ol`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-0 [&>li:first-child]:rounded-t-[12px] [&>li:last-child]:rounded-b-[12px]`,children:we.map((r,i)=>{let a=be.get(r.n),s=r.op.startsWith(`expect`),d=b.recorded?.shots[r.n],f=[...d&&b.recorded?[{label:`When recorded`,run:b.recorded.run,n:d,note:`The app after step ${r.n} as you recorded it.`}]:[],...a?.shot&&X?[{label:`Last replay`,run:X.dir,n:r.n,note:`The app after step ${r.n} on the last replay${xe?`, before your last change`:``}.`}]:[]];return(0,M.jsxs)(`li`,{id:`dstep-${r.n}`,className:g(`flex scroll-mt-48 flex-col`,i>0&&`border-t border-line-soft`,a&&!a.ok&&`bg-fail-soft`),children:[(0,M.jsxs)(`div`,{className:`group flex min-h-11 items-start gap-3 px-3 py-2`,children:[(0,M.jsx)(`span`,{className:`w-6 flex-none pt-0.5 text-right font-mono text-[12px] text-muted tabular-nums`,children:r.n}),(0,M.jsx)(`span`,{className:`flex w-4 flex-none justify-center pt-1`,children:a?a.ok?(0,M.jsx)(n,{size:14,strokeWidth:2.5,"aria-label":`Passed on the last replay`,className:`text-pass`}):(0,M.jsx)(t,{size:14,strokeWidth:2.5,"aria-label":`Failed on the last replay`,className:`text-fail`}):X?(0,M.jsx)(c,{size:14,"aria-label":`Not replayed`,className:`text-muted`}):s?(0,M.jsx)(u,{size:14,"aria-hidden":`true`,className:`text-pass`}):(0,M.jsx)(`span`,{"aria-hidden":`true`,className:`mt-1 size-1.5 rounded-full bg-line-strong`})}),(0,M.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,M.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[s&&(0,M.jsx)(x,{tone:`pass`,icon:!1,className:`min-h-5 px-2 text-[11px]`,children:`Check`}),r.op.startsWith(`wait`)&&(0,M.jsx)(x,{tone:`neutral`,icon:!1,className:`min-h-5 px-2 text-[11px]`,children:`Wait`}),(0,M.jsx)(`span`,{className:`min-w-0 text-[14px] text-ink [overflow-wrap:anywhere]`,children:r.text}),a?.healed&&(0,M.jsx)(x,{tone:`warn`,icon:!1,className:`min-h-5 px-2 text-[11px]`,children:`Healed`})]}),r.fields?.note&&(0,M.jsxs)(`span`,{className:`text-[12.5px] text-ink-2`,children:[`Note: `,r.fields.note]}),a&&!a.ok&&a.error&&(0,M.jsx)(`span`,{className:`line-clamp-2 text-[12.5px] text-fail [overflow-wrap:anywhere]`,"data-tip":a.error,children:a.error})]}),(0,M.jsxs)(`span`,{className:`relative flex flex-none items-center gap-0.5`,children:[(0,M.jsx)(_,{size:`icon`,variant:`icon`,disabled:O,"aria-haspopup":`dialog`,"aria-expanded":z===r.n,"aria-label":`Add a check or wait after step ${r.n}`,"data-tip":`Add a check or wait after step ${r.n}`,onClick:()=>B(z===r.n?null:r.n),className:`size-8`,children:(0,M.jsx)(e,{"aria-hidden":`true`})}),(0,M.jsx)(re,{open:z===r.n,onClose:()=>B(null),label:`Add after step ${r.n}`,role:`dialog`,side:`auto`,className:`right-0 w-[min(360px,calc(100vw-48px))]`,children:(0,M.jsx)(se,{step:r,onAdd:e=>{B(null),Y(()=>oe({workflow:b.workflow.path,step:r.n,action:`insert`,...e}),`Added after step ${r.n}.`)}})}),f.length>0&&(0,M.jsx)(_,{size:`icon`,variant:`icon`,"aria-label":`See the app after step ${r.n}`,"aria-expanded":V===r.n,"data-tip":`See the app after step ${r.n}`,onClick:()=>de(V===r.n?null:r.n),className:`size-8`,children:(0,M.jsx)(l,{"aria-hidden":`true`})}),(0,M.jsx)(_,{size:`icon`,variant:`icon`,"aria-label":`Change step ${r.n}`,"data-tip":`Change step ${r.n}`,onClick:()=>U({n:r.n,mode:`edit`}),className:`size-8`,children:(0,M.jsx)(o,{"aria-hidden":`true`})}),r.n>1&&(0,M.jsx)(_,{size:`icon`,variant:`icon`,"aria-label":`Drop step ${r.n}`,"data-tip":`Drop step ${r.n}`,onClick:()=>U({n:r.n,mode:`remove`}),className:`size-8 hover:text-fail`,children:(0,M.jsx)(p,{"aria-hidden":`true`})})]})]}),H&&H.n===r.n&&(0,M.jsx)(`div`,{className:`pr-3`,children:(0,M.jsx)(ae,{workflow:b.workflow.path,step:r,mode:H.mode,onCancel:()=>U(null),onDone:()=>{W(H.mode===`remove`?`Step ${r.n} dropped.`:`Step ${r.n} changed.`),U(null),K()}},`${r.n}-${H.mode}`)}),V===r.n&&f.length>0&&(0,M.jsx)(ce,{pictures:f,step:r.n,busy:O,onPick:e=>void Y(()=>oe({workflow:b.workflow.path,step:r.n,action:`insert`,kind:e.text?`check_text`:`check_present`,target:e.target,...e.text?{text:e.text}:{}}),e.text?`Added after step ${r.n}: a check that ${e.target.name||e.target.automation_id} shows "${e.text}".`:`Added after step ${r.n}: a check that ${e.target.name||e.target.automation_id} is there.`)})]},`${r.n}-${r.text}`)})})]}),N===`data`&&(b.values.length===0?(0,M.jsx)(te,{className:`py-4`,children:`Nothing is typed or chosen in this workflow, so it has no test data.`}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`p`,{className:`m-0 text-sm text-ink-2`,children:`Where each value typed or chosen comes from when it replays. Test data can come from a data file's rows on the Last run tab.`}),(0,M.jsx)(`ul`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-0`,children:b.values.map(e=>(0,M.jsx)(le,{v:e,secrets:b.secrets,busy:O,onSave:(t,n,r)=>void Y(()=>oe({workflow:b.workflow.path,step:e.n,action:`data`,as:t,...n===void 0?{}:{name:n},...r===void 0?{}:{value:r}}),t===`secret`?`Step ${e.n} types the secret ${n}; what was typed left the workflow.`:`Step ${e.n} saved.`)},e.n))})]})),N===`run`&&(0,M.jsx)(ue,{view:b,job:G,rows:me,heal:ge,busy:O||J,onRun:Ee})]})]})}export{P as n,N as r,de as t};
1
+ import{An as e,Ar as t,C as n,Dn as r,Ir as i,Nr as a,Tn as o,a as s,fn as c,it as l,j as u,kr as d,ln as f,pr as p,wr as m,wt as h}from"./line-icons-CQ-3V8ax.js";import{B as g,R as _,V as v,Zt as y,a as b,c as x,f as ee,ft as S,i as C,l as te,o as w,st as ne,t as T}from"./filters-CflRmNDz.js";import{xt as E}from"./frame-CYYiRu5P.js";import{n as D}from"./markdown-nTIj9lyp.js";import{O as re,r as O}from"./index-D4a0w3Vl.js";import{i as k,r as ie}from"./segmented-CAf_qz5Z.js";import{a as A}from"./dataParts-DI_OJhy5.js";var j=i(a(),1),M=y();function N(e){return(e.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||``).replace(/\.(exe|app)$/i,``).toLowerCase().replace(/[^a-z0-9_.-]+/g,`-`).replace(/^[^a-z]+/,``).replace(/-+$/,``).slice(0,40)||`app`}function P({value:e,onChange:t,onPicked:n,onError:r,className:i}){let[a,o]=(0,j.useState)(!1),s=async()=>{o(!0),r(``);try{let e=await S.browse();`path`in e?(t(e.path),n?.(e.path,e.name)):`unavailable`in e&&r(e.unavailable)}catch(e){r(e.message)}finally{o(!1)}};return(0,M.jsxs)(`div`,{className:g(`flex min-w-0 gap-2`,i),children:[(0,M.jsx)(b,{"aria-label":`App's path`,value:e,spellCheck:!1,placeholder:`C:\\Program Files\\Contoso\\Billing.exe`,onChange:e=>t(e.target.value),className:`min-w-0 flex-1 font-mono text-[13px]`}),(0,M.jsxs)(_,{type:`button`,disabled:a,onClick:()=>void s(),"data-tip":`Choose the app's .exe on this computer`,children:[(0,M.jsx)(h,{"aria-hidden":`true`}),a?`Choosing…`:`Browse…`]})]})}var F={click:[`target`,`timeout`,`note`],double_click:[`target`,`timeout`,`note`],type:[`target`,`text`,`timeout`,`note`],select:[`target`,`value`,`timeout`,`note`],keys:[`keys`,`note`],expect:[`target`,`text`,`timeout`,`note`],wait:[`seconds`,`note`],wait_for:[`target`,`text`,`timeout`,`note`],launch:[`timeout`,`note`],close:[`note`],expect_image:[`timeout`,`note`]};function I({p:e}){return(0,M.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,M.jsx)(`ul`,{className:`m-0 flex flex-col gap-0.5 pl-5 text-[13px] text-ink-2`,children:e.summary.map((e,t)=>(0,M.jsx)(`li`,{className:`[overflow-wrap:anywhere]`,children:e},t))}),(0,M.jsx)(`pre`,{className:`m-0 max-h-[200px] overflow-auto rounded-[10px] bg-surface-muted p-2.5 font-mono text-[12px] leading-relaxed whitespace-pre-wrap`,children:e.diff.map((e,t)=>(0,M.jsx)(`span`,{className:g(`block`,e.startsWith(`+`)?`text-pass`:e.startsWith(`-`)?`text-fail`:`text-muted`),children:e},t))})]})}function L({label:e,children:t}){return(0,M.jsxs)(`label`,{className:`flex min-w-0 flex-col gap-1 text-[13px] font-medium`,children:[e,t]})}function ae({workflow:e,step:r,mode:i,onDone:a,onCancel:s}){let c=F[r.op]??[`note`],l=r.fields??{},[u,d]=(0,j.useState)({automation_id:l.target?.automation_id??``,name:l.target?.name??``,control_type:l.target?.control_type??``}),[f,m]=(0,j.useState)(l.text??``),[h,g]=(0,j.useState)(l.value??``),[v,y]=(0,j.useState)(l.keys??``),[x,ee]=(0,j.useState)(l.seconds===void 0?``:String(l.seconds)),[C,te]=(0,j.useState)(l.timeout===void 0?``:String(l.timeout)),[w,ne]=(0,j.useState)(l.note??``),[T,E]=(0,j.useState)(null),[D,re]=(0,j.useState)(``),[O,k]=(0,j.useState)(!1),ie=()=>{let e={};return c.includes(`target`)&&(u.automation_id!==(l.target?.automation_id??``)||u.name!==(l.target?.name??``)||u.control_type!==(l.target?.control_type??``))&&(e.target=u),c.includes(`text`)&&f!==(l.text??``)&&(e.text=f),c.includes(`value`)&&h!==(l.value??``)&&(e.value=h),c.includes(`keys`)&&v!==(l.keys??``)&&(e.keys=v),c.includes(`seconds`)&&x!==(l.seconds===void 0?``:String(l.seconds))&&(e.seconds=Number(x)),c.includes(`timeout`)&&C!==(l.timeout===void 0?``:String(l.timeout))&&C.trim()&&(e.timeout=Number(C)),c.includes(`note`)&&w!==(l.note??``)&&(e.note=w),e},A=async t=>{k(!0),re(``);try{let n=await S.editStep({workflow:e,step:r.n,action:i,...i===`edit`?{fields:ie()}:{},...t?{version:t}:{}});n.written?a():E(n)}catch(e){re(e.message)}finally{k(!1)}};(0,j.useEffect)(()=>{i===`remove`&&A()},[]);let N=()=>E(null);return(0,M.jsxs)(`div`,{className:`mb-2 ml-9 flex flex-col gap-3 rounded-[12px] bg-surface-muted p-3`,children:[i===`edit`&&!T&&(0,M.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,180px),1fr))] gap-2.5`,children:[c.includes(`target`)&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(L,{label:`Control's name`,children:(0,M.jsx)(b,{size:`sm`,value:u.name,maxLength:300,onChange:e=>(d({...u,name:e.target.value}),N()),className:`bg-bg`})}),(0,M.jsx)(L,{label:`Automation id`,children:(0,M.jsx)(b,{size:`sm`,value:u.automation_id,maxLength:300,spellCheck:!1,onChange:e=>(d({...u,automation_id:e.target.value}),N()),className:`bg-bg font-mono text-[12.5px]`})}),(0,M.jsx)(L,{label:`Control type`,children:(0,M.jsx)(b,{size:`sm`,value:u.control_type,maxLength:60,spellCheck:!1,placeholder:`Button`,onChange:e=>(d({...u,control_type:e.target.value}),N()),className:`bg-bg`})})]}),c.includes(`text`)&&(0,M.jsx)(L,{label:r.op===`type`?`Text to type`:`Text it shows`,children:(0,M.jsx)(b,{size:`sm`,value:f,maxLength:500,onChange:e=>m(e.target.value),className:`bg-bg`})}),c.includes(`value`)&&(0,M.jsx)(L,{label:`Item to choose`,children:(0,M.jsx)(b,{size:`sm`,value:h,maxLength:500,onChange:e=>g(e.target.value),className:`bg-bg`})}),c.includes(`keys`)&&(0,M.jsx)(L,{label:`Keys`,children:(0,M.jsx)(b,{size:`sm`,value:v,maxLength:100,spellCheck:!1,placeholder:`ctrl+s`,onChange:e=>y(e.target.value),className:`bg-bg font-mono text-[12.5px]`})}),c.includes(`seconds`)&&(0,M.jsx)(L,{label:`Wait (seconds)`,children:(0,M.jsx)(b,{size:`sm`,type:`number`,min:0,max:600,value:x,onChange:e=>ee(e.target.value),className:`bg-bg`})}),c.includes(`timeout`)&&(0,M.jsx)(L,{label:`Timeout (seconds)`,children:(0,M.jsx)(b,{size:`sm`,type:`number`,min:0,max:600,value:C,placeholder:`default`,onChange:e=>te(e.target.value),className:`bg-bg`})}),c.includes(`note`)&&(0,M.jsx)(L,{label:`Note`,children:(0,M.jsx)(b,{size:`sm`,value:w,maxLength:200,onChange:e=>ne(e.target.value),className:`bg-bg`})})]}),i===`remove`&&!T&&!D&&(0,M.jsx)(`p`,{role:`status`,className:`m-0 text-[13px] text-muted`,children:`Working out the change…`}),T&&(0,M.jsx)(I,{p:T}),D&&(0,M.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[10px] bg-fail-soft px-3 py-2 text-[13px] text-fail [overflow-wrap:anywhere]`,children:D}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[T?(0,M.jsxs)(_,{size:`sm`,variant:i===`remove`?`destructive`:`primary`,disabled:O,onClick:()=>void A(T.version),children:[i===`remove`?(0,M.jsx)(p,{"aria-hidden":`true`}):(0,M.jsx)(n,{"aria-hidden":`true`}),O?`Saving…`:i===`remove`?`Delete step ${r.n}`:`Save the change`]}):i===`edit`&&(0,M.jsx)(_,{size:`sm`,variant:`primary`,disabled:O||!Object.keys(ie()).length,onClick:()=>void A(),children:O?`Checking…`:`Preview the change`}),T&&i===`edit`&&(0,M.jsxs)(_,{size:`sm`,onClick:()=>E(null),children:[(0,M.jsx)(o,{"aria-hidden":`true`}),`Change it more`]}),(0,M.jsxs)(_,{size:`sm`,variant:`ghost`,onClick:s,children:[(0,M.jsx)(t,{"aria-hidden":`true`}),`Cancel`]})]})]})}var R=[{id:`typed`,label:`As typed`,note:`The workflow types exactly this.`},{id:`data`,label:`Test data`,note:`A named value the replay fills in: its own value, a row of a data file, or one you give when it runs.`},{id:`secret`,label:`Secret`,note:`Read from an environment variable when it replays; what was typed leaves the workflow.`}],z={replay:[`Replaying the workflow`,`Replayed the workflow`,`working`],validate:[`Checking the workflow`,`Checked the workflow`,`searching`]};async function oe(e){let t=await S.editStep(e);await S.editStep({...e,version:t.version})}var B=[{id:`check_text`,label:`Check a control shows a text`,control:!0,text:`need`},{id:`check_present`,label:`Check a control is there`,control:!0},{id:`wait_for`,label:`Wait for a control`,control:!0,text:`may`},{id:`wait_gone`,label:`Wait until a control is gone`,control:!0},{id:`wait`,label:`Wait some seconds`,control:!1},{id:`keys`,label:`Press keys`,control:!1}];function se({step:t,onAdd:n}){let[r,i]=(0,j.useState)(`check_text`),a=t.fields?.target,[o,s]=(0,j.useState)({name:a?.name??``,automation_id:a?.automation_id??``,control_type:a?.control_type??``}),[c,l]=(0,j.useState)(``),[u,d]=(0,j.useState)(`2`),[f,p]=(0,j.useState)(``),m=B.find(e=>e.id===r),h=m.control?!!(o.name.trim()||o.automation_id.trim())&&(m.text!==`need`||!!c.trim()):r===`wait`?Number(u)>0:!!f.trim();return(0,M.jsxs)(`form`,{className:`flex flex-col gap-2.5 p-3`,onSubmit:e=>{e.preventDefault(),h&&n({kind:r,...m.control?{target:o}:{},...m.text&&c.trim()?{text:c}:{},...r===`wait`?{seconds:Number(u)}:{},...r===`keys`?{keys:f}:{}})},children:[(0,M.jsxs)(`p`,{className:`m-0 text-[13px] font-semibold`,children:[`After step `,t.n]}),(0,M.jsx)(w,{size:`sm`,"aria-label":`What to add`,value:r,onChange:e=>i(e.target.value),children:B.map(e=>(0,M.jsx)(`option`,{value:e.id,children:e.label},e.id))}),m.control&&(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[`Control's name`,(0,M.jsx)(b,{size:`sm`,value:o.name,maxLength:300,onChange:e=>s({...o,name:e.target.value})})]}),(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[`Automation id`,(0,M.jsx)(b,{size:`sm`,value:o.automation_id,maxLength:300,spellCheck:!1,onChange:e=>s({...o,automation_id:e.target.value}),className:`font-mono text-[12.5px]`})]})]}),m.text&&(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[m.text===`need`?`The text it shows`:`Showing the text (optional)`,(0,M.jsx)(b,{size:`sm`,value:c,maxLength:500,placeholder:`Invoice saved`,onChange:e=>l(e.target.value)})]}),r===`wait`&&(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[`Seconds`,(0,M.jsx)(b,{size:`sm`,type:`number`,min:1,max:600,value:u,onChange:e=>d(e.target.value)})]}),r===`keys`&&(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[12.5px] font-medium`,children:[`Keys`,(0,M.jsx)(b,{size:`sm`,value:f,maxLength:100,spellCheck:!1,placeholder:`ctrl+s`,onChange:e=>p(e.target.value),className:`font-mono text-[12.5px]`})]}),(0,M.jsx)(`p`,{className:`m-0 text-[12px] text-muted`,children:`The control is filled from this step's; change it for another. A wait for a control is better than a fixed wait.`}),(0,M.jsxs)(_,{type:`submit`,size:`sm`,variant:`primary`,disabled:!h,className:`self-start`,children:[(0,M.jsx)(e,{"aria-hidden":`true`}),`Add`]})]})}var V=e=>e.name||e.automation_id||`the control`;function ce({pictures:e,step:t,busy:n,onPick:r}){let[i,a]=(0,j.useState)(0),o=e[Math.min(i,e.length-1)],[s,c]=(0,j.useState)(``),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(null);(0,j.useEffect)(()=>{let e=!1;return c(``),u(``),f(null),S.shot(o.run,o.n).then(t=>!e&&c(t),t=>!e&&u(t.message)),S.controls(o.run,o.n).then(t=>!e&&f(t),()=>{}),()=>{e=!0}},[o.run,o.n]);let p=(e,t)=>`${Math.max(0,Math.min(100,e/t*100))}%`,m=d&&d.w>0?[...d.controls].sort((e,t)=>t.w*t.h-e.w*e.h):[];return(0,M.jsxs)(`div`,{className:`flex flex-col gap-2 pr-3 pb-3 pl-3 sm:pl-[76px]`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.length>1&&(0,M.jsx)(`div`,{role:`radiogroup`,"aria-label":`Pictures of step ${t}`,className:`flex w-fit max-w-full flex-wrap gap-1 rounded-[10px] bg-surface-strong p-1`,children:e.map((e,t)=>(0,M.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===i,onClick:()=>a(t),className:k(t===i),children:e.label},e.label))}),(0,M.jsxs)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:[o.note,m.length>0?` Click a control to check that it shows its text, or that it is there.`:``]})]}),l&&(0,M.jsx)(`p`,{className:`m-0 text-sm text-fail`,children:l}),!s&&!l&&(0,M.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`Loading the picture…`}),s&&(0,M.jsxs)(`div`,{className:`relative w-full max-w-[720px] overflow-hidden rounded-[10px] border border-line-soft`,style:m.length?{aspectRatio:`${d.w} / ${d.h}`}:void 0,children:[(0,M.jsx)(`img`,{src:s,alt:`The app after step ${t}, ${o.label.toLowerCase()}`,className:m.length?`absolute inset-0 size-full object-fill`:`block w-full`}),m.map((e,t)=>{let i=e.text?`Check ${V(e)} shows "${e.text}"`:`Check ${V(e)} is there`;return(0,M.jsx)(`button`,{type:`button`,disabled:n,"aria-label":i,"data-tip":i,onClick:()=>r({target:{...e.automation_id?{automation_id:e.automation_id}:{},...e.name?{name:e.name}:{},...e.control_type?{control_type:e.control_type}:{}},...e.text?{text:e.text}:{}}),className:`absolute cursor-pointer rounded-[3px] border-0 bg-transparent p-0 outline-none hover:bg-accent/15 hover:ring-2 hover:ring-accent focus-visible:bg-accent/15 focus-visible:ring-2 focus-visible:ring-accent`,style:{left:p(e.x,d.w),top:p(e.y,d.h),width:p(e.w,d.w),height:p(e.h,d.h)}},`${t}-${e.automation_id||e.name}`)})]})]})}function le({v:e,secrets:t,onSave:r,busy:i}){let[a,o]=(0,j.useState)(e.as),[s,c]=(0,j.useState)(e.name??``),[l,u]=(0,j.useState)(e.value??``);(0,j.useEffect)(()=>{o(e.as),c(e.name??``),u(e.value??``)},[e]);let d=R.filter(t=>e.op===`type`||t.id!==`secret`),f=a!==e.as||s!==(e.name??``)||l!==(e.value??``),p=a===`typed`?!0:a===`data`?/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(s):/^[A-Z_][A-Z0-9_]{0,63}$/.test(s);return(0,M.jsxs)(`li`,{className:`flex flex-wrap items-start gap-x-4 gap-y-2 border-t border-line-soft px-3 py-2.5 first:border-t-0`,children:[(0,M.jsx)(`span`,{className:`w-6 flex-none pt-2 text-right font-mono text-[12px] text-muted tabular-nums`,children:e.n}),(0,M.jsxs)(`span`,{className:`flex min-w-0 flex-[1_1_220px] flex-col pt-1.5`,children:[(0,M.jsx)(`span`,{className:`text-[14px] text-ink [overflow-wrap:anywhere]`,children:e.line}),(0,M.jsx)(`span`,{className:`text-[12.5px] text-ink-2`,children:R.find(e=>e.id===a)?.note})]}),(0,M.jsxs)(`span`,{className:`flex flex-[1_1_360px] flex-wrap items-center gap-2`,children:[(0,M.jsx)(w,{"aria-label":`Where the value of step ${e.n} comes from`,value:a,disabled:i,onChange:e=>o(e.target.value),className:`w-[150px] flex-none`,children:d.map(e=>(0,M.jsx)(`option`,{value:e.id,children:e.label},e.id))}),a!==`typed`&&(0,M.jsx)(b,{"aria-label":a===`secret`?`The secret's environment variable`:`The test data's name`,value:s,maxLength:64,spellCheck:!1,list:a===`secret`?`desktop-secrets`:void 0,placeholder:a===`secret`?`BILLING_PASSWORD`:`customer`,onChange:e=>c(a===`secret`?e.target.value.toUpperCase():e.target.value),className:`w-[170px] flex-none font-mono text-[13px]`}),a!==`secret`&&(0,M.jsx)(b,{"aria-label":a===`data`?`Its value`:`The value`,value:l,maxLength:500,onChange:e=>u(e.target.value),className:`min-w-[140px] flex-1`}),a===`secret`&&!t.includes(s)&&s&&(0,M.jsx)(`span`,{className:`text-[12px] text-warn`,children:`Not in desktop.secrets yet`}),(0,M.jsxs)(_,{size:`sm`,variant:`primary`,disabled:i||!f||!p,onClick:()=>r(a,a===`typed`?void 0:s,a===`secret`?void 0:l),children:[(0,M.jsx)(n,{"aria-hidden":`true`}),`Save`]})]}),(0,M.jsx)(`datalist`,{id:`desktop-secrets`,children:t.map(e=>(0,M.jsx)(`option`,{value:e},e))})]})}function ue({view:e,job:t,rows:n,onRun:i,busy:a,heal:o}){let[s,c]=(0,j.useState)(()=>Object.fromEntries(e.variables.map(e=>[e.name,e.value]))),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(o),[p,m]=(0,j.useState)(!1),h=e.lastRun,g=l.startsWith(`file:`)?{file:l.slice(5)}:l.startsWith(`request:`)?{request:l.slice(8)}:void 0,y=t&&t.kind===`replay`&&t.target===e.workflow.path;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`p`,{className:`m-0 text-sm text-ink-2`,children:`Replay plays the steps in the app with no model, as a scheduled run or CI will, and takes over the mouse and keyboard while it runs: use a test machine and a test account.`}),(0,M.jsxs)(`form`,{className:`flex flex-col gap-3 rounded-[12px] card border p-3`,onSubmit:e=>{e.preventDefault(),i({variables:s,...g?{rows:g}:{},heal:d,updateBaselines:p})},children:[e.variables.length>0&&(0,M.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,180px),1fr))] gap-3`,children:e.variables.map(e=>(0,M.jsxs)(`label`,{className:`flex flex-col gap-1 text-[13px] font-medium text-ink-2`,children:[e.name,(0,M.jsx)(b,{value:s[e.name]??``,onChange:t=>c({...s,[e.name]:t.target.value})})]},e.name))}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,M.jsxs)(`label`,{className:`flex min-w-[220px] flex-col gap-1 text-[13px] font-medium text-ink-2`,children:[`Test data`,(0,M.jsxs)(w,{value:l,onChange:e=>u(e.target.value),children:[(0,M.jsx)(`option`,{value:``,children:`Once, with the values above`}),n.files.map(e=>(0,M.jsxs)(`option`,{value:`file:${e}`,children:[`Each row of `,e]},e)),n.requests.map(e=>(0,M.jsxs)(`option`,{value:`request:${e}`,children:[`Each row of request `,e]},e))]})]}),(0,M.jsxs)(`label`,{className:`flex min-h-10 items-center gap-2.5 text-sm text-ink-2`,children:[(0,M.jsx)(E,{checked:d,onChange:f,label:`Heal a step whose control moved`}),`Heal a moved control`]}),(0,M.jsxs)(`label`,{className:`flex min-h-10 items-center gap-2.5 text-sm text-ink-2`,children:[(0,M.jsx)(E,{checked:p,onChange:m,label:`Take new image baselines`}),`New image baselines`]}),(0,M.jsx)(`span`,{className:`flex-1`}),(0,M.jsxs)(_,{type:`submit`,variant:`primary`,disabled:a,children:[(0,M.jsx)(r,{"aria-hidden":`true`}),`Replay`]})]})]}),y&&(0,M.jsx)(A,{job:t,onStop:()=>void S.stop(),words:z}),h?(0,M.jsxs)(`section`,{"aria-labelledby":`desktop-last-run`,className:`flex flex-col gap-2`,children:[(0,M.jsx)(`h3`,{id:`desktop-last-run`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Last replay`}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-[12px] card border px-3 py-2.5 text-sm`,children:[(0,M.jsx)(x,{tone:h.ok?`pass`:`fail`,children:h.many?`${h.many.passed} of ${h.many.total} passed`:h.ok?`Passed`:`Failed`}),(0,M.jsxs)(`span`,{className:`text-muted`,children:[O(h.at),` · `,v(e.replays,`replay`),` in all`]}),h.failed&&(0,M.jsxs)(`span`,{className:`min-w-0 flex-[1_1_240px] text-[13px] text-fail [overflow-wrap:anywhere]`,children:[`Step `,h.failed.index,`: `,h.failed.error]}),(0,M.jsx)(`span`,{className:`flex-1`}),h.report&&(0,M.jsx)(D,{path:h.report,children:`Report`})]})]}):(0,M.jsx)(te,{className:`py-3`,children:`Not replayed yet.`})]})}function de({workflow:i,onClose:a,backLabel:h=`Back`,notices:y}){let[b,w]=(0,j.useState)(null),[E,D]=(0,j.useState)(``),[O,A]=(0,j.useState)(!1),[N,P]=(0,j.useState)(`steps`),[F,I]=(0,j.useState)(``),[L,R]=(0,j.useState)(`all`),[z,B]=(0,j.useState)(null),[V,de]=(0,j.useState)(null),[H,U]=(0,j.useState)(null),[fe,W]=(0,j.useState)(``),[G,pe]=(0,j.useState)(null),[me,he]=(0,j.useState)({files:[],requests:[]}),[ge,_e]=(0,j.useState)(!0),K=(0,j.useCallback)(()=>{S.review(i).then(e=>{w(e),D(``)},e=>D(e.message))},[i]);(0,j.useEffect)(K,[K]);let q=(0,j.useCallback)(()=>{S.view().then(e=>{pe(e.job),he(e.rows),_e(e.heal)},()=>{})},[]);(0,j.useEffect)(q,[q]);let J=!!G?.running;(0,j.useEffect)(()=>{if(!J)return;let e=setInterval(q,1e3);return()=>clearInterval(e)},[J,q]);let ve=G&&!G.running?G.endedAt:``;(0,j.useEffect)(()=>{ve&&K()},[ve,K]);let Y=async(e,t)=>{A(!0),D(``),W(``);try{await e(),K(),t&&W(t)}catch(e){D(e.message)}finally{A(!1)}},ye=e=>void ne.start(e,{}).then(({id:e})=>location.hash=ee(`chats`,e),e=>D(e.message));if(!b)return E?(0,M.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:E}):(0,M.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Opening the workflow…`});let X=b.lastRun,be=new Map((X?.results??[]).map(e=>[e.n,e])),xe=!!X&&Date.parse(b.workflow.modified)>Date.parse(X.at),Z=b.steps.filter(e=>e.op.startsWith(`expect`)).length,Q=X&&!X.ok?X.failed?.index??0:0,$=Q?b.steps[Q-1]:void 0,Se=(X?.results??[]).filter(e=>!e.ok).length,Ce=F.toLowerCase().split(/\s+/).filter(Boolean),we=b.steps.filter(e=>Ce.every(t=>`${e.n} ${e.text} ${e.fields?.note||``}`.toLowerCase().includes(t))&&(L===`all`||(L===`checks`?e.op.startsWith(`expect`):be.get(e.n)?.ok===!1))),Te=e=>{P(`steps`),R(`all`),I(``),requestAnimationFrame(()=>document.getElementById(`dstep-${e}`)?.scrollIntoView({block:`center`,behavior:`smooth`}))},Ee=e=>void Y(async()=>{await S.replay({workflow:b.workflow.path,...e}),q()},`Replaying: the app opens on this computer.`),De=[{id:`steps`,label:`Steps`,n:b.steps.length},{id:`data`,label:`Test data`,n:b.values.length},{id:`run`,label:`Last run`}];return(0,M.jsxs)(`section`,{"aria-labelledby":`dreview-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,M.jsxs)(`div`,{className:`sticky top-0 z-20 -mx-1 flex flex-col gap-3 border-b border-line bg-bg px-1 py-3`,children:[a&&(0,M.jsx)(`div`,{children:(0,M.jsxs)(_,{size:`sm`,variant:`ghost`,onClick:a,className:`-ml-2 text-ink-2`,children:[(0,M.jsx)(s,{"aria-hidden":`true`}),h]})}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-[1_1_320px] flex-col gap-1`,children:[(0,M.jsx)(`h2`,{id:`dreview-title`,className:`m-0 min-w-0 truncate text-lg font-semibold`,"data-tip":b.workflow.name,children:b.workflow.name}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[13px] text-muted`,children:[(0,M.jsxs)(`span`,{children:[b.workflow.app||`no app`,` · `,v(b.steps.length,`step`),` · `,v(Z,`check`)]}),J&&G?.target===b.workflow.path?(0,M.jsx)(x,{tone:`running`,children:`Replaying…`}):X?(0,M.jsx)(x,{tone:X.ok?`pass`:`fail`,children:X.ok?`Last replay passed`:Q?`Last replay failed at step ${Q}`:`Last replay did not get through`}):(0,M.jsx)(x,{tone:`neutral`,icon:!1,children:`Not replayed yet`}),xe&&(0,M.jsx)(`span`,{children:`· you changed it since`})]})]}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsxs)(_,{onClick:()=>ye(`Desktop agent: look at the desktop workflow ${b.workflow.path} and tell me what to fix or add (a wait, a timeout, a dialog to dismiss, checks of the outcome); change it with desktop_edit_workflow only after showing me the change.`),"data-tip":`Ask the Desktop agent to improve it`,children:[(0,M.jsx)(m,{"aria-hidden":`true`}),`Improve`]}),(0,M.jsxs)(_,{variant:`primary`,disabled:J,onClick:()=>P(`run`),"data-tip":J?`A replay is going`:`Replay it with no model`,children:[(0,M.jsx)(r,{"aria-hidden":`true`}),`Replay`]})]})]})]}),y,E&&(0,M.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:E}),fe&&(0,M.jsx)(`p`,{role:`status`,className:`m-0 rounded-[10px] bg-pass-soft px-3 py-1.5 text-[13px] text-pass`,children:fe}),X&&!X.ok&&(0,M.jsxs)(`div`,{role:`alert`,className:`flex flex-col gap-2 rounded-[12px] border border-fail/30 bg-fail-soft px-4 py-3 text-sm`,children:[(0,M.jsxs)(`p`,{className:`m-0 font-semibold text-fail`,children:[Q?`Step ${Q} failed`:`The replay did not get through`,xe&&(0,M.jsx)(`span`,{className:`font-normal text-ink-2`,children:` · before your last change`})]}),$&&(0,M.jsx)(`p`,{className:`m-0 font-medium text-ink [overflow-wrap:anywhere]`,children:$.text}),(0,M.jsx)(`p`,{className:`m-0 line-clamp-3 text-[13px] text-ink-2 [overflow-wrap:anywhere]`,children:X.failed?.error||X.error||`It failed.`}),(0,M.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[$&&(0,M.jsxs)(_,{size:`sm`,onClick:()=>Te(Q),children:[(0,M.jsx)(l,{"aria-hidden":`true`}),`Show`]}),$&&Q>1&&(0,M.jsxs)(_,{size:`sm`,onClick:()=>(Te(Q),U({n:Q,mode:`edit`})),"data-tip":`Change the failed step: its control, text or timeout`,children:[(0,M.jsx)(o,{"aria-hidden":`true`}),`Change`]}),(0,M.jsxs)(_,{size:`sm`,variant:`ghost`,onClick:()=>ye(`Desktop agent: the last replay of ${b.workflow.path} failed${Q?` at step ${Q}`:``}. Read its report (${X.dir}), tell me why, and offer a fix.`),children:[(0,M.jsx)(f,{"aria-hidden":`true`}),`Ask why`]})]})]}),X&&X.ok&&X.heals>0&&!X.healsAccepted&&(0,M.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-3 rounded-[12px] bg-accent-soft px-3 py-2.5 text-sm`,children:[(0,M.jsxs)(`span`,{className:`min-w-0 flex-[1_1_240px]`,children:[`The last replay found `,v(X.heals,`moved control`),` and healed `,X.heals===1?`it`:`them`,`: write the new locators into the workflow?`]}),(0,M.jsxs)(_,{size:`sm`,disabled:O,onClick:()=>void Y(()=>S.acceptHeals(X.dir),`The healed locators are in the workflow.`),children:[(0,M.jsx)(d,{"aria-hidden":`true`}),`Accept`]})]}),(0,M.jsx)(`div`,{role:`tablist`,"aria-label":`This workflow`,className:ie,children:De.map(e=>(0,M.jsxs)(`button`,{type:`button`,role:`tab`,id:`dreview-tab-${e.id}`,"aria-selected":N===e.id,"aria-controls":`dreview-panel-${e.id}`,onClick:()=>P(e.id),className:k(N===e.id),children:[e.label,e.n!==void 0&&(0,M.jsx)(`span`,{className:`text-[12px] text-muted tabular-nums`,children:e.n}),e.id===`run`&&X&&(0,M.jsx)(`span`,{"aria-label":X.ok?`passed`:`failed`,className:g(`size-2 rounded-full`,X.ok?`bg-pass`:`bg-fail`)})]},e.id))}),(0,M.jsxs)(`div`,{role:`tabpanel`,id:`dreview-panel-${N}`,"aria-labelledby":`dreview-tab-${N}`,className:`flex min-w-0 flex-col gap-4`,children:[N===`steps`&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(C,{id:`dreview-step-search`,label:`Find a step`,value:F,onChange:I}),(0,M.jsx)(T,{items:[{id:`all`,label:`All`,n:b.steps.length},{id:`checks`,label:`Checks`,n:Z},...Se?[{id:`failed`,label:`Failed`,n:Se,alert:!0}]:[]],value:L,onChange:R})]}),Z===0&&(0,M.jsx)(`p`,{className:`m-0 rounded-[10px] bg-warn-soft px-3 py-2 text-[13px] text-warn`,children:`No checks of the outcome: a replay passes when its steps run. Add one with + after the step whose result matters.`}),we.length===0?(0,M.jsx)(`p`,{className:`m-0 rounded-[12px] card border px-4 py-4 text-sm text-muted`,children:`No step matches.`}):(0,M.jsx)(`ol`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-0 [&>li:first-child]:rounded-t-[12px] [&>li:last-child]:rounded-b-[12px]`,children:we.map((r,i)=>{let a=be.get(r.n),s=r.op.startsWith(`expect`),d=b.recorded?.shots[r.n],f=[...d&&b.recorded?[{label:`When recorded`,run:b.recorded.run,n:d,note:`The app after step ${r.n} as you recorded it.`}]:[],...a?.shot&&X?[{label:`Last replay`,run:X.dir,n:r.n,note:`The app after step ${r.n} on the last replay${xe?`, before your last change`:``}.`}]:[]];return(0,M.jsxs)(`li`,{id:`dstep-${r.n}`,className:g(`flex scroll-mt-48 flex-col`,i>0&&`border-t border-line-soft`,a&&!a.ok&&`bg-fail-soft`),children:[(0,M.jsxs)(`div`,{className:`group flex min-h-11 items-start gap-3 px-3 py-2`,children:[(0,M.jsx)(`span`,{className:`w-6 flex-none pt-0.5 text-right font-mono text-[12px] text-muted tabular-nums`,children:r.n}),(0,M.jsx)(`span`,{className:`flex w-4 flex-none justify-center pt-1`,children:a?a.ok?(0,M.jsx)(n,{size:14,strokeWidth:2.5,"aria-label":`Passed on the last replay`,className:`text-pass`}):(0,M.jsx)(t,{size:14,strokeWidth:2.5,"aria-label":`Failed on the last replay`,className:`text-fail`}):X?(0,M.jsx)(c,{size:14,"aria-label":`Not replayed`,className:`text-muted`}):s?(0,M.jsx)(u,{size:14,"aria-hidden":`true`,className:`text-pass`}):(0,M.jsx)(`span`,{"aria-hidden":`true`,className:`mt-1 size-1.5 rounded-full bg-line-strong`})}),(0,M.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,M.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[s&&(0,M.jsx)(x,{tone:`pass`,icon:!1,className:`min-h-5 px-2 text-[11px]`,children:`Check`}),r.op.startsWith(`wait`)&&(0,M.jsx)(x,{tone:`neutral`,icon:!1,className:`min-h-5 px-2 text-[11px]`,children:`Wait`}),(0,M.jsx)(`span`,{className:`min-w-0 text-[14px] text-ink [overflow-wrap:anywhere]`,children:r.text}),a?.healed&&(0,M.jsx)(x,{tone:`warn`,icon:!1,className:`min-h-5 px-2 text-[11px]`,children:`Healed`})]}),r.fields?.note&&(0,M.jsxs)(`span`,{className:`text-[12.5px] text-ink-2`,children:[`Note: `,r.fields.note]}),a&&!a.ok&&a.error&&(0,M.jsx)(`span`,{className:`line-clamp-2 text-[12.5px] text-fail [overflow-wrap:anywhere]`,"data-tip":a.error,children:a.error})]}),(0,M.jsxs)(`span`,{className:`relative flex flex-none items-center gap-0.5`,children:[(0,M.jsx)(_,{size:`icon`,variant:`icon`,disabled:O,"aria-haspopup":`dialog`,"aria-expanded":z===r.n,"aria-label":`Add a check or wait after step ${r.n}`,"data-tip":`Add a check or wait after step ${r.n}`,onClick:()=>B(z===r.n?null:r.n),className:`size-8`,children:(0,M.jsx)(e,{"aria-hidden":`true`})}),(0,M.jsx)(re,{open:z===r.n,onClose:()=>B(null),label:`Add after step ${r.n}`,role:`dialog`,side:`auto`,className:`right-0 w-[min(360px,calc(100vw-48px))]`,children:(0,M.jsx)(se,{step:r,onAdd:e=>{B(null),Y(()=>oe({workflow:b.workflow.path,step:r.n,action:`insert`,...e}),`Added after step ${r.n}.`)}})}),f.length>0&&(0,M.jsx)(_,{size:`icon`,variant:`icon`,"aria-label":`See the app after step ${r.n}`,"aria-expanded":V===r.n,"data-tip":`See the app after step ${r.n}`,onClick:()=>de(V===r.n?null:r.n),className:`size-8`,children:(0,M.jsx)(l,{"aria-hidden":`true`})}),(0,M.jsx)(_,{size:`icon`,variant:`icon`,"aria-label":`Change step ${r.n}`,"data-tip":`Change step ${r.n}`,onClick:()=>U({n:r.n,mode:`edit`}),className:`size-8`,children:(0,M.jsx)(o,{"aria-hidden":`true`})}),r.n>1&&(0,M.jsx)(_,{size:`icon`,variant:`icon`,"aria-label":`Drop step ${r.n}`,"data-tip":`Drop step ${r.n}`,onClick:()=>U({n:r.n,mode:`remove`}),className:`size-8 hover:text-fail`,children:(0,M.jsx)(p,{"aria-hidden":`true`})})]})]}),H&&H.n===r.n&&(0,M.jsx)(`div`,{className:`pr-3`,children:(0,M.jsx)(ae,{workflow:b.workflow.path,step:r,mode:H.mode,onCancel:()=>U(null),onDone:()=>{W(H.mode===`remove`?`Step ${r.n} dropped.`:`Step ${r.n} changed.`),U(null),K()}},`${r.n}-${H.mode}`)}),V===r.n&&f.length>0&&(0,M.jsx)(ce,{pictures:f,step:r.n,busy:O,onPick:e=>void Y(()=>oe({workflow:b.workflow.path,step:r.n,action:`insert`,kind:e.text?`check_text`:`check_present`,target:e.target,...e.text?{text:e.text}:{}}),e.text?`Added after step ${r.n}: a check that ${e.target.name||e.target.automation_id} shows "${e.text}".`:`Added after step ${r.n}: a check that ${e.target.name||e.target.automation_id} is there.`)})]},`${r.n}-${r.text}`)})})]}),N===`data`&&(b.values.length===0?(0,M.jsx)(te,{className:`py-4`,children:`Nothing is typed or chosen in this workflow, so it has no test data.`}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`p`,{className:`m-0 text-sm text-ink-2`,children:`Where each value typed or chosen comes from when it replays. Test data can come from a data file's rows on the Last run tab.`}),(0,M.jsx)(`ul`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-0`,children:b.values.map(e=>(0,M.jsx)(le,{v:e,secrets:b.secrets,busy:O,onSave:(t,n,r)=>void Y(()=>oe({workflow:b.workflow.path,step:e.n,action:`data`,as:t,...n===void 0?{}:{name:n},...r===void 0?{}:{value:r}}),t===`secret`?`Step ${e.n} types the secret ${n}; what was typed left the workflow.`:`Step ${e.n} saved.`)},e.n))})]})),N===`run`&&(0,M.jsx)(ue,{view:b,job:G,rows:me,heal:ge,busy:O||J,onRun:Ee})]})]})}export{P as n,N as r,de as t};