@playword/core
Version:
Supercharge your web test automation experience with AI
385 lines (345 loc) • 59.1 kB
JavaScript
"use strict";var we=Object.create;var V=Object.defineProperty,ye=Object.defineProperties,Rt=Object.getOwnPropertyDescriptor,be=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertyNames,Ft=Object.getOwnPropertySymbols,ve=Object.getPrototypeOf,Ot=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable;var nt=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))Ot.call(t,n)&&nt(e,n,t[n]);if(Ft)for(var n of Ft(t))Ae.call(t,n)&&nt(e,n,t[n]);return e},S=(e,t)=>ye(e,be(t));var Dt=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},Mt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xe(t))!Ot.call(e,o)&&o!==n&&V(e,o,{get:()=>t[o],enumerable:!(r=Rt(t,o))||r.enumerable});return e};var Ce=(e,t,n)=>(n=e!=null?we(ve(e)):{},Mt(t||!e||!e.__esModule?V(n,"default",{value:e,enumerable:!0}):n,e)),Ee=e=>Mt(V({},"__esModule",{value:!0}),e),_t=(e,t,n,r)=>{for(var o=r>1?void 0:r?Rt(t,n):t,a=e.length-1,c;a>=0;a--)(c=e[a])&&(o=(r?c(t,n,o):c(o))||o);return r&&o&&V(t,n,o),o};var g=(e,t,n)=>nt(e,typeof t!="symbol"?t+"":t,n);var s=(e,t,n)=>new Promise((r,o)=>{var a=l=>{try{i(n.next(l))}catch(d){o(d)}},c=l=>{try{i(n.throw(l))}catch(d){o(d)}},i=l=>l.done?r(l.value):Promise.resolve(l.value).then(a,c);i((n=n.apply(e,t)).next())});var _e={};Dt(_e,{Observer:()=>It,PlayWord:()=>kt});module.exports=Ee(_e);var ne=require("@langchain/core/messages"),U=require("timers/promises");var W={};Dt(W,{assertElementContains:()=>it,assertElementContentEquals:()=>rt,assertElementContentNotEqual:()=>ct,assertElementNotContain:()=>st,assertElementNotVisible:()=>dt,assertElementVisible:()=>lt,assertPageContains:()=>pt,assertPageNotContain:()=>mt,assertPageTitleEquals:()=>ut,assertPageUrlMatches:()=>ht,click:()=>ft,goto:()=>gt,hover:()=>wt,input:()=>yt,pressKeys:()=>bt,scroll:()=>xt,select:()=>vt,sleep:()=>At,switchFrame:()=>J,switchPage:()=>Ct,waitForText:()=>Et});var Qt=require("timers/promises");var H=(e,t)=>{e.classList.add(t)},jt=()=>s(void 0,null,function*(){let e=yield caches.keys();yield Promise.all(e.map(t=>caches.delete(t)))}),Wt=()=>s(void 0,null,function*(){(yield indexedDB.databases()).filter(t=>t.name).map(t=>indexedDB.deleteDatabase(t.name))}),qt=()=>{localStorage.clear(),sessionStorage.clear()},Vt=()=>s(void 0,null,function*(){let e=yield navigator.serviceWorker.getRegistrations();yield Promise.all(e.map(t=>t.unregister()))}),L=e=>{let t=document.querySelectorAll("*:not(head):not(script):not(style)"),n=[],r=a=>{let c=[];for(;a&&a.nodeType==1;a=a.parentNode){let i=1;for(let l=a.previousSibling;l;l=l.previousSibling)l.nodeType===1&&l.nodeName===a.nodeName&&i++;c.unshift(`${a.nodeName.toLowerCase()}[${i}]`)}return"//"+c.join("/")},o=a=>{var c,i;return e.includes(a.nodeName.toLowerCase())?(i=(c=a==null?void 0:a.checkVisibility)==null?void 0:c.call(a,{checkOpacity:!0,checkVisibilityCSS:!0,contentVisibilityAuto:!0}))!=null?i:!0:!1};for(let a of t){if(!o(a))continue;let c=a.cloneNode(!0);c.innerHTML=[...c.childNodes].filter(i=>i.nodeType===3).map(i=>i.nodeValue).join("").trim(),!(c.outerHTML.length>1e3)&&n.push({html:c.outerHTML,xpath:r(a)})}return n},zt=(e,t)=>e.classList.contains(t),G=(e,t)=>{e.classList.remove(t)},at=(e,{name:t,value:n})=>{t==="value"&&e instanceof HTMLInputElement?e.value=n.toString():n?e.setAttribute(t,n.toString()):e.removeAttribute(t)},Bt=()=>{window.__name=i=>i;let e,t=i=>{i.preventDefault(),i.stopImmediatePropagation()},n=i=>{let l=i.cloneNode(!0),d=[...l.childNodes].filter(u=>u.nodeType===3).map(u=>u.nodeValue),f=[...l.attributes].map(u=>`${u.name}="${u.value}"`),m=i.nodeName.toLowerCase();return{frameSrc:o(),html:`<${m} ${f.join(" ")}>${d.join(" ").trim()}</${m}>`,xpath:r(i)}},r=i=>{let l=[];for(;i&&i.nodeType==1;i=i.parentNode){let d=1;for(let f=i.previousSibling;f;f=f.previousSibling)f.nodeType===1&&f.nodeName===i.nodeName&&d++;l.unshift(`${i.nodeName.toLowerCase()}[${d}]`)}return"//"+l.join("/")},o=()=>{if(window.self===window.top)return;let{origin:i,pathname:l,search:d,hash:f}=new URL(document.location.href);return i+decodeURIComponent(l)+d+f},a=i=>s(void 0,null,function*(){return window.emit({name:"click",params:C({},n(i))})}),c=i=>s(void 0,null,function*(){let l=["color","date","datetime-local","email","text","month","number","password","range","search","tel","time","url","week"];if(i.value)return l.includes(i.type)||i.nodeName==="TEXTAREA"?window.emit({name:"input",params:S(C({},n(i)),{text:i.value})}):window.emit({name:"click",params:C({},n(i))})});document.addEventListener("change",i=>{clearTimeout(e);let l=i.target;if(l.nodeName==="SELECT")return window.emit({name:"select",params:S(C({},n(l)),{option:l.value})});if(l.className==="plwd-input")return window.updateInput(l.value)},!0),document.addEventListener("click",i=>{let l=document.elementFromPoint(i.clientX,i.clientY);clearTimeout(e),l.className.startsWith("plwd")&&l.className!=="plwd-input"&&t(i)},!0),document.addEventListener("keydown",i=>{let l=document.querySelector(".plwd-panel:not(.open)"),{activeElement:d}=document;if(clearTimeout(e),i.key==="Escape")return window.stopDryRun();if(!((d==null?void 0:d.className)==="plwd-input"||l)){if(t(i),["A","a"].includes(i.key))return window.accept();if(["C","c"].includes(i.key))return window.cancel()}},!0),document.addEventListener("mousedown",i=>{let l=document.elementFromPoint(i.clientX,i.clientY);l.className.startsWith("plwd")&&l.className!=="plwd-input"&&t(i)}),document.addEventListener("mouseleave",i=>{clearTimeout(e),document.querySelector(".plwd-panel.open")&&t(i)},!0),document.addEventListener("mouseout",i=>{clearTimeout(e),document.querySelector(".plwd-panel.open")&&t(i)},!0),document.addEventListener("mouseover",i=>{clearTimeout(e),document.elementFromPoint(i.clientX,i.clientY).nodeName!=="IFRAME"&&(document.querySelector(".plwd-panel.open")&&t(i),e=setTimeout(()=>s(void 0,null,function*(){let d=document.elementFromPoint(i.clientX,i.clientY);if(!d.className.startsWith("plwd"))return window.emit({name:"hover",params:S(C({},n(d)),{duration:1e3})})}),3e3))}),document.addEventListener("mouseup",i=>{let l=document.activeElement,d=document.elementFromPoint(i.clientX,i.clientY);if(clearTimeout(e),d.className.startsWith("plwd")&&d.className!=="plwd-input"&&t(i),!(["SELECT","OPTION"].includes(d.nodeName)||!l))return["INPUT","TEXTAREA"].includes(l.nodeName)&&!["INPUT","TEXTAREA"].includes(d.nodeName)&&l.blur(),d.classList.contains("plwd-accept-btn")?window.accept():d.classList.contains("plwd-cancel-btn")?window.cancel():d.classList.contains("plwd-clear-btn")?window.clearAll():d.classList.contains("plwd-delete-btn")?window.deleteStep(parseInt(d.getAttribute("data-index"))):d.classList.contains("plwd-dry-run-btn")?window.dryRun():["INPUT","TEXTAREA"].includes(d.nodeName)?c(d):a(d)})},Ht=e=>{window.addEventListener("load",()=>{let t=document.createElement("style");t.textContent=e,document.body.appendChild(t);let n=document.createElement("div");n.classList.add("plwd-banner"),n.innerText="PlayWord";let r=document.createElement("div");r.classList.add("plwd-loader-box");let o=document.createElement("input");o.classList.add("plwd-input"),o.placeholder="Step Description";let a=document.createElement("button");a.classList.add("plwd-accept-btn"),a.innerText="\u2713 Accept (a)",a.setAttribute("title","Add the step to the test case");let c=document.createElement("button");c.classList.add("plwd-cancel-btn"),c.innerText="\u2715 Cancel (c)",c.setAttribute("title","Undo the step");let i=document.createElement("div");i.classList.add("plwd-input-box"),i.appendChild(o),i.appendChild(r),i.appendChild(c),i.appendChild(a);let l=document.createElement("ul");l.classList.add("plwd-timeline");let d=document.createElement("button");d.classList.add("plwd-dry-run-btn"),d.innerText="Dry Run";let f=document.createElement("button");f.classList.add("plwd-clear-btn"),f.innerText="Clear All";let m=document.createElement("p");m.classList.add("plwd-preview-title"),m.innerText="Test Case Preview";let u=document.createElement("div");u.classList.add("plwd-preview"),u.appendChild(m),u.appendChild(d),u.appendChild(f),u.appendChild(l);let x=document.createElement("div");x.classList.add("plwd-toast-icon");let h=document.createElement("div");h.classList.add("plwd-toast-content");let p=document.createElement("div");p.classList.add("plwd-panel"),p.appendChild(n),p.appendChild(i),p.appendChild(u),document.body.appendChild(p);let E=document.createElement("div");E.classList.add("plwd-toast"),E.appendChild(x),E.appendChild(h),document.body.appendChild(E)})},Gt=(e,t)=>{let n=r=>{let o=document.createElementNS("http://www.w3.org/2000/svg","path");o.classList.add("plwd-trash-lid"),o.setAttribute("d","M6 15l4 0 0-3 8 0 0 3 4 0 0 2 -16 0zM12 14l4 0 0 1 -4 0z"),o.setAttribute("fill-rule","evenodd");let a=document.createElementNS("http://www.w3.org/2000/svg","path");a.classList.add("plwd-trash-can"),a.setAttribute("d","M8 17h2v9h8v-9h2v9a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2z");let c=document.createElementNS("http://www.w3.org/2000/svg","svg");c.classList.add("plwd-trash-icon"),c.setAttribute("viewBox","3 6 24 28"),c.appendChild(o),c.appendChild(a);let i=document.createElement("button");return i.classList.add("plwd-delete-btn"),i.setAttribute("data-index",r.toString()),i.appendChild(c),i};e.replaceChildren();for(let[r,o]of t.entries()){let a=n(r),c=document.createElement("li"),i=document.createElement("span"),l=document.createTextNode(o.input);"success"in o.actions[0]&&(i.innerText=o.actions[0].success?"\u2713":"\u2715",i.style.color=o.actions[0].success?"#26a69a":"#f44336"),i.classList.add("plwd-marker"),c.classList.add("plwd-timeline-item"),c.appendChild(i),c.appendChild(l),c.appendChild(a),e.appendChild(c)}},Ut=e=>{let t=document.querySelector(".plwd-toast-content"),n=document.querySelector(".plwd-toast-icon"),r=document.querySelector(".plwd-toast:not(.open)");t&&n&&r&&(t.innerText=e.content,n.innerText=e.icon,r.style.color=e.color,r.classList.add("open"),setTimeout(()=>r.classList.remove("open"),1900))},Kt=(e,t)=>{if(e.replaceChildren(),!t)return;let n=document.createElement("div");n.classList.add("plwd-loader"),e.appendChild(n)};var $t=Ce(require("sanitize-html"));var ot=new RegExp(/^\[\b(?:ai)\b\]/i),Jt=new RegExp(/^\b(?:are|assert|assure|can|check|compare|confirm|could|did|do|does|ensure|expect|guarantee|has|have|is|match|satisfy|shall|should|test|then|was|were|validate|verify)\b/i),Yt=new RegExp(new RegExp("(?<={)[^{}]+(?=})","g")),N=["a","button","div","h1","h2","h3","h4","h5","h6","img","input","label","li","p","select","span","strong","td","textarea","th","ul"];var Xt=`
.plwd-panel {
background: rgba(0, 0, 0, .7);
height: 100%;
opacity: 0;
transition: all .3s;
visibility: hidden;
width: 100%;
}
.plwd-banner {
color: #ffffff !important;
font-size: 32px !important;
font-weight: bold;
left: 4vw;
position: absolute;
top: 6vh;
}
.plwd-input {
background: transparent;
border: none;
border-bottom: 1px solid #ffffff;
color: #ffffff !important;
font-size: 20px !important;
font-weight: bold;
letter-spacing: 2px;
padding: 12px;
width: 90%;
}
.plwd-input[disabled] {
cursor: not-allowed;
opacity: 0.5;
}
.plwd-input-box {
margin: 10% auto 0 auto;
width: 90%;
}
.plwd-timeline {
max-height: 55vh;
overflow-x: hidden;
overflow-y: auto;
padding: 0;
position: relative;
width: 100%;
}
.plwd-preview {
margin: auto;
width: 80%;
text-align: left;
}
.plwd-preview-title {
color: #ffffff !important;
display: inline-block;
float: left;
font-size: 32px !important;
font-weight: bold;
height: 40px;
line-height: 40px;
margin: 0;
visibility: hidden;
}
.plwd-panel {
display: block;
left: 0;
position: fixed;
text-align: center;
top: 50%;
transform: translateY(-50%);
z-index: 2147483647;
}
.plwd-toast {
background: #333333;
border-radius: 25px;
bottom: 30px;
font-size: 24px !important;
font-weight: bold;
height: 50px;
left: 0;
line-height: 50px;
margin: auto;
position: fixed;
right: 0;
text-align: center;
visibility: hidden;
width: 50px;
z-index: 2147483647;
}
.plwd-toast-icon {
float: left;
width: 50px;
}
.plwd-toast-content {
overflow: hidden;
white-space: nowrap;
}
.plwd-toast.open {
animation: fade-in 0.5s, expand 0.5s 0.5s, stay 0.5s 1s, fade-out 0.5s 1.5s;
visibility: visible;
}
.plwd-input:focus {
outline: none;
}
.plwd-input::placeholder {
color: #ffffff !important;
font-size: 20px !important;
opacity: 0.4;
padding: 12px;
}
.plwd-loader-box {
display: inline-block;
height: 20px;
width: 20px;
}
.plwd-accept-btn {
border-radius: 25px;
color: #4db6ac !important;
font-size: 20px !important;
height: 45px;
line-height: 45px;
margin: 8px;
width: 150px;
}
.plwd-cancel-btn {
border-radius: 25px;
color: #e0e0e0 !important;
font-size: 20px !important;
height: 45px;
line-height: 45px;
margin: 8px;
width: 150px;
}
.plwd-dry-run-btn {
border-radius: 25px;
color: #e5c07b !important;
float: right;
font-size: 20px !important;
height: 40px;
line-height: 40px;
width: 100px;
visibility: hidden;
}
.plwd-clear-btn {
border-radius: 25px;
color: #e0e0e0 !important;
float: right;
font-size: 20px !important;
height: 40px;
line-height: 40px;
width: 100px;
visibility: hidden;
}
.plwd-delete-btn {
border-radius: 25px;
color: #ff6c6c !important;
height: 40px;
line-height: 40px;
margin: 0 8px;
width: 80px;
}
.plwd-accept-btn, .plwd-cancel-btn, .plwd-dry-run-btn, .plwd-clear-btn, .plwd-delete-btn {
background: transparent;
border: none;
box-sizing: border-box;
cursor: pointer;
font-weight: bold;
outline: none;
overflow: hidden;
position: relative;
text-align: center;
vertical-align: middle;
}
.plwd-accept-btn::before,
.plwd-cancel-btn::before,
.plwd-dry-run-btn::before,
.plwd-clear-btn::before,
.plwd-delete-btn::before {
background: currentColor;
bottom: 0;
content: '';
left: 0;
opacity: 0;
position: absolute;
right: 0;
top: 0;
transition: opacity .3s;
}
.plwd-accept-btn::after,
.plwd-cancel-btn::after,
.plwd-dry-run-btn::after,
.plwd-clear-btn::after,
.plwd-delete-btn::after {
background: currentColor;
border-radius: 25px;
content: '';
height: 6vh;
left: 50%;
opacity: 0;
padding: 50%;
position: absolute;
transform: translate(-50%, -50%) scale(1);
transition: opacity 1s, transform .5s;
}
.plwd-accept-btn:hover::before,
.plwd-cancel-btn:hover::before,
.plwd-dry-run-btn:hover::before,
.plwd-clear-btn:hover::before,
.plwd-delete-btn:hover::before {
opacity: .1;
}
.plwd-accept-btn:active::after,
.plwd-cancel-btn:active::after,
.plwd-dry-run-btn:active::after,
.plwd-clear-btn:active::after,
.plwd-delete-btn:active::after {
opacity: .2;
transform: translate(-50%, -50%) scale(0);
transition: transform 0s;
}
.plwd-panel.open, .plwd-preview-title.open, .plwd-dry-run-btn.open, .plwd-clear-btn.open {
opacity: 1;
visibility: visible;
}
.plwd-loader {
animation: loading .75s infinite linear;
border-bottom: 4px solid rgba(255, 255, 255, .5);
border-left: 4px solid rgba(255, 255, 255, .5);
border-right: 4px solid rgba(255, 255, 255, .5);
border-top: 4px solid rgba(255, 255, 255, 1);
border-radius: 100%;
height: inherit;
width: inherit;
}
.plwd-marker {
font-size: 16px !important;
font-weight: bold;
padding: 0 16px;
}
.plwd-timeline-item {
animation: draw-border 1s;
color: #ffffff !important;
content-visibility: auto;
border-color: #26a69a;
border-style: solid;
border-width: 2px;
border-right-width: 0px;
border-top-width: 0px;
font-size: 24px !important;
height: 100px;
line-height: 100px;
list-style-type: none;
overflow-x: auto;
overflow-y: hidden;
padding: 0 16px;
position: relative;
text-align: left;
white-space: nowrap;
width: 100%;
}
.plwd-timeline-item:last-child {
border-bottom: none;
}
.plwd-delete-btn::before {
background: currentColor;
bottom: 0;
content: '';
left: 0;
opacity: 0;
position: absolute;
right: 0;
top: 0;
transition: opacity .3s;
}
.plwd-trash-icon {
fill: #ff6c6c;
height: 40px;
width: 40%;
}
.plwd-trash-lid {
transform-origin: right bottom;
transition: transform .2s cubic-bezier(0.4, 0.0, 0.2, 1);
}
.plwd-delete-btn:hover .plwd-trash-lid {
transform: translateY(-1px) rotate(10deg);
}
@keyframes expand {
from {
min-width: 50px;
}
to {
min-width: 250px;
}
}
@keyframes fade-in {
from {
bottom: 0;
opacity: 0;
}
to {
bottom: 30px;
opacity: 1;
}
}
@keyframes stay {
from {
min-width: 250px;
}
to {
min-width: 250px;
}
}
@keyframes fade-out {
from {
bottom: 30px;
min-width: 250px;
opacity: 1;
}
to {
bottom: 45px;
min-width: 250px;
opacity: 0;
}
}
@keyframes draw-border {
0% {
max-height: 0;
width: 0;
}
30% {
max-height: 100px;
width: 0;
}
100% {
max-height: 100px;
width: 100%;
}
}
@keyframes loading {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
`,k=e=>(0,$t.default)(e,{allowedAttributes:{"*":["aria*","class","data*","href","id","name","placeholder","title","type","value"]},allowedStyles:{"*":{"*":[]}},allowedTags:N});var w=(e,t="none",n=!1)=>{if(process.env.PLWD_DEBUG!=="true")return;let r={green:32,magenta:35,red:31};return n&&console.log("-".repeat(process.stdout.columns)),console.log(t==="none"?e:`\x1B[${r[t]}m${e}\x1B[0m`)};var I=(n,...r)=>s(void 0,[n,...r],function*(e,t={}){var a;if(e.frame=void 0,t.frameSrc&&(yield Pe(e,t.frameSrc))){let c=(a=e.page)==null?void 0:a.frames().find(i=>i.url()===t.frameSrc);e.frame=c}let o=e.frame||e.page;return yield o.waitForLoadState("domcontentloaded"),o}),D=e=>{let t=e.match(Yt);return t&&process.env[t[0]]||e},Pe=(e,t,n=3e4)=>s(void 0,null,function*(){var a;let r=Date.now(),o=!1;for(;!o&&Date.now()-r<n;)o=!!((a=e.page)!=null&&a.frames().some(c=>c.url()===t)),yield(0,Qt.setTimeout)(500);return o}),it=(e,t)=>s(void 0,null,function*(){var n;try{let o=(yield I(e,t)).locator(t.xpath).first(),a=D(t.text);return yield o.waitFor({state:"visible",timeout:5e3}),!!((n=yield o.textContent())!=null&&n.includes(a))}catch(r){return!1}}),st=(e,t)=>s(void 0,null,function*(){var n;try{let o=(yield I(e,t)).locator(t.xpath).first(),a=D(t.text);return yield o.waitFor({state:"visible",timeout:5e3}),!((n=yield o.textContent())!=null&&n.includes(a))||!1}catch(r){return!1}}),rt=(e,t)=>s(void 0,null,function*(){var n;try{let o=(yield I(e,t)).locator(t.xpath).first(),a=D(t.text);return yield o.waitFor({state:"visible",timeout:5e3}),((n=yield o.textContent())==null?void 0:n.trim())===a.trim()}catch(r){return!1}}),ct=(e,t)=>s(void 0,null,function*(){var n;try{let o=(yield I(e,t)).locator(t.xpath).first(),a=D(t.text);return yield o.waitFor({state:"visible",timeout:5e3}),((n=yield o.textContent())==null?void 0:n.trim())!==a.trim()}catch(r){return!1}}),lt=(e,t)=>s(void 0,null,function*(){try{return yield(yield I(e,t)).locator(t.xpath).first().waitFor({state:"visible",timeout:5e3}),!0}catch(n){return!1}}),dt=(e,t)=>s(void 0,null,function*(){try{return yield(yield I(e,t)).locator(t.xpath).first().waitFor({state:"hidden",timeout:5e3}),!0}catch(n){return!1}}),pt=(e,t)=>s(void 0,null,function*(){try{let n=yield I(e,t),r=D(t.text),o=yield n.getByText(r).all();return(yield Promise.all(o.map(c=>c.isVisible()))).some(Boolean)}catch(n){return!1}}),mt=(e,t)=>s(void 0,null,function*(){try{let n=yield I(e,t),r=D(t.text),o=yield n.getByText(r).all();return!(yield Promise.all(o.map(c=>c.isVisible()))).some(Boolean)}catch(n){return!1}}),ut=(e,t)=>s(void 0,null,function*(){var n;try{let r=D(t.text);return(yield(n=e.page)==null?void 0:n.title())===r}catch(r){return!1}}),ht=(e,t)=>s(void 0,null,function*(){try{let n=e.page.url();return new RegExp(t.pattern).test(n)}catch(n){return!1}}),ft=(e,t)=>s(void 0,null,function*(){try{let r=(yield I(e,t)).locator(t.xpath).first();return yield r.waitFor({state:"visible",timeout:5e3}),yield r.click({timeout:5e3}),"Performed the click action"}catch(n){return"Failed to perform the action"}}),gt=(e,t)=>s(void 0,null,function*(){var n;try{return yield(n=e.page)==null?void 0:n.goto(t.url),"Navigated to "+t.url}catch(r){return"Failed to perform the action"}}),wt=(e,t)=>s(void 0,null,function*(){var n;try{let o=(yield I(e,t)).locator(t.xpath).first();return yield o.waitFor({state:"visible",timeout:5e3}),yield o.hover({timeout:5e3}),t.duration&&(yield(n=e.page)==null?void 0:n.waitForTimeout(t.duration)),"Performed the hover action"}catch(r){return"Failed to perform the action"}}),yt=(e,t)=>s(void 0,null,function*(){try{let r=(yield I(e,t)).locator(t.xpath).first(),o=D(t.text);return yield r.waitFor({state:"visible",timeout:5e3}),yield r.fill(o,{timeout:5e3}),"Performed the input action"}catch(n){return"Failed to perform the action"}}),bt=(e,t)=>s(void 0,null,function*(){var n;try{return yield(n=e.page)==null?void 0:n.keyboard.press(t.keys),"Pressed keys "+t.keys}catch(r){return"Failed to perform the action"}}),xt=(e,t)=>s(void 0,null,function*(){try{let n=yield I(e,t);switch(t.direction){case"up":return yield n.evaluate(()=>window.scrollBy({top:window.innerHeight})),"scrolled up";case"down":return yield n.evaluate(()=>window.scrollBy({top:window.innerHeight})),"scrolled down";case"top":return yield n.evaluate(()=>window.scrollTo({top:0})),"scrolled to top";case"bottom":return yield n.evaluate(()=>window.scrollTo({top:document.body.scrollHeight})),"scrolled to bottom";default:return`Unsupported scroll target ${t.direction}`}}catch(n){return"Failed to perform the action"}}),vt=(e,t)=>s(void 0,null,function*(){try{let r=(yield I(e,t)).locator(t.xpath).first();return yield r.waitFor({state:"visible",timeout:5e3}),yield r.selectOption({value:t.option},{timeout:5e3}),"Performed the select action"}catch(n){return"Failed to perform the action"}}),At=(e,t)=>s(void 0,null,function*(){var n;try{return yield(n=e.page)==null?void 0:n.waitForTimeout(t.duration),"Slept for "+t.duration+" milliseconds"}catch(r){return"Failed to perform the action"}}),J=(e,t)=>s(void 0,null,function*(){var n;try{return e.frame=void 0,t.frameNumber!==void 0&&(e.frame=(n=e.page)==null?void 0:n.frames()[t.frameNumber]),"Switched to frame"}catch(r){return"Failed to perform the action"}}),Ct=(e,t)=>s(void 0,null,function*(){try{return e.page=e.context.pages()[t.pageNumber||0],"Switched to page"}catch(n){return"Failed to perform the action"}}),Et=(e,t)=>s(void 0,null,function*(){try{let n=yield I(e,t),r=D(t.text);return yield n.waitForSelector("text="+r,{state:"visible",timeout:3e4}),"Waited for text: "+r}catch(n){return"Failed to perform the action"}});var _=require("fs/promises"),Zt=require("path");var B=class{constructor(t=""){this.recordPath=t;g(this,"position",0);g(this,"recordings",[]);g(this,"check",t=>s(this,null,function*(){try{return yield(0,_.access)(t),t.endsWith(".json")}catch(n){return!1}}));g(this,"removeProperty",(t,n)=>{if(!(!t||typeof t!="object")){if(Array.isArray(t))return t.forEach(r=>this.removeProperty(r,n));for(let r of Object.keys(t))r===n?delete t[r]:this.removeProperty(t[r],n)}})}addAction(t){this.recordings[this.position].actions.push(t)}clear(){this.recordings=[],this.position=0}count(){return this.recordings.length}delete(t){t<0||t>=this.recordings.length||(this.recordings.splice(t,1),this.position>=t&&this.position--,this.position<0&&(this.position=0))}initStep(t,n){this.position=t,this.recordings[t]={input:n,actions:[]}}list(){return this.recordings}load(){return s(this,null,function*(){(yield this.check(this.recordPath))&&(this.recordings=JSON.parse(yield(0,_.readFile)(this.recordPath,"utf-8")))})}save(){return s(this,arguments,function*(t=[]){let n=structuredClone(this.recordings.slice(0,this.position+1));for(let r of t)this.removeProperty(n,r);yield(0,_.mkdir)((0,Zt.dirname)(this.recordPath),{recursive:!0}),yield(0,_.writeFile)(this.recordPath,JSON.stringify(n,null,2))})}};var R=require("@langchain/core/tools"),A=require("zod");var Pt=[(0,R.tool)((r,o)=>s(void 0,[r,o],function*({keywords:e,text:t},{configurable:n}){let{ref:a}=n,{ai:c,input:i,page:l,recorder:d}=a,m=(yield l.evaluate(L,N)).map(({html:p,xpath:E})=>({html:k(p),xpath:E}));w("Embedding the snapshot..."),yield c.embedTexts(m.map(({html:p})=>p)),w("Snapshot embedded.");let u=yield c.searchDocuments(e),x=yield c.getBestCandidate(i,u),{xpath:h}=m.find(({html:p})=>p===u[x].pageContent);return d==null||d.addAction({name:"assertElementContains",params:{text:t,xpath:h}}),(yield it(a,{text:t,xpath:h}))?"PASS: Element contains text: "+t:"FAIL: Element does not contain text: "+t}),{name:"AssertElementContains",description:"Call to verify that an element contains specific text",schema:A.z.object({keywords:A.z.string().describe("Keywords for searching the relevant element from user input"),text:A.z.string().describe("The text to verify on the element")})}),(0,R.tool)((r,o)=>s(void 0,[r,o],function*({keywords:e,text:t},{configurable:n}){let{ref:a}=n,{ai:c,input:i,page:l,recorder:d}=a,m=(yield l.evaluate(L,N)).map(({html:p,xpath:E})=>({html:k(p),xpath:E}));w("Embedding the snapshot..."),yield c.embedTexts(m.map(({html:p})=>p)),w("Snapshot embedded.");let u=yield c.searchDocuments(e),x=yield c.getBestCandidate(i,u),{xpath:h}=m.find(({html:p})=>p===u[x].pageContent);return d==null||d.addAction({name:"assertElementNotContain",params:{text:t,xpath:h}}),(yield st(a,{text:t,xpath:h}))?"PASS: Element does not contain text: "+t:"FAIL: Element contains text: "+t}),{name:"AssertElementNotContain",description:"Call to verify that an element does not contain specific text",schema:A.z.object({keywords:A.z.string().describe("Keywords for searching the relevant element from user input"),text:A.z.string().describe("The text to verify on the element")})}),(0,R.tool)((r,o)=>s(void 0,[r,o],function*({keywords:e,text:t},{configurable:n}){let{ref:a}=n,{ai:c,input:i,page:l,recorder:d}=a,m=(yield l.evaluate(L,N)).map(({html:p,xpath:E})=>({html:k(p),xpath:E}));w("Embedding the snapshot..."),yield c.embedTexts(m.map(({html:p})=>p)),w("Snapshot embedded.");let u=yield c.searchDocuments(e),x=yield c.getBestCandidate(i,u),{xpath:h}=m.find(({html:p})=>p===u[x].pageContent);return d==null||d.addAction({name:"assertElementContentEquals",params:{xpath:h,text:t}}),(yield rt(a,{xpath:h,text:t}))?"PASS: Element content is equal to: "+t:"FAIL: Element content is not equal to: "+t}),{name:"AssertElementContentEquals",description:"Call to verify that an element has specific text",schema:A.z.object({keywords:A.z.string().describe("Keywords for searching the relevant element from user input"),text:A.z.string().describe("The text to verify on the element")})}),(0,R.tool)((r,o)=>s(void 0,[r,o],function*({keywords:e,text:t},{configurable:n}){let{ref:a}=n,{ai:c,input:i,page:l,recorder:d}=a,m=(yield l.evaluate(L,N)).map(({html:p,xpath:E})=>({html:k(p),xpath:E}));w("Embedding the snapshot..."),yield c.embedTexts(m.map(({html:p})=>p)),w("Snapshot embedded.");let u=yield c.searchDocuments(e),x=yield c.getBestCandidate(i,u),{xpath:h}=m.find(({html:p})=>p===u[x].pageContent);return d==null||d.addAction({name:"assertElementContentNotEqual",params:{xpath:h,text:t}}),(yield ct(a,{xpath:h,text:t}))?"PASS: Element content is not equal to: "+t:"FAIL: Element content is equal to: "+t}),{name:"AssertElementContentNotEqual",description:"Call to verify that an element does not have specific text",schema:A.z.object({keywords:A.z.string().describe("Keywords for searching the relevant element from user input"),text:A.z.string().describe("The text to verify on the element")})}),(0,R.tool)((n,r)=>s(void 0,[n,r],function*({keywords:e},{configurable:t}){let{ref:o}=t,{ai:a,input:c,page:i,recorder:l}=o,f=(yield i.evaluate(L,N)).map(({html:h,xpath:p})=>({html:k(h),xpath:p}));w("Embedding the snapshot..."),yield a.embedTexts(f.map(({html:h})=>h)),w("Snapshot embedded.");let m=yield a.searchDocuments(e),u=yield a.getBestCandidate(c,m),{xpath:x}=f.find(({html:h})=>h===m[u].pageContent);return l==null||l.addAction({name:"assertElementVisible",params:{xpath:x}}),(yield lt(o,{xpath:x}))?"PASS: Element is visible":"FAIL: Element is invisible"}),{name:"AssertElementVisible",description:"Call to verify that an element is visible",schema:A.z.object({keywords:A.z.string().describe("Keywords for searching the relevant element from user input")})}),(0,R.tool)((n,r)=>s(void 0,[n,r],function*({keywords:e},{configurable:t}){let{ref:o}=t,{ai:a,input:c,page:i,recorder:l}=o,f=(yield i.evaluate(L,N)).map(({html:h,xpath:p})=>({html:k(h),xpath:p}));w("Embedding the snapshot..."),yield a.embedTexts(f.map(({html:h})=>h)),w("Snapshot embedded.");let m=yield a.searchDocuments(e),u=yield a.getBestCandidate(c,m),{xpath:x}=f.find(({html:h})=>h===m[u].pageContent);return l==null||l.addAction({name:"assertElementNotVisible",params:{xpath:x}}),(yield dt(o,{xpath:x}))?"PASS: Element is invisible":"FAIL: Element is visible"}),{name:"AssertElementNotVisible",description:"Call to verify that an element is not visible",schema:A.z.object({keywords:A.z.string().describe("Keywords for searching the relevant element from user input")})}),(0,R.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"assertPageContains",params:{text:e}}),(yield pt(o,{text:e}))?"PASS: Page contains text: "+e:"FAIL: Page does not contain text: "+e}),{name:"AssertPageContains",description:"Call to verify that the page contains specific text",schema:A.z.object({text:A.z.string().describe("The text to verify on the page")})}),(0,R.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"assertPageNotContain",params:{text:e}}),(yield mt(o,{text:e}))?"PASS: Page does not contain text: "+e:"FAIL: Page contains text: "+e}),{name:"AssertPageNotContain",description:"Call to verify that the page does not contain specific text",schema:A.z.object({text:A.z.string().describe("The text to verify on the page")})}),(0,R.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"assertPageTitleContains",params:{text:e}}),(yield ut(o,{text:e}))?"PASS: Page title is equal to: "+e:"FAIL: Page title is not equal to: "+e}),{name:"AssertPageTitleEquals",description:"Call to verify that the page title is equal to specific text",schema:A.z.object({text:A.z.string().describe("The text to verify on the page title")})}),(0,R.tool)((n,r)=>s(void 0,[n,r],function*({pattern:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"assertPageTitleMatches",params:{pattern:e}}),(yield ht(o,{pattern:e}))?"PASS: Page URL matches the pattern: "+e:"FAIL: Page URL does not match the pattern: "+e}),{name:"AssertPageUrlMatches",description:"Call to verify that the page URL matches a specific pattern",schema:A.z.object({pattern:A.z.string().describe("The pattern to verify on the page URL")})})];var P=require("@langchain/core/tools"),y=require("zod");var Tt=[(0,P.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){return JSON.stringify({name:"assertElementContains",params:S(C({},t.action.params),{text:e})})}),{name:"AssertElementContains",description:"Call to verify that an element contains specific text",schema:y.z.object({text:y.z.string().describe("The text to verify")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){return JSON.stringify({name:"assertElementNotContain",params:S(C({},t.action.params),{text:e})})}),{name:"AssertElementNotContain",description:"Call to verify that an element does not contain specific text",schema:y.z.object({text:y.z.string().describe("The text to verify")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){return JSON.stringify({name:"assertElementContentEquals",params:S(C({},t.action.params),{text:e})})}),{name:"AssertElementContentEquals",description:"Call to verify that an element has specific text",schema:y.z.object({text:y.z.string().describe("The text to verify")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){return JSON.stringify({name:"assertElementContentNotEqual",params:S(C({},t.action.params),{text:e})})}),{name:"AssertElementContentNotEqual",description:"Call to verify that an element does not have specific text",schema:y.z.object({text:y.z.string().describe("The text to verify")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*(e,{configurable:t}){return JSON.stringify({name:"assertElementVisible",params:t.action.params})}),{name:"AssertElementVisible",description:"Call to verify that an element is visible"}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*(e,{configurable:t}){return JSON.stringify({name:"assertElementNotVisible",params:t.action.params})}),{name:"AssertElementNotVisible",description:"Call to verify that an element is not visible"}),(0,P.tool)(t=>s(void 0,[t],function*({text:e}){return JSON.stringify({name:"assertPageContains",params:{text:e}})}),{name:"AssertPageContains",description:"Call to verify that the page contains specific text",schema:y.z.object({text:y.z.string().describe("The text to verify")})}),(0,P.tool)(t=>s(void 0,[t],function*({text:e}){return JSON.stringify({name:"assertPageNotContain",params:{text:e}})}),{name:"AssertPageNotContain",description:"Call to verify that the page does not contain specific text",schema:y.z.object({text:y.z.string().describe("The text to verify")})}),(0,P.tool)(t=>s(void 0,[t],function*({text:e}){return JSON.stringify({name:"assertPageTitleEquals",params:{text:e}})}),{name:"AssertPageTitleEquals",description:"Call to verify that the page title equals specific text",schema:y.z.object({text:y.z.string().describe("The text to verify")})}),(0,P.tool)(t=>s(void 0,[t],function*({pattern:e}){return JSON.stringify({name:"assertPageUrlMatches",params:{pattern:e}})}),{name:"AssertPageUrlMatches",description:"Call to verify that the page URL matches a specific pattern",schema:y.z.object({pattern:y.z.string().describe("The pattern to match")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*(e,{configurable:t}){return JSON.stringify({name:"click",params:t.action.params})}),{name:"Click",description:"Call to handle the click event"}),(0,P.tool)(t=>s(void 0,[t],function*({url:e}){return JSON.stringify({name:"goto",params:{url:e}})}),{name:"GoTo",description:"Call to handle the navigation event",schema:y.z.object({url:y.z.string().describe("The URL to navigate to")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*({duration:e},{configurable:t}){return JSON.stringify({name:"hover",params:S(C({},t.action.params),{duration:e})})}),{name:"Hover",description:"Call to handle the hover event",schema:y.z.object({duration:y.z.number().describe("How long the hover event should last. Default is 1000ms")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){return JSON.stringify({name:"input",params:C({text:e},t.action.params)})}),{name:"Input",description:"Call to handle the input event",schema:y.z.object({text:y.z.string().describe("The text to input")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*({direction:e},{configurable:t}){return JSON.stringify({name:"scroll",params:S(C({},t.action.params),{direction:e})})}),{name:"Scroll",description:"Call to handle the scroll event",schema:y.z.object({direction:y.z.enum(["up","down","top","bottom"]).describe("The direction to scroll")})}),(0,P.tool)((n,r)=>s(void 0,[n,r],function*({option:e},{configurable:t}){return JSON.stringify({name:"select",params:C({option:e},t.action.params)})}),{name:"Select",description:"Call to handle the select event",schema:y.z.object({option:y.z.string().describe("The option to select")})}),(0,P.tool)(t=>s(void 0,[t],function*({duration:e}){return JSON.stringify({name:"sleep",params:{duration:e}})}),{name:"Sleep",description:"Call to handle the sleep event",schema:y.z.object({duration:y.z.number().describe("The duration to sleep in milliseconds")})}),(0,P.tool)(t=>s(void 0,[t],function*({text:e}){return JSON.stringify({name:"waitForText",params:{text:e}})}),{name:"WaitForText",description:"Call to handle the wait for text event",schema:y.z.object({text:y.z.string().describe("The text to wait for")})})];var te=require("@langchain/core/documents"),F=require("@langchain/core/tools"),v=require("zod");var St=[(0,F.tool)((n,r)=>s(void 0,[n,r],function*({keywords:e},{configurable:t}){let{ref:o}=t,{ai:a,input:c,page:i,recorder:l}=o,f=(yield i.evaluate(L,N)).map(({html:h,xpath:p})=>({html:k(h),xpath:p}));w("Embedding the snapshot..."),yield a.embedTexts(f.map(({html:h})=>h)),w("Snapshot embedded.");let m=yield a.searchDocuments(e),u=yield a.getBestCandidate(c,m),{xpath:x}=f.find(({html:h})=>h===m[u].pageContent);return l==null||l.addAction({name:"click",params:{xpath:x}}),ft(o,{xpath:x})}),{name:"Click",description:"Call to click on an element",schema:v.z.object({keywords:v.z.string().describe("Keywords for searching the relevant element from user input")})}),(0,F.tool)((n,r)=>s(void 0,[n,r],function*({url:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"goto",params:{url:e}}),gt(o,{url:e})}),{name:"GoTo",description:"Call to go to a specific URL",schema:v.z.object({url:v.z.string().describe("The URL to navigate to")})}),(0,F.tool)((r,o)=>s(void 0,[r,o],function*({duration:e,keywords:t},{configurable:n}){let{ref:a}=n,{ai:c,input:i,page:l,recorder:d}=a,m=(yield l.evaluate(L,N)).map(({html:p,xpath:E})=>({html:k(p),xpath:E}));w("Embedding the snapshot..."),yield c.embedTexts(m.map(({html:p})=>p)),w("Snapshot embedded.");let u=yield c.searchDocuments(t),x=yield c.getBestCandidate(i,u),{xpath:h}=m.find(({html:p})=>p===u[x].pageContent);return d==null||d.addAction({name:"hover",params:{duration:e,xpath:h}}),wt(a,{duration:e,xpath:h})}),{name:"Hover",description:"Call to hover over an element",schema:v.z.object({duration:v.z.number().describe("The duration to hover over the element. Default is 1000ms"),keywords:v.z.string().describe("Keywords for searching the relevant element from user input")})}),(0,F.tool)((r,o)=>s(void 0,[r,o],function*({keywords:e,text:t},{configurable:n}){let{ref:a}=n,{ai:c,input:i,page:l,recorder:d}=a,m=(yield l.evaluate(L,["input","textarea"])).map(({html:p,xpath:E})=>({html:k(p),xpath:E}));w("Embedding the snapshot..."),yield c.embedTexts(m.map(({html:p})=>p)),w("Snapshot embedded.");let u=yield c.searchDocuments(e),x=yield c.getBestCandidate(i,u),{xpath:h}=m.find(({html:p})=>p===u[x].pageContent);return d==null||d.addAction({name:"input",params:{text:t,xpath:h}}),yt(a,{text:t,xpath:h})}),{name:"Input",description:"Call to type text into the input field or textarea",schema:v.z.object({keywords:v.z.string().describe("Keywords for searching the relevant element from user input"),text:v.z.string().describe("Text to input")})}),(0,F.tool)((n,r)=>s(void 0,[n,r],function*({keys:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"pressKeys",params:{keys:e}}),bt(o,{keys:e})}),{name:"PressKeys",description:"Call to press a key or keys",schema:v.z.object({keys:v.z.string().describe("Keys to press. The format should match the Playwright API")})}),(0,F.tool)((n,r)=>s(void 0,[n,r],function*({direction:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"scroll",params:{direction:e}}),xt(o,{direction:e})}),{name:"Scroll",description:"Call to scroll the page",schema:v.z.object({direction:v.z.enum(["top","bottom","up","down"]).describe("The direction to scroll")})}),(0,F.tool)((r,o)=>s(void 0,[r,o],function*({keywords:e,option:t},{configurable:n}){let{ref:a}=n,{ai:c,input:i,page:l,recorder:d}=a,m=(yield l.evaluate(L,["select"])).map(({html:p,xpath:E})=>({html:k(p),xpath:E}));w("Embedding the snapshot..."),yield c.embedTexts(m.map(({html:p})=>p)),w("Snapshot embedded.");let u=yield c.searchDocuments(e),x=yield c.getBestCandidate(i,u),{xpath:h}=m.find(({html:p})=>p===u[x].pageContent);return d==null||d.addAction({name:"select",params:{option:t,xpath:h}}),vt(a,{option:t,xpath:h})}),{name:"Select",description:"Call to select an option from a select element",schema:v.z.object({keywords:v.z.string().describe("Keywords for searching the relevant element from user input"),option:v.z.string().describe("The option to select")})}),(0,F.tool)((n,r)=>s(void 0,[n,r],function*({duration:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"sleep",params:{duration:e}}),At(o,{duration:e})}),{name:"Sleep",description:"Call to wait for a certain amount of time",schema:v.z.object({duration:v.z.number().describe("The duration to wait in milliseconds")})}),(0,F.tool)((n,r)=>s(void 0,[n,r],function*({enterFrame:e},{configurable:t}){let{ref:o}=t,{ai:a,input:c,page:i,recorder:l}=o,d=i==null?void 0:i.frames().map(f=>JSON.stringify({name:f.name(),url:f.url()}));if(e&&(d!=null&&d.length)){let f=d.map(u=>new te.Document({pageContent:u})),m=yield a.getBestCandidate(c,f);return l==null||l.addAction({name:"switchFrame",params:{frameNumber:m}}),J(o,{frameNumber:m})}return l==null||l.addAction({name:"switchFrame",params:{}}),J(o,{})}),{name:"SwitchFrame",description:"Call to switch, enter or return to a frame",schema:v.z.object({enterFrame:v.z.boolean().describe("Return true to enter the frame, false to return to the main page")})}),(0,F.tool)((n,r)=>s(void 0,[n,r],function*({pageNumber:e},{configurable:t}){let{ref:o}=t;return Ct(o,{pageNumber:e})}),{name:"SwitchPage",description:"Call to switch to a different page or tab",schema:v.z.object({pageNumber:v.z.number().describe("The index of the page to switch to. Starts from 0")})}),(0,F.tool)((n,r)=>s(void 0,[n,r],function*({text:e},{configurable:t}){var a;let{ref:o}=t;return(a=o.recorder)==null||a.addAction({name:"waitForText",params:{text:e}}),Et(o,{text:e})}),{name:"WaitForText",description:"Call to wait for text to appear on the page",schema:v.z.object({text:v.z.string().describe("Text to wait for")})})];var It=class{constructor(t,{delay:n=250,recordPath:r=".playword/recordings.json"}={}){this.playword=t;g(this,"action",{name:"",params:{}});g(this,"delay");g(this,"input","");g(this,"recorder");g(this,"state",{dryRunning:!1,waitingForAI:!1,waitingForUserAction:!1});this.delay=Math.abs(n),this.recorder=new B(r),this.playword.recorder=void 0,this.observe=this.observe.bind(this)}ai(){return this.playword.ai}context(){return this.playword.context}page(){return this.playword.page}setPageListeners(){return s(this,null,function*(){let t=()=>s(this,null,function*(){this.state.waitingForAI||(yield Promise.all([l(),u("Accepted","\u2713","#4db6ac")]),this.recorder.initStep(this.recorder.count(),this.input),this.recorder.addAction(this.action),yield this.recorder.save(["html","success"]),this.state.waitingForUserAction=!1)}),n=()=>s(this,null,function*(){this.state.waitingForAI||(this.state.waitingForUserAction=!1)}),r=()=>s(this,null,function*(){this.recorder.clear(),yield Promise.all([this.recorder.save(),h()])}),o=()=>s(this,null,function*(){yield Promise.all([m(".plwd-preview-title").evaluate(G,"open"),m(".plwd-clear-btn").evaluate(G,"open"),m(".plwd-dry-run-btn").evaluate(G,"open"),m(".plwd-panel").evaluate(G,"open")])}),a=b=>s(this,null,function*(){this.recorder.delete(b),yield Promise.all([this.recorder.save(["html","success"]),h()])}),c=b=>s(this,null,function*(){tt(""),yield Promise.all([E(),j(!0)]);let T=yield this.ai().summarizeAction(JSON.stringify(b));tt(T),yield Promise.all([E(),j(!1)])}),i=()=>s(this,null,function*(){w("Starting the dry run process...","green",!0),this.state.dryRunning=!0,this.state.waitingForUserAction=!1,yield Promise.all([u("Dry Run","\u{1F680}","#e5c07b"),p()]);for(let b of this.recorder.list())if(this.state.dryRunning){let T=b.actions[0],O=yield W[T.name](this.playword,T.params);T.success=!!(O!=="Failed to perform the action"&&O),w((T.success?"PASS: ":"FAIL: ")+b.input),yield(0,U.setTimeout)(this.delay)}yield u("Completed","\u{1F680}","#e5c07b"),this.state.dryRunning=!1,w("Dry Run Completed")}),l=()=>s(this,null,function*(){yield j(!0);let{tool_calls:b}=yield this.ai().useTools(Tt,[new ne.HumanMessage(this.input)]);if(!b||!b.length)return j(!1);let T=Tt.find(et=>et.name===b[0].name);if(!T)return j(!1);let{content:O}=yield T.invoke(b[0],{configurable:{action:this.action}});return O&&(this.action=JSON.parse(O),w("Input: "+this.input+`
Action: `+JSON.stringify(this.action,null,2),"green",!0)),j(!1)}),d=b=>s(this,null,function*(){if(!(this.state.dryRunning||this.state.waitingForAI||this.state.waitingForUserAction)){for(this.action=b,this.state.waitingForUserAction=!0,yield(0,U.setTimeout)(500),c(b);this.state.waitingForUserAction;)(yield f())||(yield Promise.all([x(),h(),E()])),yield(0,U.setTimeout)(200);yield o()}}),f=()=>s(this,null,function*(){return m(".plwd-panel").evaluate(zt,"open")}),m=b=>this.page().locator(b).first(),u=(b,T,O)=>s(this,null,function*(){yield this.page().evaluate(Ut,{content:b,icon:T,color:O})}),x=()=>s(this,null,function*(){yield m(".plwd-panel").evaluate(H,"open")}),h=()=>s(this,null,function*(){this.recorder.count()>0&&(yield Promise.all([m(".plwd-preview-title").evaluate(H,"open"),m(".plwd-clear-btn").evaluate(H,"open"),m(".plwd-dry-run-btn").evaluate(H,"open")])),yield m(".plwd-timeline").evaluate(Gt,this.recorder.list())}),p=()=>s(this,null,function*(){let b=()=>this.page().evaluate(jt),T=()=>this.context().clearCookies(),O=()=>this.page().evaluate(Wt),et=()=>this.page().evaluate(qt),fe=()=>this.page().evaluate(Vt);yield Promise.all([b(),T(),O(),fe(),et()]),yield(0,U.setTimeout)(2e3);for(let ge of this.context().pages())yield ge.close();yield this.context().newPage()}),E=()=>s(this,null,function*(){yield m(".plwd-input").evaluate(at,{name:"value",value:this.input})}),he=()=>{this.state.dryRunning=!1},tt=b=>{this.input=b},j=b=>s(this,null,function*(){yield Promise.all([m(".plwd-input").evaluate(at,{name:"disabled",value:b}),m(".plwd-loader-box").evaluate(Kt,b)]),this.state.waitingForAI=b});this.page().on("framenavigated",b=>{let T=b.url();if(!(T==="about:blank"||T!==this.page().mainFrame().url()))return d({name:"goto",params:{url:T}})}),yield Promise.all([this.page().addInitScript(Bt),this.page().addInitScript(Ht,Xt)]),yield Promise.all([this.page().exposeFunction("accept",t),this.page().exposeFunction("cancel",n),this.page().exposeFunction("clearAll",r),this.page().exposeFunction("deleteStep",a),this.page().exposeFunction("dryRun",i),this.page().exposeFunction("emit",d),this.page().exposeFunction("notify",u),this.page().exposeFunction("stopDryRun",he),this.page().exposeFunction("updateInput",tt)])})}observe(){return s(this,null,function*(){this.context().on("page",()=>s(this,null,function*(){yield this.setPageListeners(),yield this.page().reload()})),yield this.recorder.load()})}};var pe=require("@langchain/core/messages"),me=require("crypto"),ue=require("timers/promises");var ae=require("@langchain/core/messages"),M=require("@langchain/langgraph"),Lt=require("@langchain/langgraph/prebuilt");var Te=M.Annotation.Root({messages:(0,M.Annotation)({reducer:M.messagesStateReducer})}),Se=(n,r)=>s(void 0,[n,r],function*({messages:e},{configurable:t}){let{ai:o}=t==null?void 0:t.ref;return{messages:[yield o.useTools(Pt,e)]}}),Ie=(n,r)=>s(void 0,[n,r],function*({messages:e},{configurable:t}){let{ai:o}=t==null?void 0:t.ref;return{messages:[yield o.useTools(St,e)]}}),Le=(n,r)=>s(void 0,[n,r],function*({messages:e},{configurable:t}){let{ai:o}=t==null?void 0:t.ref,a=e[e.length-1].content.toString(),c=yield o.parseResult(e);return w(`${a} => ${c}`),{messages:[new ae.AIMessage(c.toString())]}}),Ne=t=>s(void 0,[t],function*({messages:e}){let n=e[e.length-1];return Jt.test(n.content.toString())?"assert":"page"}),ke=({messages:e})=>{let{tool_calls:t}=e[e.length-1];return t&&t.length>0?"assertionTools":"result"},Fe=({messages:e})=>{let{tool_calls:t}=e[e.length-1];return t&&t.length>0?"pageTools":"__end__"},oe=new M.StateGraph(Te).addNode("assert",Se).addNode("page",Ie).addNode("result",Le).addNode("assertionTools",new Lt.ToolNode(Pt)).addNode("pageTools",new Lt.ToolNode(St)).addConditionalEdges("__start__",Ne,["page","assert"]).addConditionalEdges("assert",ke,["assertionTools","result"]).addConditionalEdges("page",Fe,["pageTools","__end__"]).addEdge("assertionTools","assert").addEdge("pageTools","page").addEdge("result","__end__").compile({checkpointer:new M.MemorySaver});var le=require("@langchain/anthropic"),de=require("@langchain/core/messages"),X=require("@langchain/google-genai"),Q=require("@langchain/openai"),q=require("zod");var ie=require("@langchain/core/utils/env"),se=require("@langchain/core/embeddings"),re=require("@langchain/core/utils/chunk_array");var Y=class extends se.Embeddings{constructor(n){var r,o,a,c,i;super(C({},n));g(this,"apiKey");g(this,"headers",{"Content-Type":"application/json"});g(this,"batchSize");g(this,"endpoint");g(this,"inputType");g(this,"model");g(this,"outputDimension");g(this,"outputDtype");g(this,"truncation");if(this.apiKey=(n==null?void 0:n.apiKey)||(0,ie.getEnvironmentVariable)("VOYAGEAI_API_KEY"),this.batchSize=(r=n==null?void 0:n.batchSize)!=null?r:8,this.endpoint=(o=n==null?void 0:n.end