@browserbasehq/stagehand 3.0.7-alpha-a890f16fa3a752f308f858e5ab9c9a0faf6b3b34 → 3.0.7-alpha-4d71162beb119635b69b17637564a2bbd0e373e7
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.
- package/dist/index.d.ts +329 -3
- package/dist/index.js +1276 -553
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -179,7 +179,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
179
179
|
var STAGEHAND_VERSION;
|
|
180
180
|
var init_version = __esm({
|
|
181
181
|
"lib/version.ts"() {
|
|
182
|
-
STAGEHAND_VERSION = "3.0.7-alpha-
|
|
182
|
+
STAGEHAND_VERSION = "3.0.7-alpha-4d71162beb119635b69b17637564a2bbd0e373e7";
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
185
|
|
|
@@ -638,6 +638,106 @@ var init_executionContextRegistry = __esm({
|
|
|
638
638
|
}
|
|
639
639
|
});
|
|
640
640
|
|
|
641
|
+
// lib/v3/dom/build/a11yScripts.generated.ts
|
|
642
|
+
var a11yScriptBootstrap, a11yScriptSources, a11yScriptGlobalRefs;
|
|
643
|
+
var init_a11yScripts_generated = __esm({
|
|
644
|
+
"lib/v3/dom/build/a11yScripts.generated.ts"() {
|
|
645
|
+
a11yScriptBootstrap = 'if (!globalThis.__stagehandA11yScripts) { var __stagehandA11yScriptsFactory=(()=>{var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var N=(o,t)=>{for(var n in t)i(o,n,{get:t[n],enumerable:!0})},h=(o,t,n,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of f(t))!p.call(o,u)&&u!==n&&i(o,u,{get:()=>t[u],enumerable:!(d=a(t,u))||d.enumerable});return o};var E=o=>h(i({},"__esModule",{value:!0}),o);var b={};N(b,{documentHasFocusStrict:()=>g,getBoundingRectLite:()=>w,getScrollOffsets:()=>y,nodeToAbsoluteXPath:()=>$,resolveDeepActiveElement:()=>T});function y(){try{let o=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,t=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(o)||0,sy:Number(t)||0}}catch{return{sx:0,sy:0}}}function w(){try{let o=this.getBoundingClientRect();return{left:Number(o?.left??0)||0,top:Number(o?.top??0)||0}}catch{return{left:0,top:0}}}function T(){try{return(t=>{let n=t.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}function $(){return(t=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let l=1,m=`${e.nodeType}:${(e.nodeName||"").toLowerCase()}`;for(let c=e.previousSibling;c;c=c.previousSibling)`${c.nodeType}:${(c.nodeName||"").toLowerCase()}`===m&&(l+=1);return l},d=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return"";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return"//";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let l=(e.nodeName||"").toLowerCase();return`${l.includes(":")?`*[name()=\'${l}\']`:l}[${n(e)}]`},u=[],s=t;for(;s;){if(s.nodeType===Node.DOCUMENT_FRAGMENT_NODE){u.push("//"),s=s.host??null;continue}let e=d(s);e&&u.push(e),s=s.parentNode}u.reverse();let r="";for(let e of u)e==="//"?r=r?r.endsWith("/")?`${r}/`:`${r}//`:"//":r=r?r.endsWith("/")?`${r}${e}`:`${r}/${e}`:`/${e}`;return r||"/"}catch{return"/"}})(this)}function g(){try{return document.hasFocus()===!0}catch{return!1}}return E(b);})();\n globalThis.__stagehandA11yScripts = __stagehandA11yScriptsFactory;\n}';
|
|
646
|
+
a11yScriptSources = {
|
|
647
|
+
"documentHasFocusStrict": "function h(){try{return document.hasFocus()===!0}catch{return!1}}",
|
|
648
|
+
"getBoundingRectLite": "function f(){try{let r=this.getBoundingClientRect();return{left:Number(r?.left??0)||0,top:Number(r?.top??0)||0}}catch{return{left:0,top:0}}}",
|
|
649
|
+
"getScrollOffsets": "function a(){try{let r=window.scrollX??window.pageXOffset??document.documentElement?.scrollLeft??0,s=window.scrollY??window.pageYOffset??document.documentElement?.scrollTop??0;return{sx:Number(r)||0,sy:Number(s)||0}}catch{return{sx:0,sy:0}}}",
|
|
650
|
+
"nodeToAbsoluteXPath": 'function N(){return(s=>{try{let n=e=>{if(!e||!e.parentNode)return 1;let u=1,d=`${e.nodeType}:${(e.nodeName||"").toLowerCase()}`;for(let l=e.previousSibling;l;l=l.previousSibling)`${l.nodeType}:${(l.nodeName||"").toLowerCase()}`===d&&(u+=1);return u},i=e=>{if(!e||e.nodeType===Node.DOCUMENT_NODE)return"";if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return"//";if(e.nodeType===Node.TEXT_NODE)return`text()[${n(e)}]`;if(e.nodeType===Node.COMMENT_NODE)return`comment()[${n(e)}]`;let u=(e.nodeName||"").toLowerCase();return`${u.includes(":")?`*[name()=\'${u}\']`:u}[${n(e)}]`},c=[],o=s;for(;o;){if(o.nodeType===Node.DOCUMENT_FRAGMENT_NODE){c.push("//"),o=o.host??null;continue}let e=i(o);e&&c.push(e),o=o.parentNode}c.reverse();let t="";for(let e of c)e==="//"?t=t?t.endsWith("/")?`${t}/`:`${t}//`:"//":t=t?t.endsWith("/")?`${t}${e}`:`${t}/${e}`:`/${e}`;return t||"/"}catch{return"/"}})(this)}',
|
|
651
|
+
"resolveDeepActiveElement": "function p(){try{return(s=>{let n=s.activeElement??null;for(;n&&n.shadowRoot&&n.shadowRoot.activeElement;)n=n.shadowRoot.activeElement;return n??null})(document)}catch{return null}}"
|
|
652
|
+
};
|
|
653
|
+
a11yScriptGlobalRefs = {
|
|
654
|
+
"documentHasFocusStrict": "globalThis.__stagehandA11yScripts.documentHasFocusStrict",
|
|
655
|
+
"getBoundingRectLite": "globalThis.__stagehandA11yScripts.getBoundingRectLite",
|
|
656
|
+
"getScrollOffsets": "globalThis.__stagehandA11yScripts.getScrollOffsets",
|
|
657
|
+
"nodeToAbsoluteXPath": "globalThis.__stagehandA11yScripts.nodeToAbsoluteXPath",
|
|
658
|
+
"resolveDeepActiveElement": "globalThis.__stagehandA11yScripts.resolveDeepActiveElement"
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
// lib/v3/understudy/a11yInvocation.ts
|
|
664
|
+
function buildA11yInvocation(name, args) {
|
|
665
|
+
const invocation = `${a11yScriptGlobalRefs[name]}(${args.join(", ")})`;
|
|
666
|
+
return `(() => { ${a11yScriptBootstrap}; return ${invocation}; })()`;
|
|
667
|
+
}
|
|
668
|
+
var init_a11yInvocation = __esm({
|
|
669
|
+
"lib/v3/understudy/a11yInvocation.ts"() {
|
|
670
|
+
init_a11yScripts_generated();
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
// lib/v3/dom/build/locatorScripts.generated.ts
|
|
675
|
+
var locatorScriptBootstrap, locatorScriptSources, locatorScriptGlobalRefs;
|
|
676
|
+
var init_locatorScripts_generated = __esm({
|
|
677
|
+
"lib/v3/dom/build/locatorScripts.generated.ts"() {
|
|
678
|
+
locatorScriptBootstrap = 'if (!globalThis.__stagehandLocatorScripts) { var __stagehandLocatorScriptsFactory=(()=>{var L=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var c in e)L(t,c,{get:e[c],enumerable:!0})},A=(t,e,c,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!H.call(t,o)&&o!==c&&L(t,o,{get:()=>e[o],enumerable:!(n=R(e,o))||n.enumerable});return t};var _=t=>A(L({},"__esModule",{value:!0}),t);var oe={};D(oe,{assignFilePayloadsToInputElement:()=>F,countCssMatchesPierce:()=>ee,countCssMatchesPrimary:()=>Z,countTextMatches:()=>te,countXPathMatchesMainWorld:()=>ne,dispatchDomClick:()=>W,ensureFileInputElement:()=>I,fillElementValue:()=>O,focusElement:()=>V,isElementChecked:()=>B,isElementVisible:()=>Y,prepareElementForTyping:()=>T,readElementInnerHTML:()=>U,readElementInnerText:()=>j,readElementInputValue:()=>$,readElementTextContent:()=>z,resolveCssSelector:()=>K,resolveCssSelectorPierce:()=>G,resolveTextSelector:()=>J,resolveXPathMainWorld:()=>Q,scrollElementToPercent:()=>q,selectElementOptions:()=>X});function I(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}function F(t){try{let e=this;if(!e||e.tagName?.toLowerCase()!=="input"||(e.type??"").toLowerCase()!=="file")return!1;let c=(()=>{try{return new DataTransfer}catch{return null}})();if(!c)return!1;let n=Array.isArray(t)?t:[];for(let o of n){if(!o)continue;let y=o.name||"upload.bin",u=o.mimeType||"application/octet-stream",a=typeof o.lastModified=="number"?o.lastModified:Date.now(),l=window.atob(o.base64??""),i=new Uint8Array(l.length);for(let s=0;s<l.length;s+=1)i[s]=l.charCodeAt(s);let f=new Blob([i],{type:u}),h=new File([f],y,{type:u,lastModified:a});c.items.add(h)}return e.files=c.files,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),!0}catch{return!1}}function W(t){let e=t??{};try{let c=new MouseEvent("click",{bubbles:!!e.bubbles,cancelable:!!e.cancelable,composed:!!e.composed,detail:typeof e.detail=="number"?e.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(c)}catch{try{this.click()}catch{}}}function q(t){let e=c=>{if(typeof c=="number"&&Number.isFinite(c))return c;let n=String(c??"").trim();if(!n)return 0;let o=parseFloat(n.replace("%",""));return Number.isNaN(o)||!Number.isFinite(o)?0:o};try{let c=Math.max(0,Math.min(e(t),100)),n=this,o=n.tagName?.toLowerCase()??"";if(o==="html"||o==="body"){let h=(n.ownerDocument?.scrollingElement||n.ownerDocument?.documentElement||n.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,s=n.ownerDocument?.defaultView?.innerHeight??window.innerHeight,g=Math.max(0,h-s)*(c/100);return n.ownerDocument?.defaultView?.scrollTo({top:g,left:n.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:"smooth"}),!0}let u=n.scrollHeight??0,a=n.clientHeight??0,i=Math.max(0,u-a)*(c/100);return n.scrollTo({top:i,left:n.scrollLeft??0,behavior:"smooth"}),!0}catch{return!1}}var v=new Set(["color","date","datetime-local","month","range","time","week"]),P=new Set(["","email","number","password","search","tel","text","url"]);function T(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument||document,c=e.defaultView||window;try{typeof t.focus=="function"&&t.focus()}catch{}if(t instanceof c.HTMLInputElement||t instanceof c.HTMLTextAreaElement){try{if(typeof t.select=="function")return t.select(),!0}catch{}try{let n=(t.value??"").length;if(typeof t.setSelectionRange=="function")return t.setSelectionRange(0,n),!0}catch{}return!0}if(t.isContentEditable){let n=e.getSelection?.(),o=e.createRange?.();if(n&&o)try{o.selectNodeContents(t),n.removeAllRanges(),n.addRange(o)}catch{}return!0}return!1}catch{return!1}}function O(t){let e=this;if(!e.isConnected)return{status:"error",reason:"notconnected"};let n=(e.ownerDocument||document).defaultView||window,o=t??"";try{let y=u=>{let a;if(typeof n.InputEvent=="function")try{a=new n.InputEvent("input",{bubbles:!0,composed:!0,data:u,inputType:"insertText"})}catch{a=new n.Event("input",{bubbles:!0,composed:!0})}else a=new n.Event("input",{bubbles:!0,composed:!0});e.dispatchEvent(a);let l=new n.Event("change",{bubbles:!0});e.dispatchEvent(l)};if(e instanceof n.HTMLInputElement){let u=(e.type||"").toLowerCase();if(!P.has(u)&&!v.has(u))return{status:"error",reason:`unsupported-input-type:${u}`};let a=t;if(u==="number"){let l=t.trim();if(l!==""&&Number.isNaN(Number(l)))return{status:"error",reason:"invalid-number-value"};a=l}if(o=a,v.has(u)){let l=t.trim();o=l,T.call(e);let i=n.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(i,"value")?.set;return typeof h=="function"?h.call(e,l):e.value=l,e._valueTracker?.setValue?.(l),e.value!==l?{status:"error",reason:"malformed-value"}:(y(l),{status:"done"})}return T.call(e),{status:"needsinput",value:a}}return e instanceof n.HTMLTextAreaElement?(T.call(e),o=t,{status:"needsinput",value:t}):e instanceof n.HTMLSelectElement?{status:"error",reason:"unsupported-element"}:e.isContentEditable?(T.call(e),o=t,{status:"needsinput",value:t}):{status:"error",reason:"unsupported-element"}}catch(y){let u="exception";if(y&&typeof y=="object"){let a=y.message;typeof a=="string"&&a.trim().length>0&&(u=`exception:${a}`)}return{status:"needsinput",value:o,reason:u}}}function V(){try{typeof this.focus=="function"&&this.focus()}catch{}}function X(t){try{if(!(this instanceof HTMLSelectElement))return[];let e=Array.isArray(t)?t:[t],c=new Set(e.map(u=>String(u??"").trim())),n=u=>{let a=(u.label||u.textContent||"").trim(),l=String(u.value??"").trim();return c.has(a)||c.has(l)};if(this.multiple)for(let u of Array.from(this.options))u.selected=n(u);else{let u=!1;for(let a of Array.from(this.options))!u&&n(a)?(a.selected=!0,this.value=a.value,u=!0):a.selected=!1}let o=new Event("input",{bubbles:!0}),y=new Event("change",{bubbles:!0});return this.dispatchEvent(o),this.dispatchEvent(y),Array.from(this.selectedOptions).map(u=>u.value)}catch{return[]}}function Y(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument?.defaultView?.getComputedStyle(t)??window.getComputedStyle(t);if(!e||e.display==="none"||e.visibility==="hidden")return!1;let c=parseFloat(e.opacity??"1");if(!Number.isFinite(c)||c===0)return!1;let n=t.getBoundingClientRect();return!(!n||Math.max(n.width,n.height)===0||t.getClientRects().length===0)}catch{return!1}}function B(){try{let t=this;if((t.tagName||"").toLowerCase()==="input"){let n=t.type?.toLowerCase()??"";if(n==="checkbox"||n==="radio")return!!t.checked}let c=t.getAttribute?.("aria-checked");return c!=null?c==="true":!1}catch{return!1}}function $(){try{let t=this,e=(t.tagName||"").toLowerCase();return e==="input"||e==="textarea"||e==="select"?String(t.value??""):t.isContentEditable?String(t.textContent??""):""}catch{return""}}function z(){try{return String(this.textContent??"")}catch{return""}}function U(){try{return String(this.innerHTML??"")}catch{return""}}function j(){try{let t=this,e=t.innerText;if(typeof e=="string"&&e.length>0)return e;let c=t.textContent;return typeof c=="string"?c:""}catch{return""}}var N=t=>{let e=Number(t??0);return!Number.isFinite(e)||e<0?0:Math.floor(e)},M=(t,e)=>{if(!t)return[];let c=new WeakSet,n=new Set,o=[],y=[document],u=a=>{if(!(!a||c.has(a)||o.length>=e)){c.add(a);try{let l=a.querySelectorAll(t);for(let i of l)if(!n.has(i)&&(n.add(i),o.push(i),o.length>=e))return}catch{}try{let i=(a instanceof Document?a:a.host?.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),f;for(;f=i.nextNode();){if(!(f instanceof Element))continue;let h=f.shadowRoot;h&&y.push(h)}}catch{}}};for(;y.length&&o.length<e;){let a=y.shift();a&&u(a)}return o};function K(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e);return M(c,n+1)[n]??null}function G(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e),o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!="function")return M(c,n+1)[n]??null;let y=h=>{try{return o.getClosedRoot(h)??null}catch{return null}},u=new WeakSet,a=new Set,l=[],i=[document],f=h=>{if(!(!h||u.has(h)||l.length>=n+1)){u.add(h);try{let s=h.querySelectorAll(c);for(let d of s)if(!a.has(d)&&(a.add(d),l.push(d),l.length>=n+1))return}catch{}try{let d=(h instanceof Document?h:h.host?.ownerDocument??document).createTreeWalker(h,NodeFilter.SHOW_ELEMENT),g;for(;g=d.nextNode();){if(!(g instanceof Element))continue;let w=g.shadowRoot;w&&i.push(w);let E=y(g);E&&i.push(E)}}catch{}}};for(;i.length&&l.length<n+1;){let h=i.shift();h&&f(h)}return l[n]??null}function J(t,e){let c=String(t??"");if(!c)return null;let n=c.toLowerCase(),o=N(e),y=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),u=r=>{if(!r)return!1;let p=r.tagName?.toUpperCase()??"";return y.has(p)},a=r=>{try{if(u(r))return"";let p=r.innerText;if(typeof p=="string"&&p.trim())return p.trim()}catch{}try{let p=r.textContent;if(typeof p=="string")return p.trim()}catch{}return""},l=r=>{let p=a(r);return!!p&&p.toLowerCase().includes(n)},i=window.__stagehandV3__,f=i&&typeof i.getClosedRoot=="function"?r=>{try{return i.getClosedRoot(r)??null}catch{return null}}:r=>null,h=new WeakSet,s=[],d=[],g=r=>{!r||h.has(r)||(h.add(r),s.push(r))},w=r=>{try{return(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(g(document);s.length;){let r=s.shift();if(!r)continue;r instanceof Element&&l(r)&&d.push({element:r,tag:r.tagName??"",id:r.id??"",className:r.className??"",text:a(r)});let p=w(r);if(!p)continue;let x;for(;x=p.nextNode();){if(!(x instanceof Element))continue;l(x)&&d.push({element:x,tag:x.tagName??"",id:x.id??"",className:x.className??"",text:a(x)});let b=x.shadowRoot;b&&g(b);let S=f(x);S&&g(S)}}let E=[];for(let r of d){let p=r.element,x=!1;for(let b of d)if(r!==b)try{if(p.contains(b.element)){x=!0;break}}catch{}x||E.push(r)}return E[o]?.element??null}function Q(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e),o=window.__stagehandV3__;if(n===0){try{if(o&&typeof o.resolveSimpleXPath=="function"){let s=o.resolveSimpleXPath(c);if(s)return s}}catch{}try{return document.evaluate(c,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch{}}let u=(s=>{let d=String(s||"").trim();if(!d)return[];let g=d.replace(/^xpath=/i,""),w=[],E=0;for(;E<g.length;){let m="child";g.startsWith("//",E)?(m="desc",E+=2):g[E]==="/"&&(m="child",E+=1);let r=E;for(;E<g.length&&g[E]!=="/";)E+=1;let p=g.slice(r,E).trim();if(!p)continue;let x=p.match(/^(.*?)(\\[(\\d+)\\])?$/u),b=(x?.[1]??p).trim(),S=x?.[3]?Math.max(1,Number(x[3])):null,C=b===""?"*":b.toLowerCase();w.push({axis:m,tag:C,index:S})}return w})(c);if(!u.length)return null;let a=o&&typeof o.getClosedRoot=="function"?s=>{try{return o.getClosedRoot(s)??null}catch{return null}}:s=>null,l=s=>{let d=[];if(!s)return d;if(s instanceof Document)return s.documentElement&&d.push(s.documentElement),d;if(s instanceof ShadowRoot||s instanceof DocumentFragment)return d.push(...Array.from(s.children??[])),d;if(s instanceof Element){d.push(...Array.from(s.children??[]));let g=s.shadowRoot;g&&d.push(...Array.from(g.children??[]));let w=a(s);return w&&d.push(...Array.from(w.children??[])),d}return d},i=s=>{let d=[],g=new Set,w=[...l(s)];for(;w.length;){let E=w.shift();!E||g.has(E)||(g.add(E),d.push(E),w.push(...l(E)))}return d},f=[document];for(let s of u){let d=[],g=new Set;for(let w of f){if(!w)continue;let E=s.axis==="child"?l(w):i(w);if(!E.length)continue;let m=E.filter(r=>r instanceof Element?s.tag==="*"?!0:r.localName===s.tag:!1);if(s.index!=null){let r=s.index-1,p=r>=0&&r<m.length?m[r]:null;p&&!g.has(p)&&(g.add(p),d.push(p))}else for(let r of m)g.has(r)||(g.add(r),d.push(r))}if(!d.length)return null;f=d}return f[n]??null}function Z(t){let e=String(t??"").trim();if(!e)return 0;let c=new WeakSet,n=o=>{if(!o||c.has(o))return 0;c.add(o);let y=0;try{let u=o;typeof u.querySelectorAll=="function"&&(y+=u.querySelectorAll(e).length)}catch{}try{let a=(o instanceof Document?o:o?.ownerDocument??document).createTreeWalker(o,NodeFilter.SHOW_ELEMENT),l;for(;l=a.nextNode();)l instanceof Element&&l.shadowRoot&&(y+=n(l.shadowRoot))}catch{}return y};try{return n(document)}catch{try{return document.querySelectorAll(e).length}catch{return 0}}}function ee(t){let e=String(t??"").trim();if(!e)return 0;let c=window.__stagehandV3__;if(!c||typeof c.getClosedRoot!="function")try{return document.querySelectorAll(e).length}catch{return 0}let n=new WeakSet,o=[],y=l=>{!l||n.has(l)||(n.add(l),o.push(l))};y(document);let u=0,a=l=>{let i=l.shadowRoot;i&&y(i);try{let f=c.getClosedRoot(l);f&&y(f)}catch{}};for(;o.length;){let l=o.shift();if(l){try{let i=l;typeof i.querySelectorAll=="function"&&(u+=i.querySelectorAll(e).length)}catch{}try{let f=(l instanceof Document?l:l instanceof ShadowRoot?l.host?.ownerDocument??document:l.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),h;for(;h=f.nextNode();)h instanceof Element&&a(h)}catch{}}}return u}function te(t){let e=String(t??"");if(!e)return{count:0,sample:[],error:null};let c=e.toLowerCase(),n=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),o=m=>{if(!m)return!1;let r=m.tagName?.toUpperCase()??"";return n.has(r)},y=m=>{try{if(o(m))return"";let r=m.innerText;if(typeof r=="string"&&r.trim())return r.trim()}catch{}try{let r=m.textContent;if(typeof r=="string")return r.trim()}catch{}return""},u=m=>{let r=y(m);return!!r&&r.toLowerCase().includes(c)},a=window.__stagehandV3__,l=a&&typeof a.getClosedRoot=="function"?m=>{try{return a.getClosedRoot(m)??null}catch{return null}}:m=>null,i=new WeakSet,f=[],h=m=>{!m||i.has(m)||(i.add(m),f.push(m))},s=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},d=[];for(h(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&u(m)&&d.push({element:m,tag:m.tagName??"",id:m.id??"",className:m.className??"",text:y(m)});let r=s(m);if(!r)continue;let p;for(;p=r.nextNode();){if(!(p instanceof Element))continue;u(p)&&d.push({element:p,tag:p.tagName??"",id:p.id??"",className:p.className??"",text:y(p)});let x=p.shadowRoot;x&&h(x);let b=l(p);b&&h(b)}}let g=[];for(let m of d){let r=m.element,p=!1;for(let x of d)if(m!==x)try{if(r.contains(x.element)){p=!0;break}}catch{}p||g.push(m)}let w=g.length,E=g.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:w,sample:E,error:null}}function ne(t){let e=String(t??"").trim();if(!e)return 0;let n=(i=>{let f=String(i||"").trim().replace(/^xpath=/i,"");if(!f)return[];let h=[],s=0;for(;s<f.length;){let d="child";f.startsWith("//",s)?(d="desc",s+=2):f[s]==="/"&&(d="child",s+=1);let g=s;for(;s<f.length&&f[s]!=="/";)s+=1;let w=f.slice(g,s).trim();if(!w)continue;let E=w.match(/^(.*?)(\\[(\\d+)\\])?$/u),m=(E?.[1]??w).trim(),r=E?.[3]?Math.max(1,Number(E[3])):null,p=m===""?"*":m.toLowerCase();h.push({axis:d,tag:p,index:r})}return h})(e);if(!n.length)return 0;let o=window.__stagehandV3__,y=o&&typeof o.getClosedRoot=="function"?i=>{try{return o.getClosedRoot(i)??null}catch{return null}}:i=>null,u=i=>{let f=[];if(!i)return f;if(i instanceof Document)return i.documentElement&&f.push(i.documentElement),f;if(i instanceof ShadowRoot||i instanceof DocumentFragment)return f.push(...Array.from(i.children??[])),f;if(i instanceof Element){f.push(...Array.from(i.children??[]));let h=i.shadowRoot;h&&f.push(...Array.from(h.children??[]));let s=y(i);return s&&f.push(...Array.from(s.children??[])),f}return f},a=i=>{let f=[],h=new Set,s=[...u(i)];for(;s.length;){let d=s.shift();!d||h.has(d)||(h.add(d),f.push(d),s.push(...u(d)))}return f},l=[document];for(let i of n){let f=[],h=new Set;for(let s of l){if(!s)continue;let d=i.axis==="child"?u(s):a(s);if(!d.length)continue;let g=d.filter(w=>w instanceof Element?i.tag==="*"?!0:w.localName===i.tag:!1);if(i.index!=null){let w=i.index-1,E=w>=0&&w<g.length?g[w]:null;E&&!h.has(E)&&(h.add(E),f.push(E))}else for(let w of g)h.has(w)||(h.add(w),f.push(w))}if(!f.length)return 0;l=f}return l.length}return _(oe);})();\n globalThis.__stagehandLocatorScripts = __stagehandLocatorScriptsFactory;\n}';
|
|
679
|
+
locatorScriptSources = {
|
|
680
|
+
"assignFilePayloadsToInputElement": 'function k(t){try{let e=this;if(!e||e.tagName?.toLowerCase()!=="input"||(e.type??"").toLowerCase()!=="file")return!1;let i=(()=>{try{return new DataTransfer}catch{return null}})();if(!i)return!1;let n=Array.isArray(t)?t:[];for(let s of n){if(!s)continue;let y=s.name||"upload.bin",u=s.mimeType||"application/octet-stream",a=typeof s.lastModified=="number"?s.lastModified:Date.now(),l=window.atob(s.base64??""),c=new Uint8Array(l.length);for(let r=0;r<l.length;r+=1)c[r]=l.charCodeAt(r);let f=new Blob([c],{type:u}),h=new File([f],y,{type:u,lastModified:a});i.items.add(h)}return e.files=i.files,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),!0}catch{return!1}}',
|
|
681
|
+
"countCssMatchesPierce": 'function K(t){let e=String(t??"").trim();if(!e)return 0;let i=window.__stagehandV3__;if(!i||typeof i.getClosedRoot!="function")try{return document.querySelectorAll(e).length}catch{return 0}let n=new WeakSet,s=[],y=l=>{!l||n.has(l)||(n.add(l),s.push(l))};y(document);let u=0,a=l=>{let c=l.shadowRoot;c&&y(c);try{let f=i.getClosedRoot(l);f&&y(f)}catch{}};for(;s.length;){let l=s.shift();if(l){try{let c=l;typeof c.querySelectorAll=="function"&&(u+=c.querySelectorAll(e).length)}catch{}try{let f=(l instanceof Document?l:l instanceof ShadowRoot?l.host?.ownerDocument??document:l.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),h;for(;h=f.nextNode();)h instanceof Element&&a(h)}catch{}}}return u}',
|
|
682
|
+
"countCssMatchesPrimary": 'function j(t){let e=String(t??"").trim();if(!e)return 0;let i=new WeakSet,n=s=>{if(!s||i.has(s))return 0;i.add(s);let y=0;try{let u=s;typeof u.querySelectorAll=="function"&&(y+=u.querySelectorAll(e).length)}catch{}try{let a=(s instanceof Document?s:s?.ownerDocument??document).createTreeWalker(s,NodeFilter.SHOW_ELEMENT),l;for(;l=a.nextNode();)l instanceof Element&&l.shadowRoot&&(y+=n(l.shadowRoot))}catch{}return y};try{return n(document)}catch{try{return document.querySelectorAll(e).length}catch{return 0}}}',
|
|
683
|
+
"countTextMatches": 'function G(t){let e=String(t??"");if(!e)return{count:0,sample:[],error:null};let i=e.toLowerCase(),n=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),s=m=>{if(!m)return!1;let o=m.tagName?.toUpperCase()??"";return n.has(o)},y=m=>{try{if(s(m))return"";let o=m.innerText;if(typeof o=="string"&&o.trim())return o.trim()}catch{}try{let o=m.textContent;if(typeof o=="string")return o.trim()}catch{}return""},u=m=>{let o=y(m);return!!o&&o.toLowerCase().includes(i)},a=window.__stagehandV3__,l=a&&typeof a.getClosedRoot=="function"?m=>{try{return a.getClosedRoot(m)??null}catch{return null}}:m=>null,c=new WeakSet,f=[],h=m=>{!m||c.has(m)||(c.add(m),f.push(m))},r=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},d=[];for(h(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&u(m)&&d.push({element:m,tag:m.tagName??"",id:m.id??"",className:m.className??"",text:y(m)});let o=r(m);if(!o)continue;let p;for(;p=o.nextNode();){if(!(p instanceof Element))continue;u(p)&&d.push({element:p,tag:p.tagName??"",id:p.id??"",className:p.className??"",text:y(p)});let x=p.shadowRoot;x&&h(x);let b=l(p);b&&h(b)}}let g=[];for(let m of d){let o=m.element,p=!1;for(let x of d)if(m!==x)try{if(o.contains(x.element)){p=!0;break}}catch{}p||g.push(m)}let w=g.length,E=g.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:w,sample:E,error:null}}',
|
|
684
|
+
"countXPathMatchesMainWorld": 'function J(t){let e=String(t??"").trim();if(!e)return 0;let n=(c=>{let f=String(c||"").trim().replace(/^xpath=/i,"");if(!f)return[];let h=[],r=0;for(;r<f.length;){let d="child";f.startsWith("//",r)?(d="desc",r+=2):f[r]==="/"&&(d="child",r+=1);let g=r;for(;r<f.length&&f[r]!=="/";)r+=1;let w=f.slice(g,r).trim();if(!w)continue;let E=w.match(/^(.*?)(\\[(\\d+)\\])?$/u),m=(E?.[1]??w).trim(),o=E?.[3]?Math.max(1,Number(E[3])):null,p=m===""?"*":m.toLowerCase();h.push({axis:d,tag:p,index:o})}return h})(e);if(!n.length)return 0;let s=window.__stagehandV3__,y=s&&typeof s.getClosedRoot=="function"?c=>{try{return s.getClosedRoot(c)??null}catch{return null}}:c=>null,u=c=>{let f=[];if(!c)return f;if(c instanceof Document)return c.documentElement&&f.push(c.documentElement),f;if(c instanceof ShadowRoot||c instanceof DocumentFragment)return f.push(...Array.from(c.children??[])),f;if(c instanceof Element){f.push(...Array.from(c.children??[]));let h=c.shadowRoot;h&&f.push(...Array.from(h.children??[]));let r=y(c);return r&&f.push(...Array.from(r.children??[])),f}return f},a=c=>{let f=[],h=new Set,r=[...u(c)];for(;r.length;){let d=r.shift();!d||h.has(d)||(h.add(d),f.push(d),r.push(...u(d)))}return f},l=[document];for(let c of n){let f=[],h=new Set;for(let r of l){if(!r)continue;let d=c.axis==="child"?u(r):a(r);if(!d.length)continue;let g=d.filter(w=>w instanceof Element?c.tag==="*"?!0:w.localName===c.tag:!1);if(c.index!=null){let w=c.index-1,E=w>=0&&w<g.length?g[w]:null;E&&!h.has(E)&&(h.add(E),f.push(E))}else for(let w of g)h.has(w)||(h.add(w),f.push(w))}if(!f.length)return 0;l=f}return l.length}',
|
|
685
|
+
"dispatchDomClick": 'function H(t){let e=t??{};try{let i=new MouseEvent("click",{bubbles:!!e.bubbles,cancelable:!!e.cancelable,composed:!!e.composed,detail:typeof e.detail=="number"?e.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(i)}catch{try{this.click()}catch{}}}',
|
|
686
|
+
"ensureFileInputElement": 'function R(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}',
|
|
687
|
+
"fillElementValue": 'function A(t){let e=this;if(!e.isConnected)return{status:"error",reason:"notconnected"};let n=(e.ownerDocument||document).defaultView||window,s=t??"";try{let y=u=>{let a;if(typeof n.InputEvent=="function")try{a=new n.InputEvent("input",{bubbles:!0,composed:!0,data:u,inputType:"insertText"})}catch{a=new n.Event("input",{bubbles:!0,composed:!0})}else a=new n.Event("input",{bubbles:!0,composed:!0});e.dispatchEvent(a);let l=new n.Event("change",{bubbles:!0});e.dispatchEvent(l)};if(e instanceof n.HTMLInputElement){let u=(e.type||"").toLowerCase();if(!C.has(u)&&!L.has(u))return{status:"error",reason:`unsupported-input-type:${u}`};let a=t;if(u==="number"){let l=t.trim();if(l!==""&&Number.isNaN(Number(l)))return{status:"error",reason:"invalid-number-value"};a=l}if(s=a,L.has(u)){let l=t.trim();s=l,S.call(e);let c=n.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(c,"value")?.set;return typeof h=="function"?h.call(e,l):e.value=l,e._valueTracker?.setValue?.(l),e.value!==l?{status:"error",reason:"malformed-value"}:(y(l),{status:"done"})}return S.call(e),{status:"needsinput",value:a}}return e instanceof n.HTMLTextAreaElement?(S.call(e),s=t,{status:"needsinput",value:t}):e instanceof n.HTMLSelectElement?{status:"error",reason:"unsupported-element"}:e.isContentEditable?(S.call(e),s=t,{status:"needsinput",value:t}):{status:"error",reason:"unsupported-element"}}catch(y){let u="exception";if(y&&typeof y=="object"){let a=y.message;typeof a=="string"&&a.trim().length>0&&(u=`exception:${a}`)}return{status:"needsinput",value:s,reason:u}}}',
|
|
688
|
+
"focusElement": 'function _(){try{typeof this.focus=="function"&&this.focus()}catch{}}',
|
|
689
|
+
"isElementChecked": 'function W(){try{let t=this;if((t.tagName||"").toLowerCase()==="input"){let n=t.type?.toLowerCase()??"";if(n==="checkbox"||n==="radio")return!!t.checked}let i=t.getAttribute?.("aria-checked");return i!=null?i==="true":!1}catch{return!1}}',
|
|
690
|
+
"isElementVisible": 'function F(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument?.defaultView?.getComputedStyle(t)??window.getComputedStyle(t);if(!e||e.display==="none"||e.visibility==="hidden")return!1;let i=parseFloat(e.opacity??"1");if(!Number.isFinite(i)||i===0)return!1;let n=t.getBoundingClientRect();return!(!n||Math.max(n.width,n.height)===0||t.getClientRects().length===0)}catch{return!1}}',
|
|
691
|
+
"prepareElementForTyping": 'function S(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument||document,i=e.defaultView||window;try{typeof t.focus=="function"&&t.focus()}catch{}if(t instanceof i.HTMLInputElement||t instanceof i.HTMLTextAreaElement){try{if(typeof t.select=="function")return t.select(),!0}catch{}try{let n=(t.value??"").length;if(typeof t.setSelectionRange=="function")return t.setSelectionRange(0,n),!0}catch{}return!0}if(t.isContentEditable){let n=e.getSelection?.(),s=e.createRange?.();if(n&&s)try{s.selectNodeContents(t),n.removeAllRanges(),n.addRange(s)}catch{}return!0}return!1}catch{return!1}}',
|
|
692
|
+
"readElementInnerHTML": 'function O(){try{return String(this.innerHTML??"")}catch{return""}}',
|
|
693
|
+
"readElementInnerText": 'function V(){try{let t=this,e=t.innerText;if(typeof e=="string"&&e.length>0)return e;let i=t.textContent;return typeof i=="string"?i:""}catch{return""}}',
|
|
694
|
+
"readElementInputValue": 'function q(){try{let t=this,e=(t.tagName||"").toLowerCase();return e==="input"||e==="textarea"||e==="select"?String(t.value??""):t.isContentEditable?String(t.textContent??""):""}catch{return""}}',
|
|
695
|
+
"readElementTextContent": 'function P(){try{return String(this.textContent??"")}catch{return""}}',
|
|
696
|
+
"resolveCssSelector": 'function Y(t,e){let i=String(t??"").trim();if(!i)return null;let n=N(e);return v(i,n+1)[n]??null}',
|
|
697
|
+
"resolveCssSelectorPierce": 'function B(t,e){let i=String(t??"").trim();if(!i)return null;let n=N(e),s=window.__stagehandV3__;if(!s||typeof s.getClosedRoot!="function")return v(i,n+1)[n]??null;let y=h=>{try{return s.getClosedRoot(h)??null}catch{return null}},u=new WeakSet,a=new Set,l=[],c=[document],f=h=>{if(!(!h||u.has(h)||l.length>=n+1)){u.add(h);try{let r=h.querySelectorAll(i);for(let d of r)if(!a.has(d)&&(a.add(d),l.push(d),l.length>=n+1))return}catch{}try{let d=(h instanceof Document?h:h.host?.ownerDocument??document).createTreeWalker(h,NodeFilter.SHOW_ELEMENT),g;for(;g=d.nextNode();){if(!(g instanceof Element))continue;let w=g.shadowRoot;w&&c.push(w);let E=y(g);E&&c.push(E)}}catch{}}};for(;c.length&&l.length<n+1;){let h=c.shift();h&&f(h)}return l[n]??null}',
|
|
698
|
+
"resolveTextSelector": 'function $(t,e){let i=String(t??"");if(!i)return null;let n=i.toLowerCase(),s=N(e),y=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),u=o=>{if(!o)return!1;let p=o.tagName?.toUpperCase()??"";return y.has(p)},a=o=>{try{if(u(o))return"";let p=o.innerText;if(typeof p=="string"&&p.trim())return p.trim()}catch{}try{let p=o.textContent;if(typeof p=="string")return p.trim()}catch{}return""},l=o=>{let p=a(o);return!!p&&p.toLowerCase().includes(n)},c=window.__stagehandV3__,f=c&&typeof c.getClosedRoot=="function"?o=>{try{return c.getClosedRoot(o)??null}catch{return null}}:o=>null,h=new WeakSet,r=[],d=[],g=o=>{!o||h.has(o)||(h.add(o),r.push(o))},w=o=>{try{return(o instanceof Document?o:o?.ownerDocument??document).createTreeWalker(o,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(g(document);r.length;){let o=r.shift();if(!o)continue;o instanceof Element&&l(o)&&d.push({element:o,tag:o.tagName??"",id:o.id??"",className:o.className??"",text:a(o)});let p=w(o);if(!p)continue;let x;for(;x=p.nextNode();){if(!(x instanceof Element))continue;l(x)&&d.push({element:x,tag:x.tagName??"",id:x.id??"",className:x.className??"",text:a(x)});let b=x.shadowRoot;b&&g(b);let T=f(x);T&&g(T)}}let E=[];for(let o of d){let p=o.element,x=!1;for(let b of d)if(o!==b)try{if(p.contains(b.element)){x=!0;break}}catch{}x||E.push(o)}return E[s]?.element??null}',
|
|
699
|
+
"resolveXPathMainWorld": 'function z(t,e){let i=String(t??"").trim();if(!i)return null;let n=N(e),s=window.__stagehandV3__;if(n===0){try{if(s&&typeof s.resolveSimpleXPath=="function"){let r=s.resolveSimpleXPath(i);if(r)return r}}catch{}try{return document.evaluate(i,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch{}}let u=(r=>{let d=String(r||"").trim();if(!d)return[];let g=d.replace(/^xpath=/i,""),w=[],E=0;for(;E<g.length;){let m="child";g.startsWith("//",E)?(m="desc",E+=2):g[E]==="/"&&(m="child",E+=1);let o=E;for(;E<g.length&&g[E]!=="/";)E+=1;let p=g.slice(o,E).trim();if(!p)continue;let x=p.match(/^(.*?)(\\[(\\d+)\\])?$/u),b=(x?.[1]??p).trim(),T=x?.[3]?Math.max(1,Number(x[3])):null,M=b===""?"*":b.toLowerCase();w.push({axis:m,tag:M,index:T})}return w})(i);if(!u.length)return null;let a=s&&typeof s.getClosedRoot=="function"?r=>{try{return s.getClosedRoot(r)??null}catch{return null}}:r=>null,l=r=>{let d=[];if(!r)return d;if(r instanceof Document)return r.documentElement&&d.push(r.documentElement),d;if(r instanceof ShadowRoot||r instanceof DocumentFragment)return d.push(...Array.from(r.children??[])),d;if(r instanceof Element){d.push(...Array.from(r.children??[]));let g=r.shadowRoot;g&&d.push(...Array.from(g.children??[]));let w=a(r);return w&&d.push(...Array.from(w.children??[])),d}return d},c=r=>{let d=[],g=new Set,w=[...l(r)];for(;w.length;){let E=w.shift();!E||g.has(E)||(g.add(E),d.push(E),w.push(...l(E)))}return d},f=[document];for(let r of u){let d=[],g=new Set;for(let w of f){if(!w)continue;let E=r.axis==="child"?l(w):c(w);if(!E.length)continue;let m=E.filter(o=>o instanceof Element?r.tag==="*"?!0:o.localName===r.tag:!1);if(r.index!=null){let o=r.index-1,p=o>=0&&o<m.length?m[o]:null;p&&!g.has(p)&&(g.add(p),d.push(p))}else for(let o of m)g.has(o)||(g.add(o),d.push(o))}if(!d.length)return null;f=d}return f[n]??null}',
|
|
700
|
+
"scrollElementToPercent": 'function D(t){let e=i=>{if(typeof i=="number"&&Number.isFinite(i))return i;let n=String(i??"").trim();if(!n)return 0;let s=parseFloat(n.replace("%",""));return Number.isNaN(s)||!Number.isFinite(s)?0:s};try{let i=Math.max(0,Math.min(e(t),100)),n=this,s=n.tagName?.toLowerCase()??"";if(s==="html"||s==="body"){let h=(n.ownerDocument?.scrollingElement||n.ownerDocument?.documentElement||n.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,r=n.ownerDocument?.defaultView?.innerHeight??window.innerHeight,g=Math.max(0,h-r)*(i/100);return n.ownerDocument?.defaultView?.scrollTo({top:g,left:n.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:"smooth"}),!0}let u=n.scrollHeight??0,a=n.clientHeight??0,c=Math.max(0,u-a)*(i/100);return n.scrollTo({top:c,left:n.scrollLeft??0,behavior:"smooth"}),!0}catch{return!1}}',
|
|
701
|
+
"selectElementOptions": 'function I(t){try{if(!(this instanceof HTMLSelectElement))return[];let e=Array.isArray(t)?t:[t],i=new Set(e.map(u=>String(u??"").trim())),n=u=>{let a=(u.label||u.textContent||"").trim(),l=String(u.value??"").trim();return i.has(a)||i.has(l)};if(this.multiple)for(let u of Array.from(this.options))u.selected=n(u);else{let u=!1;for(let a of Array.from(this.options))!u&&n(a)?(a.selected=!0,this.value=a.value,u=!0):a.selected=!1}let s=new Event("input",{bubbles:!0}),y=new Event("change",{bubbles:!0});return this.dispatchEvent(s),this.dispatchEvent(y),Array.from(this.selectedOptions).map(u=>u.value)}catch{return[]}}'
|
|
702
|
+
};
|
|
703
|
+
locatorScriptGlobalRefs = {
|
|
704
|
+
"assignFilePayloadsToInputElement": "globalThis.__stagehandLocatorScripts.assignFilePayloadsToInputElement",
|
|
705
|
+
"countCssMatchesPierce": "globalThis.__stagehandLocatorScripts.countCssMatchesPierce",
|
|
706
|
+
"countCssMatchesPrimary": "globalThis.__stagehandLocatorScripts.countCssMatchesPrimary",
|
|
707
|
+
"countTextMatches": "globalThis.__stagehandLocatorScripts.countTextMatches",
|
|
708
|
+
"countXPathMatchesMainWorld": "globalThis.__stagehandLocatorScripts.countXPathMatchesMainWorld",
|
|
709
|
+
"dispatchDomClick": "globalThis.__stagehandLocatorScripts.dispatchDomClick",
|
|
710
|
+
"ensureFileInputElement": "globalThis.__stagehandLocatorScripts.ensureFileInputElement",
|
|
711
|
+
"fillElementValue": "globalThis.__stagehandLocatorScripts.fillElementValue",
|
|
712
|
+
"focusElement": "globalThis.__stagehandLocatorScripts.focusElement",
|
|
713
|
+
"isElementChecked": "globalThis.__stagehandLocatorScripts.isElementChecked",
|
|
714
|
+
"isElementVisible": "globalThis.__stagehandLocatorScripts.isElementVisible",
|
|
715
|
+
"prepareElementForTyping": "globalThis.__stagehandLocatorScripts.prepareElementForTyping",
|
|
716
|
+
"readElementInnerHTML": "globalThis.__stagehandLocatorScripts.readElementInnerHTML",
|
|
717
|
+
"readElementInnerText": "globalThis.__stagehandLocatorScripts.readElementInnerText",
|
|
718
|
+
"readElementInputValue": "globalThis.__stagehandLocatorScripts.readElementInputValue",
|
|
719
|
+
"readElementTextContent": "globalThis.__stagehandLocatorScripts.readElementTextContent",
|
|
720
|
+
"resolveCssSelector": "globalThis.__stagehandLocatorScripts.resolveCssSelector",
|
|
721
|
+
"resolveCssSelectorPierce": "globalThis.__stagehandLocatorScripts.resolveCssSelectorPierce",
|
|
722
|
+
"resolveTextSelector": "globalThis.__stagehandLocatorScripts.resolveTextSelector",
|
|
723
|
+
"resolveXPathMainWorld": "globalThis.__stagehandLocatorScripts.resolveXPathMainWorld",
|
|
724
|
+
"scrollElementToPercent": "globalThis.__stagehandLocatorScripts.scrollElementToPercent",
|
|
725
|
+
"selectElementOptions": "globalThis.__stagehandLocatorScripts.selectElementOptions"
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
// lib/v3/understudy/locatorInvocation.ts
|
|
731
|
+
function buildLocatorInvocation(name, args) {
|
|
732
|
+
const invocation = `${locatorScriptGlobalRefs[name]}(${args.join(", ")})`;
|
|
733
|
+
return `(() => { ${locatorScriptBootstrap}; return ${invocation}; })()`;
|
|
734
|
+
}
|
|
735
|
+
var init_locatorInvocation = __esm({
|
|
736
|
+
"lib/v3/understudy/locatorInvocation.ts"() {
|
|
737
|
+
init_locatorScripts_generated();
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
|
|
641
741
|
// lib/v3/understudy/a11y/snapshot.ts
|
|
642
742
|
function resolveXpathForLocation(page, x2, y) {
|
|
643
743
|
return __async(this, null, function* () {
|
|
@@ -665,11 +765,12 @@ function resolveXpathForLocation(page, x2, y) {
|
|
|
665
765
|
});
|
|
666
766
|
const ctxId = yield executionContexts.waitForMainWorld(curSession, curFrameId).catch(() => {
|
|
667
767
|
});
|
|
768
|
+
const scrollExpr = buildA11yInvocation("getScrollOffsets", []);
|
|
668
769
|
const evalParams = ctxId ? {
|
|
669
770
|
contextId: ctxId,
|
|
670
|
-
expression:
|
|
771
|
+
expression: scrollExpr,
|
|
671
772
|
returnByValue: true
|
|
672
|
-
} : { expression:
|
|
773
|
+
} : { expression: scrollExpr, returnByValue: true };
|
|
673
774
|
const { result } = yield curSession.send("Runtime.evaluate", evalParams);
|
|
674
775
|
sx = Number((_b = (_a4 = result == null ? void 0 : result.value) == null ? void 0 : _a4.sx) != null ? _b : 0);
|
|
675
776
|
sy = Number((_d2 = (_c = result == null ? void 0 : result.value) == null ? void 0 : _c.sy) != null ? _d2 : 0);
|
|
@@ -731,7 +832,7 @@ function resolveXpathForLocation(page, x2, y) {
|
|
|
731
832
|
if (objectId) {
|
|
732
833
|
const { result } = yield curSession.send("Runtime.callFunctionOn", {
|
|
733
834
|
objectId,
|
|
734
|
-
functionDeclaration:
|
|
835
|
+
functionDeclaration: a11yScriptSources.getBoundingRectLite,
|
|
735
836
|
returnByValue: true
|
|
736
837
|
});
|
|
737
838
|
left = Number((_f = (_e = result == null ? void 0 : result.value) == null ? void 0 : _e.left) != null ? _f : 0);
|
|
@@ -771,11 +872,12 @@ function computeActiveElementXpath(page) {
|
|
|
771
872
|
});
|
|
772
873
|
const ctxId = yield executionContexts.waitForMainWorld(sess, fid, 1e3).catch(() => {
|
|
773
874
|
});
|
|
875
|
+
const hasFocusExpr = buildA11yInvocation("documentHasFocusStrict", []);
|
|
774
876
|
const evalParams = ctxId ? {
|
|
775
877
|
contextId: ctxId,
|
|
776
|
-
expression:
|
|
878
|
+
expression: hasFocusExpr,
|
|
777
879
|
returnByValue: true
|
|
778
|
-
} : { expression:
|
|
880
|
+
} : { expression: hasFocusExpr, returnByValue: true };
|
|
779
881
|
const { result } = yield sess.send(
|
|
780
882
|
"Runtime.evaluate",
|
|
781
883
|
evalParams
|
|
@@ -795,19 +897,12 @@ function computeActiveElementXpath(page) {
|
|
|
795
897
|
});
|
|
796
898
|
const ctxId = yield executionContexts.waitForMainWorld(focusedSession, focusedFrameId, 1e3).catch(() => {
|
|
797
899
|
});
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
return el || null;
|
|
806
|
-
}
|
|
807
|
-
return deepActive(document);
|
|
808
|
-
} catch { return null; }
|
|
809
|
-
})()`;
|
|
810
|
-
const evalParams = ctxId ? { contextId: ctxId, expression: expr, returnByValue: false } : { expression: expr, returnByValue: false };
|
|
900
|
+
const activeExpr = buildA11yInvocation("resolveDeepActiveElement", []);
|
|
901
|
+
const evalParams = ctxId ? {
|
|
902
|
+
contextId: ctxId,
|
|
903
|
+
expression: activeExpr,
|
|
904
|
+
returnByValue: false
|
|
905
|
+
} : { expression: activeExpr, returnByValue: false };
|
|
811
906
|
const { result } = yield focusedSession.send(
|
|
812
907
|
"Runtime.evaluate",
|
|
813
908
|
evalParams
|
|
@@ -821,48 +916,7 @@ function computeActiveElementXpath(page) {
|
|
|
821
916
|
try {
|
|
822
917
|
const { result } = yield focusedSession.send("Runtime.callFunctionOn", {
|
|
823
918
|
objectId,
|
|
824
|
-
functionDeclaration:
|
|
825
|
-
try {
|
|
826
|
-
const node = this;
|
|
827
|
-
function sibIndex(n) {
|
|
828
|
-
let i = 1; const t = n.nodeType+':'+(n.nodeName||'').toLowerCase();
|
|
829
|
-
for (let p = n.previousSibling; p; p = p.previousSibling) {
|
|
830
|
-
const key = p.nodeType+':'+(p.nodeName||'').toLowerCase();
|
|
831
|
-
if (key === t) i++;
|
|
832
|
-
}
|
|
833
|
-
return i;
|
|
834
|
-
}
|
|
835
|
-
function step(n) {
|
|
836
|
-
if (!n) return '';
|
|
837
|
-
if (n.nodeType === Node.DOCUMENT_NODE) return '';
|
|
838
|
-
if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE) return '//';
|
|
839
|
-
if (n.nodeType === Node.TEXT_NODE) return 'text()[' + sibIndex(n) + ']';
|
|
840
|
-
if (n.nodeType === Node.COMMENT_NODE) return 'comment()[' + sibIndex(n) + ']';
|
|
841
|
-
const tag = (n.nodeName||'').toLowerCase();
|
|
842
|
-
const name = tag.includes(':') ? "*[name()='"+tag+"']" : tag;
|
|
843
|
-
return name + '[' + sibIndex(n) + ']';
|
|
844
|
-
}
|
|
845
|
-
const parts = [];
|
|
846
|
-
let cur = node;
|
|
847
|
-
while (cur) {
|
|
848
|
-
if (cur.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
849
|
-
parts.push('//');
|
|
850
|
-
cur = (cur && cur.host) ? cur.host : null;
|
|
851
|
-
continue;
|
|
852
|
-
}
|
|
853
|
-
const s = step(cur);
|
|
854
|
-
if (s) parts.push(s);
|
|
855
|
-
cur = cur.parentNode;
|
|
856
|
-
}
|
|
857
|
-
parts.reverse();
|
|
858
|
-
let out = '';
|
|
859
|
-
for (const s of parts) {
|
|
860
|
-
if (s === '//') out = out ? (out.endsWith('/') ? out + '/' : out + '//') : '//';
|
|
861
|
-
else out = out ? (out.endsWith('/') ? out + s : out + '/' + s) : '/' + s;
|
|
862
|
-
}
|
|
863
|
-
return out || '/';
|
|
864
|
-
} catch { return ''; }
|
|
865
|
-
}`,
|
|
919
|
+
functionDeclaration: a11yScriptSources.nodeToAbsoluteXPath,
|
|
866
920
|
returnByValue: true
|
|
867
921
|
});
|
|
868
922
|
try {
|
|
@@ -899,9 +953,6 @@ function computeActiveElementXpath(page) {
|
|
|
899
953
|
return prefix ? prefixXPath(prefix, leafXPath) : normalizeXPath(leafXPath);
|
|
900
954
|
});
|
|
901
955
|
}
|
|
902
|
-
function scrollOffsetsExpr() {
|
|
903
|
-
return "({sx:(window.scrollX||window.pageXOffset||0),sy:(window.scrollY||window.pageYOffset||0)})";
|
|
904
|
-
}
|
|
905
956
|
function buildAbsoluteXPathFromChain(chain, leafSession, leafBackendNodeId) {
|
|
906
957
|
return __async(this, null, function* () {
|
|
907
958
|
let prefix = "";
|
|
@@ -934,49 +985,7 @@ function absoluteXPathForBackendNode(session, backendNodeId) {
|
|
|
934
985
|
"Runtime.callFunctionOn",
|
|
935
986
|
{
|
|
936
987
|
objectId,
|
|
937
|
-
functionDeclaration:
|
|
938
|
-
try {
|
|
939
|
-
const node = this;
|
|
940
|
-
function sibIndex(n) {
|
|
941
|
-
let i = 1; const t = n.nodeType+':'+(n.nodeName||'').toLowerCase();
|
|
942
|
-
for (let p = n.previousSibling; p; p = p.previousSibling) {
|
|
943
|
-
const key = p.nodeType+':'+(p.nodeName||'').toLowerCase();
|
|
944
|
-
if (key === t) i++;
|
|
945
|
-
}
|
|
946
|
-
return i;
|
|
947
|
-
}
|
|
948
|
-
function step(n) {
|
|
949
|
-
if (!n) return '';
|
|
950
|
-
if (n.nodeType === Node.DOCUMENT_NODE) return '';
|
|
951
|
-
if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE) return '//'; // ShadowRoot hop
|
|
952
|
-
if (n.nodeType === Node.TEXT_NODE) return 'text()[' + sibIndex(n) + ']';
|
|
953
|
-
if (n.nodeType === Node.COMMENT_NODE) return 'comment()[' + sibIndex(n) + ']';
|
|
954
|
-
const tag = (n.nodeName||'').toLowerCase();
|
|
955
|
-
const name = tag.includes(':') ? "*[name()='"+tag+"']" : tag;
|
|
956
|
-
return name + '[' + sibIndex(n) + ']';
|
|
957
|
-
}
|
|
958
|
-
const parts = [];
|
|
959
|
-
let cur = node;
|
|
960
|
-
while (cur) {
|
|
961
|
-
// Insert a marker before stepping out of a ShadowRoot
|
|
962
|
-
if (cur.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
963
|
-
parts.push('//');
|
|
964
|
-
cur = (cur && cur.host) ? cur.host : null;
|
|
965
|
-
continue;
|
|
966
|
-
}
|
|
967
|
-
const s = step(cur);
|
|
968
|
-
if (s) parts.push(s);
|
|
969
|
-
cur = cur.parentNode;
|
|
970
|
-
}
|
|
971
|
-
parts.reverse();
|
|
972
|
-
let out = '';
|
|
973
|
-
for (const s of parts) {
|
|
974
|
-
if (s === '//') out = out ? (out.endsWith('/') ? out + '/' : out + '//') : '//';
|
|
975
|
-
else out = out ? (out.endsWith('/') ? out + s : out + '/' + s) : '/' + s;
|
|
976
|
-
}
|
|
977
|
-
return out || '/';
|
|
978
|
-
} catch { return ''; }
|
|
979
|
-
}`,
|
|
988
|
+
functionDeclaration: a11yScriptSources.nodeToAbsoluteXPath,
|
|
980
989
|
returnByValue: true
|
|
981
990
|
}
|
|
982
991
|
);
|
|
@@ -1741,18 +1750,10 @@ function resolveObjectIdForXPath(session, xpath, frameId) {
|
|
|
1741
1750
|
} catch (e2) {
|
|
1742
1751
|
contextId = void 0;
|
|
1743
1752
|
}
|
|
1744
|
-
const expr =
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
return window.__stagehandV3__.resolveSimpleXPath(xp);
|
|
1749
|
-
}
|
|
1750
|
-
} catch {}
|
|
1751
|
-
try {
|
|
1752
|
-
const res = document.evaluate(xp, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
|
1753
|
-
return res.singleNodeValue;
|
|
1754
|
-
} catch { return null; }
|
|
1755
|
-
})()`;
|
|
1753
|
+
const expr = buildLocatorInvocation("resolveXPathMainWorld", [
|
|
1754
|
+
JSON.stringify(xpath),
|
|
1755
|
+
"0"
|
|
1756
|
+
]);
|
|
1756
1757
|
const { result, exceptionDetails } = yield session.send("Runtime.evaluate", {
|
|
1757
1758
|
expression: expr,
|
|
1758
1759
|
returnByValue: false,
|
|
@@ -1765,76 +1766,41 @@ function resolveObjectIdForXPath(session, xpath, frameId) {
|
|
|
1765
1766
|
}
|
|
1766
1767
|
function resolveObjectIdForCss(session, selector, frameId) {
|
|
1767
1768
|
return __async(this, null, function* () {
|
|
1768
|
-
var _a4;
|
|
1769
1769
|
let contextId;
|
|
1770
1770
|
try {
|
|
1771
1771
|
if (frameId) {
|
|
1772
1772
|
contextId = yield executionContexts.waitForMainWorld(session, frameId, 800).catch(
|
|
1773
1773
|
() => {
|
|
1774
|
-
var
|
|
1775
|
-
return (
|
|
1774
|
+
var _a4;
|
|
1775
|
+
return (_a4 = executionContexts.getMainWorld(session, frameId)) != null ? _a4 : void 0;
|
|
1776
1776
|
}
|
|
1777
1777
|
);
|
|
1778
1778
|
}
|
|
1779
1779
|
} catch (e2) {
|
|
1780
1780
|
contextId = void 0;
|
|
1781
1781
|
}
|
|
1782
|
-
const
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
if (backdoor && typeof backdoor.getClosedRoot === 'function') {
|
|
1801
|
-
function* roots() {
|
|
1802
|
-
yield document;
|
|
1803
|
-
const queue = [];
|
|
1804
|
-
try {
|
|
1805
|
-
const w = document.createTreeWalker(document, NodeFilter.SHOW_ELEMENT);
|
|
1806
|
-
let e; while ((e = w.nextNode())) {
|
|
1807
|
-
if (e.shadowRoot) queue.push(e.shadowRoot);
|
|
1808
|
-
try { const closed = backdoor.getClosedRoot(e); if (closed) queue.push(closed); } catch {}
|
|
1809
|
-
}
|
|
1810
|
-
} catch {}
|
|
1811
|
-
while (queue.length) {
|
|
1812
|
-
const r = queue.shift();
|
|
1813
|
-
yield r;
|
|
1814
|
-
try {
|
|
1815
|
-
const w2 = document.createTreeWalker(r, NodeFilter.SHOW_ELEMENT);
|
|
1816
|
-
let e2; while ((e2 = w2.nextNode())) {
|
|
1817
|
-
if (e2.shadowRoot) queue.push(e2.shadowRoot);
|
|
1818
|
-
try { const closed2 = backdoor.getClosedRoot(e2); if (closed2) queue.push(closed2); } catch {}
|
|
1819
|
-
}
|
|
1820
|
-
} catch {}
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
for (const r of roots()) {
|
|
1824
|
-
try { const hit = r.querySelector(selector); if (hit) return hit; } catch {}
|
|
1825
|
-
}
|
|
1826
|
-
return null;
|
|
1827
|
-
}
|
|
1828
|
-
return queryOpenDeep(document);
|
|
1829
|
-
})()`;
|
|
1830
|
-
const { result, exceptionDetails } = yield session.send("Runtime.evaluate", {
|
|
1831
|
-
expression: expr,
|
|
1832
|
-
returnByValue: false,
|
|
1833
|
-
contextId,
|
|
1834
|
-
awaitPromise: true
|
|
1782
|
+
const primaryExpr = buildLocatorInvocation("resolveCssSelector", [
|
|
1783
|
+
JSON.stringify(selector),
|
|
1784
|
+
"0"
|
|
1785
|
+
]);
|
|
1786
|
+
const fallbackExpr = buildLocatorInvocation("resolveCssSelectorPierce", [
|
|
1787
|
+
JSON.stringify(selector),
|
|
1788
|
+
"0"
|
|
1789
|
+
]);
|
|
1790
|
+
const evaluate = (expression) => __async(null, null, function* () {
|
|
1791
|
+
var _a4;
|
|
1792
|
+
const { result, exceptionDetails } = yield session.send("Runtime.evaluate", {
|
|
1793
|
+
expression,
|
|
1794
|
+
returnByValue: false,
|
|
1795
|
+
contextId,
|
|
1796
|
+
awaitPromise: true
|
|
1797
|
+
});
|
|
1798
|
+
if (exceptionDetails) return null;
|
|
1799
|
+
return (_a4 = result == null ? void 0 : result.objectId) != null ? _a4 : null;
|
|
1835
1800
|
});
|
|
1836
|
-
|
|
1837
|
-
|
|
1801
|
+
const primary = yield evaluate(primaryExpr);
|
|
1802
|
+
if (primary) return primary;
|
|
1803
|
+
return evaluate(fallbackExpr);
|
|
1838
1804
|
});
|
|
1839
1805
|
}
|
|
1840
1806
|
function decorateRoles(nodes, opts) {
|
|
@@ -2074,6 +2040,9 @@ var init_snapshot = __esm({
|
|
|
2074
2040
|
"lib/v3/understudy/a11y/snapshot.ts"() {
|
|
2075
2041
|
init_executionContextRegistry();
|
|
2076
2042
|
init_logger();
|
|
2043
|
+
init_a11yScripts_generated();
|
|
2044
|
+
init_a11yInvocation();
|
|
2045
|
+
init_locatorInvocation();
|
|
2077
2046
|
init_sdkErrors();
|
|
2078
2047
|
DOM_DEPTH_ATTEMPTS = [-1, 256, 128, 64, 32, 16, 8, 4, 2, 1];
|
|
2079
2048
|
DESCRIBE_DEPTH_ATTEMPTS = [-1, 64, 32, 16, 8, 4, 2, 1];
|
|
@@ -2081,62 +2050,6 @@ var init_snapshot = __esm({
|
|
|
2081
2050
|
}
|
|
2082
2051
|
});
|
|
2083
2052
|
|
|
2084
|
-
// lib/v3/dom/build/locatorScripts.generated.ts
|
|
2085
|
-
var locatorScriptBootstrap, locatorScriptSources, locatorScriptGlobalRefs;
|
|
2086
|
-
var init_locatorScripts_generated = __esm({
|
|
2087
|
-
"lib/v3/dom/build/locatorScripts.generated.ts"() {
|
|
2088
|
-
locatorScriptBootstrap = 'if (!globalThis.__stagehandLocatorScripts) { var __stagehandLocatorScriptsFactory=(()=>{var L=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var c in e)L(t,c,{get:e[c],enumerable:!0})},A=(t,e,c,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!H.call(t,o)&&o!==c&&L(t,o,{get:()=>e[o],enumerable:!(n=R(e,o))||n.enumerable});return t};var _=t=>A(L({},"__esModule",{value:!0}),t);var oe={};D(oe,{assignFilePayloadsToInputElement:()=>F,countCssMatchesPierce:()=>ee,countCssMatchesPrimary:()=>Z,countTextMatches:()=>te,countXPathMatchesMainWorld:()=>ne,dispatchDomClick:()=>W,ensureFileInputElement:()=>I,fillElementValue:()=>O,focusElement:()=>V,isElementChecked:()=>B,isElementVisible:()=>Y,prepareElementForTyping:()=>T,readElementInnerHTML:()=>U,readElementInnerText:()=>j,readElementInputValue:()=>$,readElementTextContent:()=>z,resolveCssSelector:()=>K,resolveCssSelectorPierce:()=>G,resolveTextSelector:()=>J,resolveXPathMainWorld:()=>Q,scrollElementToPercent:()=>q,selectElementOptions:()=>X});function I(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}function F(t){try{let e=this;if(!e||e.tagName?.toLowerCase()!=="input"||(e.type??"").toLowerCase()!=="file")return!1;let c=(()=>{try{return new DataTransfer}catch{return null}})();if(!c)return!1;let n=Array.isArray(t)?t:[];for(let o of n){if(!o)continue;let y=o.name||"upload.bin",u=o.mimeType||"application/octet-stream",a=typeof o.lastModified=="number"?o.lastModified:Date.now(),l=window.atob(o.base64??""),i=new Uint8Array(l.length);for(let s=0;s<l.length;s+=1)i[s]=l.charCodeAt(s);let f=new Blob([i],{type:u}),h=new File([f],y,{type:u,lastModified:a});c.items.add(h)}return e.files=c.files,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),!0}catch{return!1}}function W(t){let e=t??{};try{let c=new MouseEvent("click",{bubbles:!!e.bubbles,cancelable:!!e.cancelable,composed:!!e.composed,detail:typeof e.detail=="number"?e.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(c)}catch{try{this.click()}catch{}}}function q(t){let e=c=>{if(typeof c=="number"&&Number.isFinite(c))return c;let n=String(c??"").trim();if(!n)return 0;let o=parseFloat(n.replace("%",""));return Number.isNaN(o)||!Number.isFinite(o)?0:o};try{let c=Math.max(0,Math.min(e(t),100)),n=this,o=n.tagName?.toLowerCase()??"";if(o==="html"||o==="body"){let h=(n.ownerDocument?.scrollingElement||n.ownerDocument?.documentElement||n.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,s=n.ownerDocument?.defaultView?.innerHeight??window.innerHeight,g=Math.max(0,h-s)*(c/100);return n.ownerDocument?.defaultView?.scrollTo({top:g,left:n.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:"smooth"}),!0}let u=n.scrollHeight??0,a=n.clientHeight??0,i=Math.max(0,u-a)*(c/100);return n.scrollTo({top:i,left:n.scrollLeft??0,behavior:"smooth"}),!0}catch{return!1}}var v=new Set(["color","date","datetime-local","month","range","time","week"]),P=new Set(["","email","number","password","search","tel","text","url"]);function T(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument||document,c=e.defaultView||window;try{typeof t.focus=="function"&&t.focus()}catch{}if(t instanceof c.HTMLInputElement||t instanceof c.HTMLTextAreaElement){try{if(typeof t.select=="function")return t.select(),!0}catch{}try{let n=(t.value??"").length;if(typeof t.setSelectionRange=="function")return t.setSelectionRange(0,n),!0}catch{}return!0}if(t.isContentEditable){let n=e.getSelection?.(),o=e.createRange?.();if(n&&o)try{o.selectNodeContents(t),n.removeAllRanges(),n.addRange(o)}catch{}return!0}return!1}catch{return!1}}function O(t){let e=this;if(!e.isConnected)return{status:"error",reason:"notconnected"};let n=(e.ownerDocument||document).defaultView||window,o=t??"";try{let y=u=>{let a;if(typeof n.InputEvent=="function")try{a=new n.InputEvent("input",{bubbles:!0,composed:!0,data:u,inputType:"insertText"})}catch{a=new n.Event("input",{bubbles:!0,composed:!0})}else a=new n.Event("input",{bubbles:!0,composed:!0});e.dispatchEvent(a);let l=new n.Event("change",{bubbles:!0});e.dispatchEvent(l)};if(e instanceof n.HTMLInputElement){let u=(e.type||"").toLowerCase();if(!P.has(u)&&!v.has(u))return{status:"error",reason:`unsupported-input-type:${u}`};let a=t;if(u==="number"){let l=t.trim();if(l!==""&&Number.isNaN(Number(l)))return{status:"error",reason:"invalid-number-value"};a=l}if(o=a,v.has(u)){let l=t.trim();o=l,T.call(e);let i=n.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(i,"value")?.set;return typeof h=="function"?h.call(e,l):e.value=l,e._valueTracker?.setValue?.(l),e.value!==l?{status:"error",reason:"malformed-value"}:(y(l),{status:"done"})}return T.call(e),{status:"needsinput",value:a}}return e instanceof n.HTMLTextAreaElement?(T.call(e),o=t,{status:"needsinput",value:t}):e instanceof n.HTMLSelectElement?{status:"error",reason:"unsupported-element"}:e.isContentEditable?(T.call(e),o=t,{status:"needsinput",value:t}):{status:"error",reason:"unsupported-element"}}catch(y){let u="exception";if(y&&typeof y=="object"){let a=y.message;typeof a=="string"&&a.trim().length>0&&(u=`exception:${a}`)}return{status:"needsinput",value:o,reason:u}}}function V(){try{typeof this.focus=="function"&&this.focus()}catch{}}function X(t){try{if(!(this instanceof HTMLSelectElement))return[];let e=Array.isArray(t)?t:[t],c=new Set(e.map(u=>String(u??"").trim())),n=u=>{let a=(u.label||u.textContent||"").trim(),l=String(u.value??"").trim();return c.has(a)||c.has(l)};if(this.multiple)for(let u of Array.from(this.options))u.selected=n(u);else{let u=!1;for(let a of Array.from(this.options))!u&&n(a)?(a.selected=!0,this.value=a.value,u=!0):a.selected=!1}let o=new Event("input",{bubbles:!0}),y=new Event("change",{bubbles:!0});return this.dispatchEvent(o),this.dispatchEvent(y),Array.from(this.selectedOptions).map(u=>u.value)}catch{return[]}}function Y(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument?.defaultView?.getComputedStyle(t)??window.getComputedStyle(t);if(!e||e.display==="none"||e.visibility==="hidden")return!1;let c=parseFloat(e.opacity??"1");if(!Number.isFinite(c)||c===0)return!1;let n=t.getBoundingClientRect();return!(!n||Math.max(n.width,n.height)===0||t.getClientRects().length===0)}catch{return!1}}function B(){try{let t=this;if((t.tagName||"").toLowerCase()==="input"){let n=t.type?.toLowerCase()??"";if(n==="checkbox"||n==="radio")return!!t.checked}let c=t.getAttribute?.("aria-checked");return c!=null?c==="true":!1}catch{return!1}}function $(){try{let t=this,e=(t.tagName||"").toLowerCase();return e==="input"||e==="textarea"||e==="select"?String(t.value??""):t.isContentEditable?String(t.textContent??""):""}catch{return""}}function z(){try{return String(this.textContent??"")}catch{return""}}function U(){try{return String(this.innerHTML??"")}catch{return""}}function j(){try{let t=this,e=t.innerText;if(typeof e=="string"&&e.length>0)return e;let c=t.textContent;return typeof c=="string"?c:""}catch{return""}}var N=t=>{let e=Number(t??0);return!Number.isFinite(e)||e<0?0:Math.floor(e)},M=(t,e)=>{if(!t)return[];let c=new WeakSet,n=new Set,o=[],y=[document],u=a=>{if(!(!a||c.has(a)||o.length>=e)){c.add(a);try{let l=a.querySelectorAll(t);for(let i of l)if(!n.has(i)&&(n.add(i),o.push(i),o.length>=e))return}catch{}try{let i=(a instanceof Document?a:a.host?.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT),f;for(;f=i.nextNode();){if(!(f instanceof Element))continue;let h=f.shadowRoot;h&&y.push(h)}}catch{}}};for(;y.length&&o.length<e;){let a=y.shift();a&&u(a)}return o};function K(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e);return M(c,n+1)[n]??null}function G(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e),o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!="function")return M(c,n+1)[n]??null;let y=h=>{try{return o.getClosedRoot(h)??null}catch{return null}},u=new WeakSet,a=new Set,l=[],i=[document],f=h=>{if(!(!h||u.has(h)||l.length>=n+1)){u.add(h);try{let s=h.querySelectorAll(c);for(let d of s)if(!a.has(d)&&(a.add(d),l.push(d),l.length>=n+1))return}catch{}try{let d=(h instanceof Document?h:h.host?.ownerDocument??document).createTreeWalker(h,NodeFilter.SHOW_ELEMENT),g;for(;g=d.nextNode();){if(!(g instanceof Element))continue;let w=g.shadowRoot;w&&i.push(w);let E=y(g);E&&i.push(E)}}catch{}}};for(;i.length&&l.length<n+1;){let h=i.shift();h&&f(h)}return l[n]??null}function J(t,e){let c=String(t??"");if(!c)return null;let n=c.toLowerCase(),o=N(e),y=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),u=r=>{if(!r)return!1;let p=r.tagName?.toUpperCase()??"";return y.has(p)},a=r=>{try{if(u(r))return"";let p=r.innerText;if(typeof p=="string"&&p.trim())return p.trim()}catch{}try{let p=r.textContent;if(typeof p=="string")return p.trim()}catch{}return""},l=r=>{let p=a(r);return!!p&&p.toLowerCase().includes(n)},i=window.__stagehandV3__,f=i&&typeof i.getClosedRoot=="function"?r=>{try{return i.getClosedRoot(r)??null}catch{return null}}:r=>null,h=new WeakSet,s=[],d=[],g=r=>{!r||h.has(r)||(h.add(r),s.push(r))},w=r=>{try{return(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(g(document);s.length;){let r=s.shift();if(!r)continue;r instanceof Element&&l(r)&&d.push({element:r,tag:r.tagName??"",id:r.id??"",className:r.className??"",text:a(r)});let p=w(r);if(!p)continue;let x;for(;x=p.nextNode();){if(!(x instanceof Element))continue;l(x)&&d.push({element:x,tag:x.tagName??"",id:x.id??"",className:x.className??"",text:a(x)});let b=x.shadowRoot;b&&g(b);let S=f(x);S&&g(S)}}let E=[];for(let r of d){let p=r.element,x=!1;for(let b of d)if(r!==b)try{if(p.contains(b.element)){x=!0;break}}catch{}x||E.push(r)}return E[o]?.element??null}function Q(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e),o=window.__stagehandV3__;if(n===0){try{if(o&&typeof o.resolveSimpleXPath=="function"){let s=o.resolveSimpleXPath(c);if(s)return s}}catch{}try{return document.evaluate(c,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch{}}let u=(s=>{let d=String(s||"").trim();if(!d)return[];let g=d.replace(/^xpath=/i,""),w=[],E=0;for(;E<g.length;){let m="child";g.startsWith("//",E)?(m="desc",E+=2):g[E]==="/"&&(m="child",E+=1);let r=E;for(;E<g.length&&g[E]!=="/";)E+=1;let p=g.slice(r,E).trim();if(!p)continue;let x=p.match(/^(.*?)(\\[(\\d+)\\])?$/u),b=(x?.[1]??p).trim(),S=x?.[3]?Math.max(1,Number(x[3])):null,C=b===""?"*":b.toLowerCase();w.push({axis:m,tag:C,index:S})}return w})(c);if(!u.length)return null;let a=o&&typeof o.getClosedRoot=="function"?s=>{try{return o.getClosedRoot(s)??null}catch{return null}}:s=>null,l=s=>{let d=[];if(!s)return d;if(s instanceof Document)return s.documentElement&&d.push(s.documentElement),d;if(s instanceof ShadowRoot||s instanceof DocumentFragment)return d.push(...Array.from(s.children??[])),d;if(s instanceof Element){d.push(...Array.from(s.children??[]));let g=s.shadowRoot;g&&d.push(...Array.from(g.children??[]));let w=a(s);return w&&d.push(...Array.from(w.children??[])),d}return d},i=s=>{let d=[],g=new Set,w=[...l(s)];for(;w.length;){let E=w.shift();!E||g.has(E)||(g.add(E),d.push(E),w.push(...l(E)))}return d},f=[document];for(let s of u){let d=[],g=new Set;for(let w of f){if(!w)continue;let E=s.axis==="child"?l(w):i(w);if(!E.length)continue;let m=E.filter(r=>r instanceof Element?s.tag==="*"?!0:r.localName===s.tag:!1);if(s.index!=null){let r=s.index-1,p=r>=0&&r<m.length?m[r]:null;p&&!g.has(p)&&(g.add(p),d.push(p))}else for(let r of m)g.has(r)||(g.add(r),d.push(r))}if(!d.length)return null;f=d}return f[n]??null}function Z(t){let e=String(t??"").trim();if(!e)return 0;let c=new WeakSet,n=o=>{if(!o||c.has(o))return 0;c.add(o);let y=0;try{let u=o;typeof u.querySelectorAll=="function"&&(y+=u.querySelectorAll(e).length)}catch{}try{let a=(o instanceof Document?o:o?.ownerDocument??document).createTreeWalker(o,NodeFilter.SHOW_ELEMENT),l;for(;l=a.nextNode();)l instanceof Element&&l.shadowRoot&&(y+=n(l.shadowRoot))}catch{}return y};try{return n(document)}catch{try{return document.querySelectorAll(e).length}catch{return 0}}}function ee(t){let e=String(t??"").trim();if(!e)return 0;let c=window.__stagehandV3__;if(!c||typeof c.getClosedRoot!="function")try{return document.querySelectorAll(e).length}catch{return 0}let n=new WeakSet,o=[],y=l=>{!l||n.has(l)||(n.add(l),o.push(l))};y(document);let u=0,a=l=>{let i=l.shadowRoot;i&&y(i);try{let f=c.getClosedRoot(l);f&&y(f)}catch{}};for(;o.length;){let l=o.shift();if(l){try{let i=l;typeof i.querySelectorAll=="function"&&(u+=i.querySelectorAll(e).length)}catch{}try{let f=(l instanceof Document?l:l instanceof ShadowRoot?l.host?.ownerDocument??document:l.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),h;for(;h=f.nextNode();)h instanceof Element&&a(h)}catch{}}}return u}function te(t){let e=String(t??"");if(!e)return{count:0,sample:[],error:null};let c=e.toLowerCase(),n=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),o=m=>{if(!m)return!1;let r=m.tagName?.toUpperCase()??"";return n.has(r)},y=m=>{try{if(o(m))return"";let r=m.innerText;if(typeof r=="string"&&r.trim())return r.trim()}catch{}try{let r=m.textContent;if(typeof r=="string")return r.trim()}catch{}return""},u=m=>{let r=y(m);return!!r&&r.toLowerCase().includes(c)},a=window.__stagehandV3__,l=a&&typeof a.getClosedRoot=="function"?m=>{try{return a.getClosedRoot(m)??null}catch{return null}}:m=>null,i=new WeakSet,f=[],h=m=>{!m||i.has(m)||(i.add(m),f.push(m))},s=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},d=[];for(h(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&u(m)&&d.push({element:m,tag:m.tagName??"",id:m.id??"",className:m.className??"",text:y(m)});let r=s(m);if(!r)continue;let p;for(;p=r.nextNode();){if(!(p instanceof Element))continue;u(p)&&d.push({element:p,tag:p.tagName??"",id:p.id??"",className:p.className??"",text:y(p)});let x=p.shadowRoot;x&&h(x);let b=l(p);b&&h(b)}}let g=[];for(let m of d){let r=m.element,p=!1;for(let x of d)if(m!==x)try{if(r.contains(x.element)){p=!0;break}}catch{}p||g.push(m)}let w=g.length,E=g.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:w,sample:E,error:null}}function ne(t){let e=String(t??"").trim();if(!e)return 0;let n=(i=>{let f=String(i||"").trim().replace(/^xpath=/i,"");if(!f)return[];let h=[],s=0;for(;s<f.length;){let d="child";f.startsWith("//",s)?(d="desc",s+=2):f[s]==="/"&&(d="child",s+=1);let g=s;for(;s<f.length&&f[s]!=="/";)s+=1;let w=f.slice(g,s).trim();if(!w)continue;let E=w.match(/^(.*?)(\\[(\\d+)\\])?$/u),m=(E?.[1]??w).trim(),r=E?.[3]?Math.max(1,Number(E[3])):null,p=m===""?"*":m.toLowerCase();h.push({axis:d,tag:p,index:r})}return h})(e);if(!n.length)return 0;let o=window.__stagehandV3__,y=o&&typeof o.getClosedRoot=="function"?i=>{try{return o.getClosedRoot(i)??null}catch{return null}}:i=>null,u=i=>{let f=[];if(!i)return f;if(i instanceof Document)return i.documentElement&&f.push(i.documentElement),f;if(i instanceof ShadowRoot||i instanceof DocumentFragment)return f.push(...Array.from(i.children??[])),f;if(i instanceof Element){f.push(...Array.from(i.children??[]));let h=i.shadowRoot;h&&f.push(...Array.from(h.children??[]));let s=y(i);return s&&f.push(...Array.from(s.children??[])),f}return f},a=i=>{let f=[],h=new Set,s=[...u(i)];for(;s.length;){let d=s.shift();!d||h.has(d)||(h.add(d),f.push(d),s.push(...u(d)))}return f},l=[document];for(let i of n){let f=[],h=new Set;for(let s of l){if(!s)continue;let d=i.axis==="child"?u(s):a(s);if(!d.length)continue;let g=d.filter(w=>w instanceof Element?i.tag==="*"?!0:w.localName===i.tag:!1);if(i.index!=null){let w=i.index-1,E=w>=0&&w<g.length?g[w]:null;E&&!h.has(E)&&(h.add(E),f.push(E))}else for(let w of g)h.has(w)||(h.add(w),f.push(w))}if(!f.length)return 0;l=f}return l.length}return _(oe);})();\n globalThis.__stagehandLocatorScripts = __stagehandLocatorScriptsFactory;\n}';
|
|
2089
|
-
locatorScriptSources = {
|
|
2090
|
-
"assignFilePayloadsToInputElement": 'function k(t){try{let e=this;if(!e||e.tagName?.toLowerCase()!=="input"||(e.type??"").toLowerCase()!=="file")return!1;let i=(()=>{try{return new DataTransfer}catch{return null}})();if(!i)return!1;let n=Array.isArray(t)?t:[];for(let s of n){if(!s)continue;let y=s.name||"upload.bin",u=s.mimeType||"application/octet-stream",a=typeof s.lastModified=="number"?s.lastModified:Date.now(),l=window.atob(s.base64??""),c=new Uint8Array(l.length);for(let r=0;r<l.length;r+=1)c[r]=l.charCodeAt(r);let f=new Blob([c],{type:u}),h=new File([f],y,{type:u,lastModified:a});i.items.add(h)}return e.files=i.files,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),!0}catch{return!1}}',
|
|
2091
|
-
"countCssMatchesPierce": 'function K(t){let e=String(t??"").trim();if(!e)return 0;let i=window.__stagehandV3__;if(!i||typeof i.getClosedRoot!="function")try{return document.querySelectorAll(e).length}catch{return 0}let n=new WeakSet,s=[],y=l=>{!l||n.has(l)||(n.add(l),s.push(l))};y(document);let u=0,a=l=>{let c=l.shadowRoot;c&&y(c);try{let f=i.getClosedRoot(l);f&&y(f)}catch{}};for(;s.length;){let l=s.shift();if(l){try{let c=l;typeof c.querySelectorAll=="function"&&(u+=c.querySelectorAll(e).length)}catch{}try{let f=(l instanceof Document?l:l instanceof ShadowRoot?l.host?.ownerDocument??document:l.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),h;for(;h=f.nextNode();)h instanceof Element&&a(h)}catch{}}}return u}',
|
|
2092
|
-
"countCssMatchesPrimary": 'function j(t){let e=String(t??"").trim();if(!e)return 0;let i=new WeakSet,n=s=>{if(!s||i.has(s))return 0;i.add(s);let y=0;try{let u=s;typeof u.querySelectorAll=="function"&&(y+=u.querySelectorAll(e).length)}catch{}try{let a=(s instanceof Document?s:s?.ownerDocument??document).createTreeWalker(s,NodeFilter.SHOW_ELEMENT),l;for(;l=a.nextNode();)l instanceof Element&&l.shadowRoot&&(y+=n(l.shadowRoot))}catch{}return y};try{return n(document)}catch{try{return document.querySelectorAll(e).length}catch{return 0}}}',
|
|
2093
|
-
"countTextMatches": 'function G(t){let e=String(t??"");if(!e)return{count:0,sample:[],error:null};let i=e.toLowerCase(),n=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),s=m=>{if(!m)return!1;let o=m.tagName?.toUpperCase()??"";return n.has(o)},y=m=>{try{if(s(m))return"";let o=m.innerText;if(typeof o=="string"&&o.trim())return o.trim()}catch{}try{let o=m.textContent;if(typeof o=="string")return o.trim()}catch{}return""},u=m=>{let o=y(m);return!!o&&o.toLowerCase().includes(i)},a=window.__stagehandV3__,l=a&&typeof a.getClosedRoot=="function"?m=>{try{return a.getClosedRoot(m)??null}catch{return null}}:m=>null,c=new WeakSet,f=[],h=m=>{!m||c.has(m)||(c.add(m),f.push(m))},r=m=>{try{return(m instanceof Document?m:m?.ownerDocument??document).createTreeWalker(m,NodeFilter.SHOW_ELEMENT)}catch{return null}},d=[];for(h(document);f.length;){let m=f.shift();if(!m)continue;m instanceof Element&&u(m)&&d.push({element:m,tag:m.tagName??"",id:m.id??"",className:m.className??"",text:y(m)});let o=r(m);if(!o)continue;let p;for(;p=o.nextNode();){if(!(p instanceof Element))continue;u(p)&&d.push({element:p,tag:p.tagName??"",id:p.id??"",className:p.className??"",text:y(p)});let x=p.shadowRoot;x&&h(x);let b=l(p);b&&h(b)}}let g=[];for(let m of d){let o=m.element,p=!1;for(let x of d)if(m!==x)try{if(o.contains(x.element)){p=!0;break}}catch{}p||g.push(m)}let w=g.length,E=g.slice(0,5).map(m=>({tag:m.tag,id:m.id,class:m.className,text:m.text}));return{count:w,sample:E,error:null}}',
|
|
2094
|
-
"countXPathMatchesMainWorld": 'function J(t){let e=String(t??"").trim();if(!e)return 0;let n=(c=>{let f=String(c||"").trim().replace(/^xpath=/i,"");if(!f)return[];let h=[],r=0;for(;r<f.length;){let d="child";f.startsWith("//",r)?(d="desc",r+=2):f[r]==="/"&&(d="child",r+=1);let g=r;for(;r<f.length&&f[r]!=="/";)r+=1;let w=f.slice(g,r).trim();if(!w)continue;let E=w.match(/^(.*?)(\\[(\\d+)\\])?$/u),m=(E?.[1]??w).trim(),o=E?.[3]?Math.max(1,Number(E[3])):null,p=m===""?"*":m.toLowerCase();h.push({axis:d,tag:p,index:o})}return h})(e);if(!n.length)return 0;let s=window.__stagehandV3__,y=s&&typeof s.getClosedRoot=="function"?c=>{try{return s.getClosedRoot(c)??null}catch{return null}}:c=>null,u=c=>{let f=[];if(!c)return f;if(c instanceof Document)return c.documentElement&&f.push(c.documentElement),f;if(c instanceof ShadowRoot||c instanceof DocumentFragment)return f.push(...Array.from(c.children??[])),f;if(c instanceof Element){f.push(...Array.from(c.children??[]));let h=c.shadowRoot;h&&f.push(...Array.from(h.children??[]));let r=y(c);return r&&f.push(...Array.from(r.children??[])),f}return f},a=c=>{let f=[],h=new Set,r=[...u(c)];for(;r.length;){let d=r.shift();!d||h.has(d)||(h.add(d),f.push(d),r.push(...u(d)))}return f},l=[document];for(let c of n){let f=[],h=new Set;for(let r of l){if(!r)continue;let d=c.axis==="child"?u(r):a(r);if(!d.length)continue;let g=d.filter(w=>w instanceof Element?c.tag==="*"?!0:w.localName===c.tag:!1);if(c.index!=null){let w=c.index-1,E=w>=0&&w<g.length?g[w]:null;E&&!h.has(E)&&(h.add(E),f.push(E))}else for(let w of g)h.has(w)||(h.add(w),f.push(w))}if(!f.length)return 0;l=f}return l.length}',
|
|
2095
|
-
"dispatchDomClick": 'function H(t){let e=t??{};try{let i=new MouseEvent("click",{bubbles:!!e.bubbles,cancelable:!!e.cancelable,composed:!!e.composed,detail:typeof e.detail=="number"?e.detail:1,view:this?.ownerDocument?.defaultView??window});this.dispatchEvent(i)}catch{try{this.click()}catch{}}}',
|
|
2096
|
-
"ensureFileInputElement": 'function R(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}',
|
|
2097
|
-
"fillElementValue": 'function A(t){let e=this;if(!e.isConnected)return{status:"error",reason:"notconnected"};let n=(e.ownerDocument||document).defaultView||window,s=t??"";try{let y=u=>{let a;if(typeof n.InputEvent=="function")try{a=new n.InputEvent("input",{bubbles:!0,composed:!0,data:u,inputType:"insertText"})}catch{a=new n.Event("input",{bubbles:!0,composed:!0})}else a=new n.Event("input",{bubbles:!0,composed:!0});e.dispatchEvent(a);let l=new n.Event("change",{bubbles:!0});e.dispatchEvent(l)};if(e instanceof n.HTMLInputElement){let u=(e.type||"").toLowerCase();if(!C.has(u)&&!L.has(u))return{status:"error",reason:`unsupported-input-type:${u}`};let a=t;if(u==="number"){let l=t.trim();if(l!==""&&Number.isNaN(Number(l)))return{status:"error",reason:"invalid-number-value"};a=l}if(s=a,L.has(u)){let l=t.trim();s=l,S.call(e);let c=n.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(c,"value")?.set;return typeof h=="function"?h.call(e,l):e.value=l,e._valueTracker?.setValue?.(l),e.value!==l?{status:"error",reason:"malformed-value"}:(y(l),{status:"done"})}return S.call(e),{status:"needsinput",value:a}}return e instanceof n.HTMLTextAreaElement?(S.call(e),s=t,{status:"needsinput",value:t}):e instanceof n.HTMLSelectElement?{status:"error",reason:"unsupported-element"}:e.isContentEditable?(S.call(e),s=t,{status:"needsinput",value:t}):{status:"error",reason:"unsupported-element"}}catch(y){let u="exception";if(y&&typeof y=="object"){let a=y.message;typeof a=="string"&&a.trim().length>0&&(u=`exception:${a}`)}return{status:"needsinput",value:s,reason:u}}}',
|
|
2098
|
-
"focusElement": 'function _(){try{typeof this.focus=="function"&&this.focus()}catch{}}',
|
|
2099
|
-
"isElementChecked": 'function W(){try{let t=this;if((t.tagName||"").toLowerCase()==="input"){let n=t.type?.toLowerCase()??"";if(n==="checkbox"||n==="radio")return!!t.checked}let i=t.getAttribute?.("aria-checked");return i!=null?i==="true":!1}catch{return!1}}',
|
|
2100
|
-
"isElementVisible": 'function F(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument?.defaultView?.getComputedStyle(t)??window.getComputedStyle(t);if(!e||e.display==="none"||e.visibility==="hidden")return!1;let i=parseFloat(e.opacity??"1");if(!Number.isFinite(i)||i===0)return!1;let n=t.getBoundingClientRect();return!(!n||Math.max(n.width,n.height)===0||t.getClientRects().length===0)}catch{return!1}}',
|
|
2101
|
-
"prepareElementForTyping": 'function S(){try{let t=this;if(!t.isConnected)return!1;let e=t.ownerDocument||document,i=e.defaultView||window;try{typeof t.focus=="function"&&t.focus()}catch{}if(t instanceof i.HTMLInputElement||t instanceof i.HTMLTextAreaElement){try{if(typeof t.select=="function")return t.select(),!0}catch{}try{let n=(t.value??"").length;if(typeof t.setSelectionRange=="function")return t.setSelectionRange(0,n),!0}catch{}return!0}if(t.isContentEditable){let n=e.getSelection?.(),s=e.createRange?.();if(n&&s)try{s.selectNodeContents(t),n.removeAllRanges(),n.addRange(s)}catch{}return!0}return!1}catch{return!1}}',
|
|
2102
|
-
"readElementInnerHTML": 'function O(){try{return String(this.innerHTML??"")}catch{return""}}',
|
|
2103
|
-
"readElementInnerText": 'function V(){try{let t=this,e=t.innerText;if(typeof e=="string"&&e.length>0)return e;let i=t.textContent;return typeof i=="string"?i:""}catch{return""}}',
|
|
2104
|
-
"readElementInputValue": 'function q(){try{let t=this,e=(t.tagName||"").toLowerCase();return e==="input"||e==="textarea"||e==="select"?String(t.value??""):t.isContentEditable?String(t.textContent??""):""}catch{return""}}',
|
|
2105
|
-
"readElementTextContent": 'function P(){try{return String(this.textContent??"")}catch{return""}}',
|
|
2106
|
-
"resolveCssSelector": 'function Y(t,e){let i=String(t??"").trim();if(!i)return null;let n=N(e);return v(i,n+1)[n]??null}',
|
|
2107
|
-
"resolveCssSelectorPierce": 'function B(t,e){let i=String(t??"").trim();if(!i)return null;let n=N(e),s=window.__stagehandV3__;if(!s||typeof s.getClosedRoot!="function")return v(i,n+1)[n]??null;let y=h=>{try{return s.getClosedRoot(h)??null}catch{return null}},u=new WeakSet,a=new Set,l=[],c=[document],f=h=>{if(!(!h||u.has(h)||l.length>=n+1)){u.add(h);try{let r=h.querySelectorAll(i);for(let d of r)if(!a.has(d)&&(a.add(d),l.push(d),l.length>=n+1))return}catch{}try{let d=(h instanceof Document?h:h.host?.ownerDocument??document).createTreeWalker(h,NodeFilter.SHOW_ELEMENT),g;for(;g=d.nextNode();){if(!(g instanceof Element))continue;let w=g.shadowRoot;w&&c.push(w);let E=y(g);E&&c.push(E)}}catch{}}};for(;c.length&&l.length<n+1;){let h=c.shift();h&&f(h)}return l[n]??null}',
|
|
2108
|
-
"resolveTextSelector": 'function $(t,e){let i=String(t??"");if(!i)return null;let n=i.toLowerCase(),s=N(e),y=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),u=o=>{if(!o)return!1;let p=o.tagName?.toUpperCase()??"";return y.has(p)},a=o=>{try{if(u(o))return"";let p=o.innerText;if(typeof p=="string"&&p.trim())return p.trim()}catch{}try{let p=o.textContent;if(typeof p=="string")return p.trim()}catch{}return""},l=o=>{let p=a(o);return!!p&&p.toLowerCase().includes(n)},c=window.__stagehandV3__,f=c&&typeof c.getClosedRoot=="function"?o=>{try{return c.getClosedRoot(o)??null}catch{return null}}:o=>null,h=new WeakSet,r=[],d=[],g=o=>{!o||h.has(o)||(h.add(o),r.push(o))},w=o=>{try{return(o instanceof Document?o:o?.ownerDocument??document).createTreeWalker(o,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(g(document);r.length;){let o=r.shift();if(!o)continue;o instanceof Element&&l(o)&&d.push({element:o,tag:o.tagName??"",id:o.id??"",className:o.className??"",text:a(o)});let p=w(o);if(!p)continue;let x;for(;x=p.nextNode();){if(!(x instanceof Element))continue;l(x)&&d.push({element:x,tag:x.tagName??"",id:x.id??"",className:x.className??"",text:a(x)});let b=x.shadowRoot;b&&g(b);let T=f(x);T&&g(T)}}let E=[];for(let o of d){let p=o.element,x=!1;for(let b of d)if(o!==b)try{if(p.contains(b.element)){x=!0;break}}catch{}x||E.push(o)}return E[s]?.element??null}',
|
|
2109
|
-
"resolveXPathMainWorld": 'function z(t,e){let i=String(t??"").trim();if(!i)return null;let n=N(e),s=window.__stagehandV3__;if(n===0){try{if(s&&typeof s.resolveSimpleXPath=="function"){let r=s.resolveSimpleXPath(i);if(r)return r}}catch{}try{return document.evaluate(i,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch{}}let u=(r=>{let d=String(r||"").trim();if(!d)return[];let g=d.replace(/^xpath=/i,""),w=[],E=0;for(;E<g.length;){let m="child";g.startsWith("//",E)?(m="desc",E+=2):g[E]==="/"&&(m="child",E+=1);let o=E;for(;E<g.length&&g[E]!=="/";)E+=1;let p=g.slice(o,E).trim();if(!p)continue;let x=p.match(/^(.*?)(\\[(\\d+)\\])?$/u),b=(x?.[1]??p).trim(),T=x?.[3]?Math.max(1,Number(x[3])):null,M=b===""?"*":b.toLowerCase();w.push({axis:m,tag:M,index:T})}return w})(i);if(!u.length)return null;let a=s&&typeof s.getClosedRoot=="function"?r=>{try{return s.getClosedRoot(r)??null}catch{return null}}:r=>null,l=r=>{let d=[];if(!r)return d;if(r instanceof Document)return r.documentElement&&d.push(r.documentElement),d;if(r instanceof ShadowRoot||r instanceof DocumentFragment)return d.push(...Array.from(r.children??[])),d;if(r instanceof Element){d.push(...Array.from(r.children??[]));let g=r.shadowRoot;g&&d.push(...Array.from(g.children??[]));let w=a(r);return w&&d.push(...Array.from(w.children??[])),d}return d},c=r=>{let d=[],g=new Set,w=[...l(r)];for(;w.length;){let E=w.shift();!E||g.has(E)||(g.add(E),d.push(E),w.push(...l(E)))}return d},f=[document];for(let r of u){let d=[],g=new Set;for(let w of f){if(!w)continue;let E=r.axis==="child"?l(w):c(w);if(!E.length)continue;let m=E.filter(o=>o instanceof Element?r.tag==="*"?!0:o.localName===r.tag:!1);if(r.index!=null){let o=r.index-1,p=o>=0&&o<m.length?m[o]:null;p&&!g.has(p)&&(g.add(p),d.push(p))}else for(let o of m)g.has(o)||(g.add(o),d.push(o))}if(!d.length)return null;f=d}return f[n]??null}',
|
|
2110
|
-
"scrollElementToPercent": 'function D(t){let e=i=>{if(typeof i=="number"&&Number.isFinite(i))return i;let n=String(i??"").trim();if(!n)return 0;let s=parseFloat(n.replace("%",""));return Number.isNaN(s)||!Number.isFinite(s)?0:s};try{let i=Math.max(0,Math.min(e(t),100)),n=this,s=n.tagName?.toLowerCase()??"";if(s==="html"||s==="body"){let h=(n.ownerDocument?.scrollingElement||n.ownerDocument?.documentElement||n.ownerDocument?.body||document.scrollingElement||document.documentElement||document.body)?.scrollHeight??document.body.scrollHeight??0,r=n.ownerDocument?.defaultView?.innerHeight??window.innerHeight,g=Math.max(0,h-r)*(i/100);return n.ownerDocument?.defaultView?.scrollTo({top:g,left:n.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:"smooth"}),!0}let u=n.scrollHeight??0,a=n.clientHeight??0,c=Math.max(0,u-a)*(i/100);return n.scrollTo({top:c,left:n.scrollLeft??0,behavior:"smooth"}),!0}catch{return!1}}',
|
|
2111
|
-
"selectElementOptions": 'function I(t){try{if(!(this instanceof HTMLSelectElement))return[];let e=Array.isArray(t)?t:[t],i=new Set(e.map(u=>String(u??"").trim())),n=u=>{let a=(u.label||u.textContent||"").trim(),l=String(u.value??"").trim();return i.has(a)||i.has(l)};if(this.multiple)for(let u of Array.from(this.options))u.selected=n(u);else{let u=!1;for(let a of Array.from(this.options))!u&&n(a)?(a.selected=!0,this.value=a.value,u=!0):a.selected=!1}let s=new Event("input",{bubbles:!0}),y=new Event("change",{bubbles:!0});return this.dispatchEvent(s),this.dispatchEvent(y),Array.from(this.selectedOptions).map(u=>u.value)}catch{return[]}}'
|
|
2112
|
-
};
|
|
2113
|
-
locatorScriptGlobalRefs = {
|
|
2114
|
-
"assignFilePayloadsToInputElement": "globalThis.__stagehandLocatorScripts.assignFilePayloadsToInputElement",
|
|
2115
|
-
"countCssMatchesPierce": "globalThis.__stagehandLocatorScripts.countCssMatchesPierce",
|
|
2116
|
-
"countCssMatchesPrimary": "globalThis.__stagehandLocatorScripts.countCssMatchesPrimary",
|
|
2117
|
-
"countTextMatches": "globalThis.__stagehandLocatorScripts.countTextMatches",
|
|
2118
|
-
"countXPathMatchesMainWorld": "globalThis.__stagehandLocatorScripts.countXPathMatchesMainWorld",
|
|
2119
|
-
"dispatchDomClick": "globalThis.__stagehandLocatorScripts.dispatchDomClick",
|
|
2120
|
-
"ensureFileInputElement": "globalThis.__stagehandLocatorScripts.ensureFileInputElement",
|
|
2121
|
-
"fillElementValue": "globalThis.__stagehandLocatorScripts.fillElementValue",
|
|
2122
|
-
"focusElement": "globalThis.__stagehandLocatorScripts.focusElement",
|
|
2123
|
-
"isElementChecked": "globalThis.__stagehandLocatorScripts.isElementChecked",
|
|
2124
|
-
"isElementVisible": "globalThis.__stagehandLocatorScripts.isElementVisible",
|
|
2125
|
-
"prepareElementForTyping": "globalThis.__stagehandLocatorScripts.prepareElementForTyping",
|
|
2126
|
-
"readElementInnerHTML": "globalThis.__stagehandLocatorScripts.readElementInnerHTML",
|
|
2127
|
-
"readElementInnerText": "globalThis.__stagehandLocatorScripts.readElementInnerText",
|
|
2128
|
-
"readElementInputValue": "globalThis.__stagehandLocatorScripts.readElementInputValue",
|
|
2129
|
-
"readElementTextContent": "globalThis.__stagehandLocatorScripts.readElementTextContent",
|
|
2130
|
-
"resolveCssSelector": "globalThis.__stagehandLocatorScripts.resolveCssSelector",
|
|
2131
|
-
"resolveCssSelectorPierce": "globalThis.__stagehandLocatorScripts.resolveCssSelectorPierce",
|
|
2132
|
-
"resolveTextSelector": "globalThis.__stagehandLocatorScripts.resolveTextSelector",
|
|
2133
|
-
"resolveXPathMainWorld": "globalThis.__stagehandLocatorScripts.resolveXPathMainWorld",
|
|
2134
|
-
"scrollElementToPercent": "globalThis.__stagehandLocatorScripts.scrollElementToPercent",
|
|
2135
|
-
"selectElementOptions": "globalThis.__stagehandLocatorScripts.selectElementOptions"
|
|
2136
|
-
};
|
|
2137
|
-
}
|
|
2138
|
-
});
|
|
2139
|
-
|
|
2140
2053
|
// lib/v3/understudy/selectorResolver.ts
|
|
2141
2054
|
var FrameSelectorResolver;
|
|
2142
2055
|
var init_selectorResolver = __esm({
|
|
@@ -14877,11 +14790,11 @@ var require_bignumber = __commonJS({
|
|
|
14877
14790
|
return n > 0 || n === i2 ? i2 : i2 - 1;
|
|
14878
14791
|
}
|
|
14879
14792
|
function coeffToString(a) {
|
|
14880
|
-
var s2,
|
|
14793
|
+
var s2, z71, i2 = 1, j = a.length, r2 = a[0] + "";
|
|
14881
14794
|
for (; i2 < j; ) {
|
|
14882
14795
|
s2 = a[i2++] + "";
|
|
14883
|
-
|
|
14884
|
-
for (;
|
|
14796
|
+
z71 = LOG_BASE - s2.length;
|
|
14797
|
+
for (; z71--; s2 = "0" + s2) ;
|
|
14885
14798
|
r2 += s2;
|
|
14886
14799
|
}
|
|
14887
14800
|
for (j = r2.length; r2.charCodeAt(--j) === 48; ) ;
|
|
@@ -14914,15 +14827,15 @@ var require_bignumber = __commonJS({
|
|
|
14914
14827
|
function toExponential(str, e2) {
|
|
14915
14828
|
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e2 < 0 ? "e" : "e+") + e2;
|
|
14916
14829
|
}
|
|
14917
|
-
function toFixedPoint(str, e2,
|
|
14830
|
+
function toFixedPoint(str, e2, z71) {
|
|
14918
14831
|
var len, zs;
|
|
14919
14832
|
if (e2 < 0) {
|
|
14920
|
-
for (zs =
|
|
14833
|
+
for (zs = z71 + "."; ++e2; zs += z71) ;
|
|
14921
14834
|
str = zs + str;
|
|
14922
14835
|
} else {
|
|
14923
14836
|
len = str.length;
|
|
14924
14837
|
if (++e2 > len) {
|
|
14925
|
-
for (zs =
|
|
14838
|
+
for (zs = z71, e2 -= len; --e2; zs += z71) ;
|
|
14926
14839
|
str += zs;
|
|
14927
14840
|
} else if (e2 < len) {
|
|
14928
14841
|
str = str.slice(0, e2) + "." + str.slice(e2);
|
|
@@ -26522,14 +26435,38 @@ var init_page = __esm({
|
|
|
26522
26435
|
}));
|
|
26523
26436
|
return;
|
|
26524
26437
|
}
|
|
26438
|
+
const isLetter = /^[a-zA-Z]$/.test(ch);
|
|
26439
|
+
const isDigit = /^[0-9]$/.test(ch);
|
|
26440
|
+
let key = ch;
|
|
26441
|
+
let code = "";
|
|
26442
|
+
let windowsVirtualKeyCode;
|
|
26443
|
+
if (isLetter) {
|
|
26444
|
+
key = ch;
|
|
26445
|
+
code = `Key${ch.toUpperCase()}`;
|
|
26446
|
+
windowsVirtualKeyCode = ch.toUpperCase().charCodeAt(0);
|
|
26447
|
+
} else if (isDigit) {
|
|
26448
|
+
key = ch;
|
|
26449
|
+
code = `Digit${ch}`;
|
|
26450
|
+
windowsVirtualKeyCode = ch.charCodeAt(0);
|
|
26451
|
+
} else if (ch === " ") {
|
|
26452
|
+
key = " ";
|
|
26453
|
+
code = "Space";
|
|
26454
|
+
windowsVirtualKeyCode = 32;
|
|
26455
|
+
}
|
|
26525
26456
|
const down = {
|
|
26526
26457
|
type: "keyDown",
|
|
26458
|
+
key,
|
|
26459
|
+
code: code || void 0,
|
|
26527
26460
|
text: ch,
|
|
26528
|
-
unmodifiedText: ch
|
|
26461
|
+
unmodifiedText: ch,
|
|
26462
|
+
windowsVirtualKeyCode
|
|
26529
26463
|
};
|
|
26530
26464
|
yield this.mainSession.send("Input.dispatchKeyEvent", down);
|
|
26531
26465
|
yield this.mainSession.send("Input.dispatchKeyEvent", {
|
|
26532
|
-
type: "keyUp"
|
|
26466
|
+
type: "keyUp",
|
|
26467
|
+
key,
|
|
26468
|
+
code: code || void 0,
|
|
26469
|
+
windowsVirtualKeyCode
|
|
26533
26470
|
});
|
|
26534
26471
|
});
|
|
26535
26472
|
const pressBackspace = () => __async(this, null, function* () {
|
|
@@ -26721,10 +26658,11 @@ var init_page = __esm({
|
|
|
26721
26658
|
});
|
|
26722
26659
|
});
|
|
26723
26660
|
}
|
|
26724
|
-
/** Normalize
|
|
26661
|
+
/** Normalize key names to match CDP expectations */
|
|
26725
26662
|
normalizeModifierKey(key) {
|
|
26726
|
-
const
|
|
26727
|
-
switch (
|
|
26663
|
+
const lower2 = key.toLowerCase();
|
|
26664
|
+
switch (lower2) {
|
|
26665
|
+
// Modifier keys
|
|
26728
26666
|
case "cmd":
|
|
26729
26667
|
case "command":
|
|
26730
26668
|
return this.isMacOS() ? "Meta" : "Control";
|
|
@@ -26732,11 +26670,56 @@ var init_page = __esm({
|
|
|
26732
26670
|
case "windows":
|
|
26733
26671
|
return "Meta";
|
|
26734
26672
|
case "ctrl":
|
|
26673
|
+
case "control":
|
|
26735
26674
|
return "Control";
|
|
26736
26675
|
case "option":
|
|
26676
|
+
case "alt":
|
|
26737
26677
|
return "Alt";
|
|
26738
26678
|
case "shift":
|
|
26739
26679
|
return "Shift";
|
|
26680
|
+
case "meta":
|
|
26681
|
+
return "Meta";
|
|
26682
|
+
// Action keys
|
|
26683
|
+
case "enter":
|
|
26684
|
+
case "return":
|
|
26685
|
+
return "Enter";
|
|
26686
|
+
case "esc":
|
|
26687
|
+
case "escape":
|
|
26688
|
+
return "Escape";
|
|
26689
|
+
case "backspace":
|
|
26690
|
+
return "Backspace";
|
|
26691
|
+
case "tab":
|
|
26692
|
+
return "Tab";
|
|
26693
|
+
case "space":
|
|
26694
|
+
case "spacebar":
|
|
26695
|
+
return " ";
|
|
26696
|
+
case "delete":
|
|
26697
|
+
case "del":
|
|
26698
|
+
return "Delete";
|
|
26699
|
+
// Arrow keys
|
|
26700
|
+
case "left":
|
|
26701
|
+
case "arrowleft":
|
|
26702
|
+
return "ArrowLeft";
|
|
26703
|
+
case "right":
|
|
26704
|
+
case "arrowright":
|
|
26705
|
+
return "ArrowRight";
|
|
26706
|
+
case "up":
|
|
26707
|
+
case "arrowup":
|
|
26708
|
+
return "ArrowUp";
|
|
26709
|
+
case "down":
|
|
26710
|
+
case "arrowdown":
|
|
26711
|
+
return "ArrowDown";
|
|
26712
|
+
// Navigation keys
|
|
26713
|
+
case "home":
|
|
26714
|
+
return "Home";
|
|
26715
|
+
case "end":
|
|
26716
|
+
return "End";
|
|
26717
|
+
case "pageup":
|
|
26718
|
+
case "pgup":
|
|
26719
|
+
return "PageUp";
|
|
26720
|
+
case "pagedown":
|
|
26721
|
+
case "pgdn":
|
|
26722
|
+
return "PageDown";
|
|
26740
26723
|
default:
|
|
26741
26724
|
return key;
|
|
26742
26725
|
}
|
|
@@ -30769,10 +30752,10 @@ var ObserveHandler = class {
|
|
|
30769
30752
|
}
|
|
30770
30753
|
};
|
|
30771
30754
|
|
|
30772
|
-
// lib/v3/agent/tools/
|
|
30755
|
+
// lib/v3/agent/tools/goto.ts
|
|
30773
30756
|
var import_ai = require("ai");
|
|
30774
30757
|
var import_zod5 = require("zod");
|
|
30775
|
-
var
|
|
30758
|
+
var gotoTool = (v3) => (0, import_ai.tool)({
|
|
30776
30759
|
description: "Navigate to a specific URL",
|
|
30777
30760
|
inputSchema: import_zod5.z.object({
|
|
30778
30761
|
url: import_zod5.z.string().describe("The URL to navigate to")
|
|
@@ -30801,10 +30784,10 @@ var createGotoTool = (v3) => (0, import_ai.tool)({
|
|
|
30801
30784
|
})
|
|
30802
30785
|
});
|
|
30803
30786
|
|
|
30804
|
-
// lib/v3/agent/tools/
|
|
30787
|
+
// lib/v3/agent/tools/act.ts
|
|
30805
30788
|
var import_ai2 = require("ai");
|
|
30806
30789
|
var import_zod6 = require("zod");
|
|
30807
|
-
var
|
|
30790
|
+
var actTool = (v3, executionModel) => (0, import_ai2.tool)({
|
|
30808
30791
|
description: "Perform an action on the page (click, type). Provide a short, specific phrase that mentions the element type.",
|
|
30809
30792
|
inputSchema: import_zod6.z.object({
|
|
30810
30793
|
action: import_zod6.z.string().describe(
|
|
@@ -30846,10 +30829,10 @@ var createActTool = (v3, executionModel) => (0, import_ai2.tool)({
|
|
|
30846
30829
|
})
|
|
30847
30830
|
});
|
|
30848
30831
|
|
|
30849
|
-
// lib/v3/agent/tools/
|
|
30832
|
+
// lib/v3/agent/tools/screenshot.ts
|
|
30850
30833
|
var import_ai3 = require("ai");
|
|
30851
30834
|
var import_zod7 = require("zod");
|
|
30852
|
-
var
|
|
30835
|
+
var screenshotTool = (v3) => (0, import_ai3.tool)({
|
|
30853
30836
|
description: "Takes a screenshot (PNG) of the current page. Use this to quickly verify page state.",
|
|
30854
30837
|
inputSchema: import_zod7.z.object({}),
|
|
30855
30838
|
execute: () => __async(null, null, function* () {
|
|
@@ -30873,10 +30856,10 @@ var createScreenshotTool = (v3) => (0, import_ai3.tool)({
|
|
|
30873
30856
|
})
|
|
30874
30857
|
});
|
|
30875
30858
|
|
|
30876
|
-
// lib/v3/agent/tools/
|
|
30859
|
+
// lib/v3/agent/tools/wait.ts
|
|
30877
30860
|
var import_ai4 = require("ai");
|
|
30878
30861
|
var import_zod8 = require("zod");
|
|
30879
|
-
var
|
|
30862
|
+
var waitTool = (v3) => (0, import_ai4.tool)({
|
|
30880
30863
|
description: "Wait for a specified time",
|
|
30881
30864
|
inputSchema: import_zod8.z.object({
|
|
30882
30865
|
timeMs: import_zod8.z.number().describe("Time in milliseconds")
|
|
@@ -30901,10 +30884,10 @@ var createWaitTool = (v3) => (0, import_ai4.tool)({
|
|
|
30901
30884
|
})
|
|
30902
30885
|
});
|
|
30903
30886
|
|
|
30904
|
-
// lib/v3/agent/tools/
|
|
30887
|
+
// lib/v3/agent/tools/navback.ts
|
|
30905
30888
|
var import_ai5 = require("ai");
|
|
30906
30889
|
var import_zod9 = require("zod");
|
|
30907
|
-
var
|
|
30890
|
+
var navBackTool = (v3) => (0, import_ai5.tool)({
|
|
30908
30891
|
description: "Navigate back to the previous page",
|
|
30909
30892
|
inputSchema: import_zod9.z.object({
|
|
30910
30893
|
reasoningText: import_zod9.z.string().describe("Why you're going back")
|
|
@@ -30925,10 +30908,10 @@ var createNavBackTool = (v3) => (0, import_ai5.tool)({
|
|
|
30925
30908
|
})
|
|
30926
30909
|
});
|
|
30927
30910
|
|
|
30928
|
-
// lib/v3/agent/tools/
|
|
30911
|
+
// lib/v3/agent/tools/close.ts
|
|
30929
30912
|
var import_ai6 = require("ai");
|
|
30930
30913
|
var import_zod10 = require("zod");
|
|
30931
|
-
var
|
|
30914
|
+
var closeTool = () => (0, import_ai6.tool)({
|
|
30932
30915
|
description: "Complete the task and close",
|
|
30933
30916
|
inputSchema: import_zod10.z.object({
|
|
30934
30917
|
reasoning: import_zod10.z.string().describe("Summary of what was accomplished"),
|
|
@@ -30939,10 +30922,10 @@ var createCloseTool = () => (0, import_ai6.tool)({
|
|
|
30939
30922
|
})
|
|
30940
30923
|
});
|
|
30941
30924
|
|
|
30942
|
-
// lib/v3/agent/tools/
|
|
30925
|
+
// lib/v3/agent/tools/ariaTree.ts
|
|
30943
30926
|
var import_ai7 = require("ai");
|
|
30944
30927
|
var import_zod11 = require("zod");
|
|
30945
|
-
var
|
|
30928
|
+
var ariaTreeTool = (v3) => (0, import_ai7.tool)({
|
|
30946
30929
|
description: "gets the accessibility (ARIA) hybrid tree text for the current page. use this to understand structure and content.",
|
|
30947
30930
|
inputSchema: import_zod11.z.object({}),
|
|
30948
30931
|
execute: () => __async(null, null, function* () {
|
|
@@ -30970,10 +30953,10 @@ ${result.content}` }]
|
|
|
30970
30953
|
})
|
|
30971
30954
|
});
|
|
30972
30955
|
|
|
30973
|
-
// lib/v3/agent/tools/
|
|
30956
|
+
// lib/v3/agent/tools/fillform.ts
|
|
30974
30957
|
var import_ai8 = require("ai");
|
|
30975
30958
|
var import_zod12 = require("zod");
|
|
30976
|
-
var
|
|
30959
|
+
var fillFormTool = (v3, executionModel) => (0, import_ai8.tool)({
|
|
30977
30960
|
description: `\u{1F4DD} FORM FILL - MULTI-FIELD INPUT TOOL
|
|
30978
30961
|
For any form with 2+ inputs/textareas. Faster than individual typing.`,
|
|
30979
30962
|
inputSchema: import_zod12.z.object({
|
|
@@ -31024,32 +31007,56 @@ For any form with 2+ inputs/textareas. Faster than individual typing.`,
|
|
|
31024
31007
|
})
|
|
31025
31008
|
});
|
|
31026
31009
|
|
|
31027
|
-
// lib/v3/agent/tools/
|
|
31010
|
+
// lib/v3/agent/tools/scroll.ts
|
|
31028
31011
|
var import_ai9 = require("ai");
|
|
31029
31012
|
var import_zod13 = require("zod");
|
|
31030
|
-
|
|
31031
|
-
|
|
31013
|
+
|
|
31014
|
+
// lib/v3/agent/utils/coordinateNormalization.ts
|
|
31015
|
+
var DEFAULT_VIEWPORT = { width: 1288, height: 711 };
|
|
31016
|
+
function isGoogleProvider(provider) {
|
|
31017
|
+
if (!provider) return false;
|
|
31018
|
+
return provider.toLowerCase().includes("google");
|
|
31019
|
+
}
|
|
31020
|
+
function normalizeGoogleCoordinates(x2, y) {
|
|
31021
|
+
const clampedX = Math.min(999, Math.max(0, x2));
|
|
31022
|
+
const clampedY = Math.min(999, Math.max(0, y));
|
|
31023
|
+
return {
|
|
31024
|
+
x: Math.floor(clampedX / 1e3 * DEFAULT_VIEWPORT.width),
|
|
31025
|
+
y: Math.floor(clampedY / 1e3 * DEFAULT_VIEWPORT.height)
|
|
31026
|
+
};
|
|
31027
|
+
}
|
|
31028
|
+
function processCoordinates(x2, y, provider) {
|
|
31029
|
+
if (isGoogleProvider(provider)) {
|
|
31030
|
+
return normalizeGoogleCoordinates(x2, y);
|
|
31031
|
+
}
|
|
31032
|
+
return { x: x2, y };
|
|
31033
|
+
}
|
|
31034
|
+
|
|
31035
|
+
// lib/v3/agent/tools/scroll.ts
|
|
31036
|
+
var scrollTool = (v3) => (0, import_ai9.tool)({
|
|
31037
|
+
description: "Scroll the page up or down by a percentage of the viewport height. Default is 80%, and what should be typically used for general page scrolling",
|
|
31032
31038
|
inputSchema: import_zod13.z.object({
|
|
31033
|
-
|
|
31034
|
-
|
|
31039
|
+
direction: import_zod13.z.enum(["up", "down"]),
|
|
31040
|
+
percentage: import_zod13.z.number().min(1).max(200).optional()
|
|
31035
31041
|
}),
|
|
31036
|
-
execute: (_0) => __async(null, [_0], function* ({
|
|
31042
|
+
execute: (_0) => __async(null, [_0], function* ({ direction, percentage = 80 }) {
|
|
31037
31043
|
v3.logger({
|
|
31038
31044
|
category: "agent",
|
|
31039
31045
|
message: `Agent calling tool: scroll`,
|
|
31040
31046
|
level: 1,
|
|
31041
31047
|
auxiliary: {
|
|
31042
31048
|
arguments: {
|
|
31043
|
-
value: JSON.stringify({
|
|
31049
|
+
value: JSON.stringify({ direction, percentage }),
|
|
31044
31050
|
type: "object"
|
|
31045
31051
|
}
|
|
31046
31052
|
}
|
|
31047
31053
|
});
|
|
31048
31054
|
const page = yield v3.context.awaitActivePage();
|
|
31049
31055
|
const { w, h: h2 } = yield page.mainFrame().evaluate("({ w: window.innerWidth, h: window.innerHeight })");
|
|
31050
|
-
const
|
|
31051
|
-
const
|
|
31052
|
-
const
|
|
31056
|
+
const scrollDistance = Math.round(h2 * percentage / 100);
|
|
31057
|
+
const cx = Math.floor(w / 2);
|
|
31058
|
+
const cy = Math.floor(h2 / 2);
|
|
31059
|
+
const deltaY = direction === "up" ? -scrollDistance : scrollDistance;
|
|
31053
31060
|
yield page.scroll(cx, cy, 0, deltaY);
|
|
31054
31061
|
v3.recordAgentReplayStep({
|
|
31055
31062
|
type: "scroll",
|
|
@@ -31057,11 +31064,73 @@ var createScrollTool = (v3) => (0, import_ai9.tool)({
|
|
|
31057
31064
|
deltaY,
|
|
31058
31065
|
anchor: { x: cx, y: cy }
|
|
31059
31066
|
});
|
|
31060
|
-
return {
|
|
31067
|
+
return {
|
|
31068
|
+
success: true,
|
|
31069
|
+
message: `Scrolled ${percentage}% ${direction} (${scrollDistance}px)`,
|
|
31070
|
+
scrolledPixels: scrollDistance
|
|
31071
|
+
};
|
|
31072
|
+
})
|
|
31073
|
+
});
|
|
31074
|
+
var scrollVisionTool = (v3, provider) => (0, import_ai9.tool)({
|
|
31075
|
+
description: `Scroll the page up or down. For general page scrolling, no coordinates needed. Only provide coordinates when scrolling inside a nested scrollable element (e.g., a dropdown menu, modal with overflow, or scrollable sidebar). Default is 80%, and what should be typically used for general page scrolling`,
|
|
31076
|
+
inputSchema: import_zod13.z.object({
|
|
31077
|
+
direction: import_zod13.z.enum(["up", "down"]),
|
|
31078
|
+
coordinates: import_zod13.z.array(import_zod13.z.number()).optional().describe(
|
|
31079
|
+
"Only use coordinates for scrolling inside a nested scrollable element - provide (x, y) within that element"
|
|
31080
|
+
),
|
|
31081
|
+
percentage: import_zod13.z.number().min(1).max(200).optional()
|
|
31082
|
+
}),
|
|
31083
|
+
execute: (_0) => __async(null, [_0], function* ({ direction, coordinates, percentage = 80 }) {
|
|
31084
|
+
const page = yield v3.context.awaitActivePage();
|
|
31085
|
+
const { w, h: h2 } = yield page.mainFrame().evaluate("({ w: window.innerWidth, h: window.innerHeight })");
|
|
31086
|
+
let cx;
|
|
31087
|
+
let cy;
|
|
31088
|
+
if (coordinates) {
|
|
31089
|
+
const processed = processCoordinates(
|
|
31090
|
+
coordinates[0],
|
|
31091
|
+
coordinates[1],
|
|
31092
|
+
provider
|
|
31093
|
+
);
|
|
31094
|
+
cx = processed.x;
|
|
31095
|
+
cy = processed.y;
|
|
31096
|
+
} else {
|
|
31097
|
+
cx = Math.floor(w / 2);
|
|
31098
|
+
cy = Math.floor(h2 / 2);
|
|
31099
|
+
}
|
|
31100
|
+
v3.logger({
|
|
31101
|
+
category: "agent",
|
|
31102
|
+
message: `Agent calling tool: scroll`,
|
|
31103
|
+
level: 1,
|
|
31104
|
+
auxiliary: {
|
|
31105
|
+
arguments: {
|
|
31106
|
+
value: JSON.stringify({
|
|
31107
|
+
direction,
|
|
31108
|
+
coordinates,
|
|
31109
|
+
percentage,
|
|
31110
|
+
processed: { cx, cy }
|
|
31111
|
+
}),
|
|
31112
|
+
type: "object"
|
|
31113
|
+
}
|
|
31114
|
+
}
|
|
31115
|
+
});
|
|
31116
|
+
const scrollDistance = Math.round(h2 * percentage / 100);
|
|
31117
|
+
const deltaY = direction === "up" ? -scrollDistance : scrollDistance;
|
|
31118
|
+
yield page.scroll(cx, cy, 0, deltaY);
|
|
31119
|
+
v3.recordAgentReplayStep({
|
|
31120
|
+
type: "scroll",
|
|
31121
|
+
deltaX: 0,
|
|
31122
|
+
deltaY,
|
|
31123
|
+
anchor: { x: cx, y: cy }
|
|
31124
|
+
});
|
|
31125
|
+
return {
|
|
31126
|
+
success: true,
|
|
31127
|
+
message: coordinates ? `Scrolled ${percentage}% ${direction} at (${cx}, ${cy})` : `Scrolled ${percentage}% ${direction}`,
|
|
31128
|
+
scrolledPixels: scrollDistance
|
|
31129
|
+
};
|
|
31061
31130
|
})
|
|
31062
31131
|
});
|
|
31063
31132
|
|
|
31064
|
-
// lib/v3/agent/tools/
|
|
31133
|
+
// lib/v3/agent/tools/extract.ts
|
|
31065
31134
|
var import_ai10 = require("ai");
|
|
31066
31135
|
var import_zod14 = require("zod");
|
|
31067
31136
|
function evaluateZodSchema(schemaStr, logger) {
|
|
@@ -31078,7 +31147,7 @@ function evaluateZodSchema(schemaStr, logger) {
|
|
|
31078
31147
|
return import_zod14.z.any();
|
|
31079
31148
|
}
|
|
31080
31149
|
}
|
|
31081
|
-
var
|
|
31150
|
+
var extractTool = (v3, executionModel, logger) => (0, import_ai10.tool)({
|
|
31082
31151
|
description: `Extract structured data from the current page based on a provided schema.
|
|
31083
31152
|
|
|
31084
31153
|
USAGE GUIDELINES:
|
|
@@ -31113,25 +31182,677 @@ var createExtractTool = (v3, executionModel, logger) => (0, import_ai10.tool)({
|
|
|
31113
31182
|
})
|
|
31114
31183
|
});
|
|
31115
31184
|
|
|
31185
|
+
// lib/v3/agent/tools/click.ts
|
|
31186
|
+
var import_ai11 = require("ai");
|
|
31187
|
+
var import_zod15 = require("zod");
|
|
31188
|
+
function waitForTimeout(ms) {
|
|
31189
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
31190
|
+
}
|
|
31191
|
+
var clickTool = (v3, provider) => (0, import_ai11.tool)({
|
|
31192
|
+
description: "Click on an element using its coordinates (this is the most reliable way to click on an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)",
|
|
31193
|
+
inputSchema: import_zod15.z.object({
|
|
31194
|
+
describe: import_zod15.z.string().describe(
|
|
31195
|
+
"Describe the element to click on in a short, specific phrase that mentions the element type and a good visual description"
|
|
31196
|
+
),
|
|
31197
|
+
coordinates: import_zod15.z.array(import_zod15.z.number()).describe("The (x, y) coordinates to click on")
|
|
31198
|
+
}),
|
|
31199
|
+
execute: (_0) => __async(null, [_0], function* ({ describe, coordinates }) {
|
|
31200
|
+
try {
|
|
31201
|
+
const page = yield v3.context.awaitActivePage();
|
|
31202
|
+
const processed = processCoordinates(
|
|
31203
|
+
coordinates[0],
|
|
31204
|
+
coordinates[1],
|
|
31205
|
+
provider
|
|
31206
|
+
);
|
|
31207
|
+
v3.logger({
|
|
31208
|
+
category: "agent",
|
|
31209
|
+
message: `Agent calling tool: click`,
|
|
31210
|
+
level: 1,
|
|
31211
|
+
auxiliary: {
|
|
31212
|
+
arguments: {
|
|
31213
|
+
value: JSON.stringify({ describe, coordinates, processed }),
|
|
31214
|
+
type: "string"
|
|
31215
|
+
}
|
|
31216
|
+
}
|
|
31217
|
+
});
|
|
31218
|
+
yield page.click(processed.x, processed.y);
|
|
31219
|
+
if (isGoogleProvider(provider)) {
|
|
31220
|
+
yield waitForTimeout(1e3);
|
|
31221
|
+
}
|
|
31222
|
+
v3.recordAgentReplayStep({
|
|
31223
|
+
type: "click",
|
|
31224
|
+
instruction: describe,
|
|
31225
|
+
playwrightArguments: { coordinates: [processed.x, processed.y] }
|
|
31226
|
+
});
|
|
31227
|
+
return {
|
|
31228
|
+
success: true,
|
|
31229
|
+
describe,
|
|
31230
|
+
coordinates: [processed.x, processed.y]
|
|
31231
|
+
};
|
|
31232
|
+
} catch (error) {
|
|
31233
|
+
return {
|
|
31234
|
+
success: false,
|
|
31235
|
+
error: `Error clicking: ${error.message}`
|
|
31236
|
+
};
|
|
31237
|
+
}
|
|
31238
|
+
})
|
|
31239
|
+
});
|
|
31240
|
+
|
|
31241
|
+
// lib/v3/agent/tools/type.ts
|
|
31242
|
+
var import_ai12 = require("ai");
|
|
31243
|
+
var import_zod16 = require("zod");
|
|
31244
|
+
function waitForTimeout2(ms) {
|
|
31245
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
31246
|
+
}
|
|
31247
|
+
var typeTool = (v3, provider) => (0, import_ai12.tool)({
|
|
31248
|
+
description: "Type text into an element using its coordinates. This will click the element and then type the text into it (this is the most reliable way to type into an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)",
|
|
31249
|
+
inputSchema: import_zod16.z.object({
|
|
31250
|
+
describe: import_zod16.z.string().describe(
|
|
31251
|
+
"Describe the element to type into in a short, specific phrase that mentions the element type and a good visual description"
|
|
31252
|
+
),
|
|
31253
|
+
text: import_zod16.z.string().describe("The text to type into the element"),
|
|
31254
|
+
coordinates: import_zod16.z.array(import_zod16.z.number()).describe("The (x, y) coordinates to type into the element")
|
|
31255
|
+
}),
|
|
31256
|
+
execute: (_0) => __async(null, [_0], function* ({ describe, coordinates, text }) {
|
|
31257
|
+
try {
|
|
31258
|
+
const page = yield v3.context.awaitActivePage();
|
|
31259
|
+
const processed = processCoordinates(
|
|
31260
|
+
coordinates[0],
|
|
31261
|
+
coordinates[1],
|
|
31262
|
+
provider
|
|
31263
|
+
);
|
|
31264
|
+
v3.logger({
|
|
31265
|
+
category: "agent",
|
|
31266
|
+
message: `Agent calling tool: type`,
|
|
31267
|
+
level: 1,
|
|
31268
|
+
auxiliary: {
|
|
31269
|
+
arguments: {
|
|
31270
|
+
value: JSON.stringify({ describe, coordinates, processed, text }),
|
|
31271
|
+
type: "string"
|
|
31272
|
+
}
|
|
31273
|
+
}
|
|
31274
|
+
});
|
|
31275
|
+
yield page.click(processed.x, processed.y);
|
|
31276
|
+
if (isGoogleProvider(provider)) {
|
|
31277
|
+
yield waitForTimeout2(1e3);
|
|
31278
|
+
}
|
|
31279
|
+
yield page.type(text);
|
|
31280
|
+
v3.recordAgentReplayStep({
|
|
31281
|
+
type: "type",
|
|
31282
|
+
instruction: describe,
|
|
31283
|
+
playwrightArguments: {
|
|
31284
|
+
coordinates: [processed.x, processed.y],
|
|
31285
|
+
text
|
|
31286
|
+
}
|
|
31287
|
+
});
|
|
31288
|
+
return { success: true, describe, text };
|
|
31289
|
+
} catch (error) {
|
|
31290
|
+
return {
|
|
31291
|
+
success: false,
|
|
31292
|
+
error: `Error typing: ${error.message}`
|
|
31293
|
+
};
|
|
31294
|
+
}
|
|
31295
|
+
})
|
|
31296
|
+
});
|
|
31297
|
+
|
|
31298
|
+
// lib/v3/agent/tools/dragAndDrop.ts
|
|
31299
|
+
var import_ai13 = require("ai");
|
|
31300
|
+
var import_zod17 = require("zod");
|
|
31301
|
+
var dragAndDropTool = (v3, provider) => (0, import_ai13.tool)({
|
|
31302
|
+
description: "Drag and drop an element using its coordinates (this is the most reliable way to drag and drop an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)",
|
|
31303
|
+
inputSchema: import_zod17.z.object({
|
|
31304
|
+
describe: import_zod17.z.string().describe("Describe the element to drag and drop"),
|
|
31305
|
+
startCoordinates: import_zod17.z.array(import_zod17.z.number()).describe("The (x, y) coordinates to start the drag and drop from"),
|
|
31306
|
+
endCoordinates: import_zod17.z.array(import_zod17.z.number()).describe("The (x, y) coordinates to end the drag and drop at")
|
|
31307
|
+
}),
|
|
31308
|
+
execute: (_0) => __async(null, [_0], function* ({ describe, startCoordinates, endCoordinates }) {
|
|
31309
|
+
try {
|
|
31310
|
+
const page = yield v3.context.awaitActivePage();
|
|
31311
|
+
const processedStart = processCoordinates(
|
|
31312
|
+
startCoordinates[0],
|
|
31313
|
+
startCoordinates[1],
|
|
31314
|
+
provider
|
|
31315
|
+
);
|
|
31316
|
+
const processedEnd = processCoordinates(
|
|
31317
|
+
endCoordinates[0],
|
|
31318
|
+
endCoordinates[1],
|
|
31319
|
+
provider
|
|
31320
|
+
);
|
|
31321
|
+
v3.logger({
|
|
31322
|
+
category: "agent",
|
|
31323
|
+
message: `Agent calling tool: dragAndDrop`,
|
|
31324
|
+
level: 1,
|
|
31325
|
+
auxiliary: {
|
|
31326
|
+
arguments: {
|
|
31327
|
+
value: JSON.stringify({
|
|
31328
|
+
describe,
|
|
31329
|
+
startCoordinates,
|
|
31330
|
+
endCoordinates,
|
|
31331
|
+
processedStart,
|
|
31332
|
+
processedEnd
|
|
31333
|
+
}),
|
|
31334
|
+
type: "string"
|
|
31335
|
+
}
|
|
31336
|
+
}
|
|
31337
|
+
});
|
|
31338
|
+
yield page.dragAndDrop(
|
|
31339
|
+
processedStart.x,
|
|
31340
|
+
processedStart.y,
|
|
31341
|
+
processedEnd.x,
|
|
31342
|
+
processedEnd.y
|
|
31343
|
+
);
|
|
31344
|
+
v3.recordAgentReplayStep({
|
|
31345
|
+
type: "dragAndDrop",
|
|
31346
|
+
instruction: describe,
|
|
31347
|
+
playwrightArguments: {
|
|
31348
|
+
startCoordinates: [processedStart.x, processedStart.y],
|
|
31349
|
+
endCoordinates: [processedEnd.x, processedEnd.y]
|
|
31350
|
+
}
|
|
31351
|
+
});
|
|
31352
|
+
return { success: true, describe };
|
|
31353
|
+
} catch (error) {
|
|
31354
|
+
return {
|
|
31355
|
+
success: false,
|
|
31356
|
+
error: `Error dragging: ${error.message}`
|
|
31357
|
+
};
|
|
31358
|
+
}
|
|
31359
|
+
})
|
|
31360
|
+
});
|
|
31361
|
+
|
|
31362
|
+
// lib/v3/agent/tools/clickAndHold.ts
|
|
31363
|
+
var import_ai14 = require("ai");
|
|
31364
|
+
var import_zod18 = require("zod");
|
|
31365
|
+
var clickAndHoldTool = (v3, provider) => (0, import_ai14.tool)({
|
|
31366
|
+
description: "Click and hold on an element using its coordinates",
|
|
31367
|
+
inputSchema: import_zod18.z.object({
|
|
31368
|
+
describe: import_zod18.z.string().describe(
|
|
31369
|
+
"Describe the element to click on in a short, specific phrase that mentions the element type and a good visual description"
|
|
31370
|
+
),
|
|
31371
|
+
duration: import_zod18.z.number().describe("The duration to hold the element in milliseconds"),
|
|
31372
|
+
coordinates: import_zod18.z.array(import_zod18.z.number()).describe("The (x, y) coordinates to click on")
|
|
31373
|
+
}),
|
|
31374
|
+
execute: (_0) => __async(null, [_0], function* ({ describe, coordinates, duration }) {
|
|
31375
|
+
try {
|
|
31376
|
+
const page = yield v3.context.awaitActivePage();
|
|
31377
|
+
const processed = processCoordinates(
|
|
31378
|
+
coordinates[0],
|
|
31379
|
+
coordinates[1],
|
|
31380
|
+
provider
|
|
31381
|
+
);
|
|
31382
|
+
v3.logger({
|
|
31383
|
+
category: "agent",
|
|
31384
|
+
message: `Agent calling tool: clickAndHold`,
|
|
31385
|
+
level: 1,
|
|
31386
|
+
auxiliary: {
|
|
31387
|
+
arguments: {
|
|
31388
|
+
value: JSON.stringify({
|
|
31389
|
+
describe,
|
|
31390
|
+
coordinates,
|
|
31391
|
+
processed,
|
|
31392
|
+
duration
|
|
31393
|
+
}),
|
|
31394
|
+
type: "string"
|
|
31395
|
+
}
|
|
31396
|
+
}
|
|
31397
|
+
});
|
|
31398
|
+
yield page.dragAndDrop(
|
|
31399
|
+
processed.x,
|
|
31400
|
+
processed.y,
|
|
31401
|
+
processed.x,
|
|
31402
|
+
processed.y,
|
|
31403
|
+
{ delay: duration }
|
|
31404
|
+
);
|
|
31405
|
+
v3.recordAgentReplayStep({
|
|
31406
|
+
type: "clickAndHold",
|
|
31407
|
+
instruction: describe,
|
|
31408
|
+
playwrightArguments: {
|
|
31409
|
+
coordinates: [processed.x, processed.y],
|
|
31410
|
+
duration
|
|
31411
|
+
}
|
|
31412
|
+
});
|
|
31413
|
+
return { success: true, describe };
|
|
31414
|
+
} catch (error) {
|
|
31415
|
+
return {
|
|
31416
|
+
success: false,
|
|
31417
|
+
error: `Error clicking and holding: ${error.message}`
|
|
31418
|
+
};
|
|
31419
|
+
}
|
|
31420
|
+
})
|
|
31421
|
+
});
|
|
31422
|
+
|
|
31423
|
+
// lib/v3/agent/tools/keys.ts
|
|
31424
|
+
var import_ai15 = require("ai");
|
|
31425
|
+
var import_zod19 = require("zod");
|
|
31426
|
+
var keysTool = (v3) => (0, import_ai15.tool)({
|
|
31427
|
+
description: `Send keyboard input to the page without targeting a specific element. Unlike the type tool which clicks then types into coordinates, this sends keystrokes directly to wherever focus currently is.
|
|
31428
|
+
|
|
31429
|
+
Use method="type" to enter text into the currently focused element. Preferred when: input is already focused, text needs to flow across multiple fields (e.g., verification codes)
|
|
31430
|
+
|
|
31431
|
+
Use method="press" for navigation keys (Enter, Tab, Escape, Backspace, arrows) and keyboard shortcuts (Cmd+A, Ctrl+C, Shift+Tab).`,
|
|
31432
|
+
inputSchema: import_zod19.z.object({
|
|
31433
|
+
method: import_zod19.z.enum(["press", "type"]),
|
|
31434
|
+
value: import_zod19.z.string().describe(
|
|
31435
|
+
"The text to type, or the key/combo to press (Enter, Tab, Cmd+A)"
|
|
31436
|
+
),
|
|
31437
|
+
repeat: import_zod19.z.number().optional()
|
|
31438
|
+
}),
|
|
31439
|
+
execute: (_0) => __async(null, [_0], function* ({ method, value, repeat }) {
|
|
31440
|
+
try {
|
|
31441
|
+
const page = yield v3.context.awaitActivePage();
|
|
31442
|
+
v3.logger({
|
|
31443
|
+
category: "agent",
|
|
31444
|
+
message: `Agent calling tool: keys`,
|
|
31445
|
+
level: 1,
|
|
31446
|
+
auxiliary: {
|
|
31447
|
+
arguments: {
|
|
31448
|
+
value: JSON.stringify({ method, value, repeat }),
|
|
31449
|
+
type: "string"
|
|
31450
|
+
}
|
|
31451
|
+
}
|
|
31452
|
+
});
|
|
31453
|
+
const times = Math.max(1, repeat != null ? repeat : 1);
|
|
31454
|
+
if (method === "type") {
|
|
31455
|
+
for (let i2 = 0; i2 < times; i2++) {
|
|
31456
|
+
yield page.type(value, { delay: 100 });
|
|
31457
|
+
}
|
|
31458
|
+
v3.recordAgentReplayStep({
|
|
31459
|
+
type: "keys",
|
|
31460
|
+
instruction: `type "${value}"`,
|
|
31461
|
+
playwrightArguments: { method, text: value, times }
|
|
31462
|
+
});
|
|
31463
|
+
return { success: true, method, value, times };
|
|
31464
|
+
}
|
|
31465
|
+
if (method === "press") {
|
|
31466
|
+
for (let i2 = 0; i2 < times; i2++) {
|
|
31467
|
+
yield page.keyPress(value, { delay: 100 });
|
|
31468
|
+
}
|
|
31469
|
+
v3.recordAgentReplayStep({
|
|
31470
|
+
type: "keys",
|
|
31471
|
+
instruction: `press ${value}`,
|
|
31472
|
+
playwrightArguments: { method, keys: value, times }
|
|
31473
|
+
});
|
|
31474
|
+
return { success: true, method, value, times };
|
|
31475
|
+
}
|
|
31476
|
+
return { success: false, error: `Unsupported method: ${method}` };
|
|
31477
|
+
} catch (error) {
|
|
31478
|
+
return { success: false, error: error.message };
|
|
31479
|
+
}
|
|
31480
|
+
})
|
|
31481
|
+
});
|
|
31482
|
+
|
|
31483
|
+
// lib/v3/agent/tools/fillFormVision.ts
|
|
31484
|
+
var import_ai16 = require("ai");
|
|
31485
|
+
var import_zod20 = require("zod");
|
|
31486
|
+
var fillFormVisionTool = (v3, provider) => (0, import_ai16.tool)({
|
|
31487
|
+
description: `FORM FILL - SPECIALIZED MULTI-FIELD INPUT TOOL
|
|
31488
|
+
|
|
31489
|
+
CRITICAL: Use this for ANY form with 2+ input fields (text inputs, textareas, etc.)
|
|
31490
|
+
IMPORTANT: Ensure the fields are visible within the current viewport
|
|
31491
|
+
|
|
31492
|
+
WHY THIS TOOL EXISTS:
|
|
31493
|
+
- Forms are the #1 use case for multi-field input
|
|
31494
|
+
- Optimized specifically for input/textarea elements
|
|
31495
|
+
- 4-6x faster than individual typing actions
|
|
31496
|
+
|
|
31497
|
+
Use fillFormVision: Pure form filling (inputs, textareas only)
|
|
31498
|
+
MANDATORY USE CASES (always use fillFormVision for these):
|
|
31499
|
+
- Registration forms: name, email, password fields
|
|
31500
|
+
- Contact forms: name, email, message fields
|
|
31501
|
+
- Checkout forms: address, payment info fields
|
|
31502
|
+
- Profile updates: multiple user data fields
|
|
31503
|
+
- Search filters: multiple criteria inputs`,
|
|
31504
|
+
inputSchema: import_zod20.z.object({
|
|
31505
|
+
fields: import_zod20.z.array(
|
|
31506
|
+
import_zod20.z.object({
|
|
31507
|
+
action: import_zod20.z.string().describe(
|
|
31508
|
+
"Description of the typing action, e.g. 'type foo into the bar field'"
|
|
31509
|
+
),
|
|
31510
|
+
value: import_zod20.z.string().describe("Text to type into the target field"),
|
|
31511
|
+
coordinates: import_zod20.z.object({
|
|
31512
|
+
x: import_zod20.z.number(),
|
|
31513
|
+
y: import_zod20.z.number()
|
|
31514
|
+
}).describe("Coordinates of the target field")
|
|
31515
|
+
})
|
|
31516
|
+
).min(2, "Provide at least two fields to fill")
|
|
31517
|
+
}),
|
|
31518
|
+
execute: (_0) => __async(null, [_0], function* ({ fields }) {
|
|
31519
|
+
try {
|
|
31520
|
+
const page = yield v3.context.awaitActivePage();
|
|
31521
|
+
const processedFields = fields.map((field) => {
|
|
31522
|
+
const processed = processCoordinates(
|
|
31523
|
+
field.coordinates.x,
|
|
31524
|
+
field.coordinates.y,
|
|
31525
|
+
provider
|
|
31526
|
+
);
|
|
31527
|
+
return __spreadProps(__spreadValues({}, field), {
|
|
31528
|
+
coordinates: { x: processed.x, y: processed.y }
|
|
31529
|
+
});
|
|
31530
|
+
});
|
|
31531
|
+
v3.logger({
|
|
31532
|
+
category: "agent",
|
|
31533
|
+
message: `Agent calling tool: fillFormVision`,
|
|
31534
|
+
level: 1,
|
|
31535
|
+
auxiliary: {
|
|
31536
|
+
arguments: {
|
|
31537
|
+
value: JSON.stringify({ fields, processedFields }),
|
|
31538
|
+
type: "string"
|
|
31539
|
+
}
|
|
31540
|
+
}
|
|
31541
|
+
});
|
|
31542
|
+
for (const field of processedFields) {
|
|
31543
|
+
yield page.click(field.coordinates.x, field.coordinates.y);
|
|
31544
|
+
yield page.type(field.value);
|
|
31545
|
+
yield new Promise((resolve3) => setTimeout(resolve3, 100));
|
|
31546
|
+
}
|
|
31547
|
+
v3.recordAgentReplayStep({
|
|
31548
|
+
type: "fillFormVision",
|
|
31549
|
+
instruction: `Fill ${fields.length} form fields`,
|
|
31550
|
+
playwrightArguments: processedFields
|
|
31551
|
+
});
|
|
31552
|
+
return {
|
|
31553
|
+
success: true,
|
|
31554
|
+
playwrightArguments: processedFields
|
|
31555
|
+
};
|
|
31556
|
+
} catch (error) {
|
|
31557
|
+
return {
|
|
31558
|
+
success: false,
|
|
31559
|
+
error: `Error filling form: ${error.message}`
|
|
31560
|
+
};
|
|
31561
|
+
}
|
|
31562
|
+
})
|
|
31563
|
+
});
|
|
31564
|
+
|
|
31565
|
+
// lib/v3/agent/tools/think.ts
|
|
31566
|
+
var import_ai17 = require("ai");
|
|
31567
|
+
var import_zod21 = require("zod");
|
|
31568
|
+
var thinkTool = () => (0, import_ai17.tool)({
|
|
31569
|
+
description: `Use this tool to think through complex problems or plan a sequence of steps. This is for internal reasoning only and doesn't perform any actions. Use this to:
|
|
31570
|
+
|
|
31571
|
+
1. Plan a multi-step approach before taking action
|
|
31572
|
+
2. Break down complex tasks
|
|
31573
|
+
3. Reason through edge cases
|
|
31574
|
+
4. Evaluate options when you're unsure what to do next
|
|
31575
|
+
|
|
31576
|
+
The output is only visible to you; use it to track your own reasoning process.`,
|
|
31577
|
+
inputSchema: import_zod21.z.object({
|
|
31578
|
+
reasoning: import_zod21.z.string().describe(
|
|
31579
|
+
"Your step-by-step reasoning or planning process. Be as detailed as needed."
|
|
31580
|
+
)
|
|
31581
|
+
}),
|
|
31582
|
+
execute: (_0) => __async(null, [_0], function* ({ reasoning }) {
|
|
31583
|
+
return {
|
|
31584
|
+
acknowledged: true,
|
|
31585
|
+
message: reasoning
|
|
31586
|
+
};
|
|
31587
|
+
})
|
|
31588
|
+
});
|
|
31589
|
+
|
|
31590
|
+
// lib/v3/agent/tools/search.ts
|
|
31591
|
+
var import_ai18 = require("ai");
|
|
31592
|
+
var import_zod22 = require("zod");
|
|
31593
|
+
function performBraveSearch(query) {
|
|
31594
|
+
return __async(this, null, function* () {
|
|
31595
|
+
var _a4;
|
|
31596
|
+
try {
|
|
31597
|
+
const encodedQuery = encodeURIComponent(query);
|
|
31598
|
+
const response = yield fetch(
|
|
31599
|
+
`https://api.search.brave.com/res/v1/web/search?q=${encodedQuery}`,
|
|
31600
|
+
{
|
|
31601
|
+
method: "GET",
|
|
31602
|
+
headers: {
|
|
31603
|
+
Accept: "application/json",
|
|
31604
|
+
"Accept-Encoding": "gzip",
|
|
31605
|
+
"X-Subscription-Token": process.env.BRAVE_API_KEY
|
|
31606
|
+
}
|
|
31607
|
+
}
|
|
31608
|
+
);
|
|
31609
|
+
if (!response.ok) {
|
|
31610
|
+
return {
|
|
31611
|
+
error: `Brave API error: ${response.status} ${response.statusText}`,
|
|
31612
|
+
data: { results: [] }
|
|
31613
|
+
};
|
|
31614
|
+
}
|
|
31615
|
+
const data = yield response.json();
|
|
31616
|
+
const results = [];
|
|
31617
|
+
if (((_a4 = data == null ? void 0 : data.web) == null ? void 0 : _a4.results) && Array.isArray(data.web.results)) {
|
|
31618
|
+
for (const item of data.web.results.slice(0, 5)) {
|
|
31619
|
+
if (item.title && item.url) {
|
|
31620
|
+
results.push({
|
|
31621
|
+
title: item.title,
|
|
31622
|
+
url: item.url,
|
|
31623
|
+
description: item.description
|
|
31624
|
+
});
|
|
31625
|
+
}
|
|
31626
|
+
}
|
|
31627
|
+
}
|
|
31628
|
+
return { data: { results } };
|
|
31629
|
+
} catch (error) {
|
|
31630
|
+
console.error("Search error", error);
|
|
31631
|
+
return {
|
|
31632
|
+
error: `Error performing search: ${error.message}`,
|
|
31633
|
+
data: { results: [] }
|
|
31634
|
+
};
|
|
31635
|
+
}
|
|
31636
|
+
});
|
|
31637
|
+
}
|
|
31638
|
+
var searchTool = (v3) => (0, import_ai18.tool)({
|
|
31639
|
+
description: "Perform a web search and returns results. Use this tool when you need information from the web or when you are unsure of the exact URL you want to navigate to. This can be used to find the ideal entry point, resulting in a task that is easier to complete due to starting further in the process.",
|
|
31640
|
+
inputSchema: import_zod22.z.object({
|
|
31641
|
+
query: import_zod22.z.string().describe("The search query to look for on the web")
|
|
31642
|
+
}),
|
|
31643
|
+
execute: (_0) => __async(null, [_0], function* ({ query }) {
|
|
31644
|
+
var _a4, _b, _c;
|
|
31645
|
+
v3.logger({
|
|
31646
|
+
category: "agent",
|
|
31647
|
+
message: `Agent calling tool: search`,
|
|
31648
|
+
level: 1,
|
|
31649
|
+
auxiliary: {
|
|
31650
|
+
arguments: {
|
|
31651
|
+
value: JSON.stringify({ query }),
|
|
31652
|
+
type: "string"
|
|
31653
|
+
}
|
|
31654
|
+
}
|
|
31655
|
+
});
|
|
31656
|
+
const result = yield performBraveSearch(query);
|
|
31657
|
+
v3.recordAgentReplayStep({
|
|
31658
|
+
type: "search",
|
|
31659
|
+
instruction: query,
|
|
31660
|
+
playwrightArguments: { query },
|
|
31661
|
+
message: (_c = result.error) != null ? _c : `Found ${(_b = (_a4 = result.data) == null ? void 0 : _a4.results.length) != null ? _b : 0} results`
|
|
31662
|
+
});
|
|
31663
|
+
return __spreadProps(__spreadValues({}, result), {
|
|
31664
|
+
timestamp: Date.now()
|
|
31665
|
+
});
|
|
31666
|
+
})
|
|
31667
|
+
});
|
|
31668
|
+
|
|
31116
31669
|
// lib/v3/agent/tools/index.ts
|
|
31670
|
+
function filterToolsByMode(tools, mode) {
|
|
31671
|
+
const filtered = __spreadValues({}, tools);
|
|
31672
|
+
if (mode === "hybrid") {
|
|
31673
|
+
delete filtered.fillForm;
|
|
31674
|
+
return filtered;
|
|
31675
|
+
}
|
|
31676
|
+
delete filtered.click;
|
|
31677
|
+
delete filtered.type;
|
|
31678
|
+
delete filtered.dragAndDrop;
|
|
31679
|
+
delete filtered.clickAndHold;
|
|
31680
|
+
delete filtered.fillFormVision;
|
|
31681
|
+
return filtered;
|
|
31682
|
+
}
|
|
31117
31683
|
function createAgentTools(v3, options) {
|
|
31684
|
+
var _a4;
|
|
31118
31685
|
const executionModel = options == null ? void 0 : options.executionModel;
|
|
31119
|
-
|
|
31120
|
-
|
|
31121
|
-
|
|
31122
|
-
|
|
31123
|
-
|
|
31124
|
-
|
|
31125
|
-
|
|
31126
|
-
|
|
31127
|
-
|
|
31128
|
-
|
|
31129
|
-
|
|
31686
|
+
const mode = (_a4 = options == null ? void 0 : options.mode) != null ? _a4 : "dom";
|
|
31687
|
+
const provider = options == null ? void 0 : options.provider;
|
|
31688
|
+
const allTools = {
|
|
31689
|
+
act: actTool(v3, executionModel),
|
|
31690
|
+
ariaTree: ariaTreeTool(v3),
|
|
31691
|
+
click: clickTool(v3, provider),
|
|
31692
|
+
clickAndHold: clickAndHoldTool(v3, provider),
|
|
31693
|
+
close: closeTool(),
|
|
31694
|
+
dragAndDrop: dragAndDropTool(v3, provider),
|
|
31695
|
+
extract: extractTool(v3, executionModel, options == null ? void 0 : options.logger),
|
|
31696
|
+
fillForm: fillFormTool(v3, executionModel),
|
|
31697
|
+
fillFormVision: fillFormVisionTool(v3, provider),
|
|
31698
|
+
goto: gotoTool(v3),
|
|
31699
|
+
keys: keysTool(v3),
|
|
31700
|
+
navback: navBackTool(v3),
|
|
31701
|
+
screenshot: screenshotTool(v3),
|
|
31702
|
+
scroll: mode === "hybrid" ? scrollVisionTool(v3, provider) : scrollTool(v3),
|
|
31703
|
+
think: thinkTool(),
|
|
31704
|
+
type: typeTool(v3, provider),
|
|
31705
|
+
wait: waitTool(v3)
|
|
31130
31706
|
};
|
|
31707
|
+
if (process.env.BRAVE_API_KEY) {
|
|
31708
|
+
allTools.search = searchTool(v3);
|
|
31709
|
+
}
|
|
31710
|
+
return filterToolsByMode(allTools, mode);
|
|
31711
|
+
}
|
|
31712
|
+
|
|
31713
|
+
// lib/v3/agent/prompts/agentSystemPrompt.ts
|
|
31714
|
+
function buildAgentSystemPrompt(options) {
|
|
31715
|
+
const {
|
|
31716
|
+
url,
|
|
31717
|
+
executionInstruction,
|
|
31718
|
+
mode,
|
|
31719
|
+
systemInstructions,
|
|
31720
|
+
isBrowserbase = false
|
|
31721
|
+
} = options;
|
|
31722
|
+
const localeDate = (/* @__PURE__ */ new Date()).toLocaleDateString();
|
|
31723
|
+
const isoDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
31724
|
+
const cdata = (text) => `<![CDATA[${text}]]>`;
|
|
31725
|
+
const isHybridMode = mode === "hybrid";
|
|
31726
|
+
const hasSearch = Boolean(process.env.BRAVE_API_KEY);
|
|
31727
|
+
const searchToolLine = hasSearch ? `
|
|
31728
|
+
<tool name="search">Perform a web search and return results. Prefer this over navigating to Google and searching within the page for reliability and efficiency.</tool>` : "";
|
|
31729
|
+
const toolsSection = isHybridMode ? `<tools>
|
|
31730
|
+
<tool name="screenshot">Take a compressed JPEG screenshot for quick visual context</tool>
|
|
31731
|
+
<tool name="ariaTree">Get an accessibility (ARIA) hybrid tree for full page context</tool>
|
|
31732
|
+
<tool name="click">Click on an element (PREFERRED - more reliable when element is visible in viewport)</tool>
|
|
31733
|
+
<tool name="type">Type text into an element (PREFERRED - more reliable when element is visible in viewport)</tool>
|
|
31734
|
+
<tool name="act">Perform a specific atomic action (click, type, etc.) - ONLY use when element is in ariaTree but NOT visible in screenshot. Less reliable but can interact with out-of-viewport elements.</tool>
|
|
31735
|
+
<tool name="dragAndDrop">Drag and drop an element</tool>
|
|
31736
|
+
<tool name="clickAndHold">Click and hold on an element</tool>
|
|
31737
|
+
<tool name="keys">Press a keyboard key</tool>
|
|
31738
|
+
<tool name="fillFormVision">Fill out a form using coordinates</tool>
|
|
31739
|
+
<tool name="think">Think about the task</tool>
|
|
31740
|
+
<tool name="extract">Extract structured data</tool>
|
|
31741
|
+
<tool name="goto">Navigate to a URL</tool>
|
|
31742
|
+
<tool name="wait|navback">Control timing and navigation</tool>
|
|
31743
|
+
<tool name="scroll">Scroll the page x pixels up or down</tool>
|
|
31744
|
+
${searchToolLine}
|
|
31745
|
+
</tools>` : `<tools>
|
|
31746
|
+
<tool name="screenshot">Take a compressed JPEG screenshot for quick visual context</tool>
|
|
31747
|
+
<tool name="ariaTree">Get an accessibility (ARIA) hybrid tree for full page context</tool>
|
|
31748
|
+
<tool name="act">Perform a specific atomic action (click, type)</tool>
|
|
31749
|
+
<tool name="keys">Press a keyboard key</tool>
|
|
31750
|
+
<tool name="fillForm">Fill out a form</tool>
|
|
31751
|
+
<tool name="think">Think about the task</tool>
|
|
31752
|
+
<tool name="extract">Extract structured data</tool>
|
|
31753
|
+
<tool name="goto">Navigate to a URL</tool>
|
|
31754
|
+
<tool name="wait|navback">Control timing and navigation</tool>
|
|
31755
|
+
<tool name="scroll">Scroll the page x pixels up or down</tool>
|
|
31756
|
+
${searchToolLine}
|
|
31757
|
+
</tools>`;
|
|
31758
|
+
const strategyItems = isHybridMode ? [
|
|
31759
|
+
`<item>Tool selection priority: Use specific tools (click, type) when elements are visible in viewport for maximum reliability.</item>`,
|
|
31760
|
+
`<item>Always use screenshot to get proper grounding of the coordinates you want to type/click into.</item>`,
|
|
31761
|
+
`<item>When interacting with an input, always use the type tool to type into the input, over clicking and then typing into it.</item>`,
|
|
31762
|
+
`<item>Use ariaTree as a secondary tool when elements aren't visible in screenshot or to get full page context.</item>`,
|
|
31763
|
+
`<item>Only use act when element is in ariaTree but NOT visible in screenshot.</item>`
|
|
31764
|
+
] : [
|
|
31765
|
+
`<item>Tool selection priority: Use act tool for all clicking and typing on a page.</item>`,
|
|
31766
|
+
`<item>Always check ariaTree first to understand full page content without scrolling - it shows all elements including those below the fold.</item>`,
|
|
31767
|
+
`<item>When interacting with an input, always use the act tool to type into the input, over clicking and then typing.</item>`,
|
|
31768
|
+
`<item>If an element is present in the ariaTree, use act to interact with it directly - this eliminates the need to scroll.</item>`,
|
|
31769
|
+
`<item>Use screenshot for visual confirmation when needed, but rely primarily on ariaTree for element detection.</item>`
|
|
31770
|
+
];
|
|
31771
|
+
const strategySection = strategyItems.join("\n ");
|
|
31772
|
+
const commonStrategyItems = `
|
|
31773
|
+
<item>CRITICAL: Use extract ONLY when the task explicitly requires structured data output (e.g., "get job listings", "extract product details"). For reading page content or understanding elements, always use ${isHybridMode ? "screenshot or ariaTree" : "ariaTree"} instead - it's faster and more reliable.</item>
|
|
31774
|
+
<item>Keep actions atomic and verify outcomes before proceeding.</item>
|
|
31775
|
+
<item>For each action, provide clear reasoning about why you're taking that step.</item>
|
|
31776
|
+
<item>When you need to input text that could be entered character-by-character or through multiple separate inputs, prefer using the keys tool to type the entire sequence at once. This is more efficient for scenarios like verification codes split across multiple fields, or when virtual keyboards are present but direct typing would be faster.</item>
|
|
31777
|
+
`;
|
|
31778
|
+
const pageUnderstandingProtocol = isHybridMode ? `<page_understanding_protocol>
|
|
31779
|
+
<step_1>
|
|
31780
|
+
<title>UNDERSTAND THE PAGE</title>
|
|
31781
|
+
<primary_tool>
|
|
31782
|
+
<name>screenshot</name>
|
|
31783
|
+
<usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>
|
|
31784
|
+
</primary_tool>
|
|
31785
|
+
<secondary_tool>
|
|
31786
|
+
<name>ariaTree</name>
|
|
31787
|
+
<usage>Get complete page context before taking actions</usage>
|
|
31788
|
+
<benefit>Eliminates the need to scroll and provides full accessible content</benefit>
|
|
31789
|
+
</secondary_tool>
|
|
31790
|
+
</step_1>
|
|
31791
|
+
</page_understanding_protocol>` : `<page_understanding_protocol>
|
|
31792
|
+
<step_1>
|
|
31793
|
+
<title>UNDERSTAND THE PAGE</title>
|
|
31794
|
+
<primary_tool>
|
|
31795
|
+
<name>ariaTree</name>
|
|
31796
|
+
<usage>Get complete page context before taking actions</usage>
|
|
31797
|
+
<benefit>Eliminates the need to scroll and provides full accessible content</benefit>
|
|
31798
|
+
</primary_tool>
|
|
31799
|
+
<secondary_tool>
|
|
31800
|
+
<name>screenshot</name>
|
|
31801
|
+
<usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>
|
|
31802
|
+
</secondary_tool>
|
|
31803
|
+
</step_1>
|
|
31804
|
+
</page_understanding_protocol>`;
|
|
31805
|
+
const roadblocksSection = isBrowserbase ? `<roadblocks>
|
|
31806
|
+
<note>captchas, popups, etc.</note>
|
|
31807
|
+
<captcha>If you see a captcha, use the wait tool. It will automatically be solved by our internal solver.</captcha>
|
|
31808
|
+
</roadblocks>` : "";
|
|
31809
|
+
const customInstructionsBlock = systemInstructions ? `<customInstructions>${cdata(systemInstructions)}</customInstructions>
|
|
31810
|
+
` : "";
|
|
31811
|
+
return `<system>
|
|
31812
|
+
<identity>You are a web automation assistant using browser automation tools to accomplish the user's goal.</identity>
|
|
31813
|
+
${customInstructionsBlock}<task>
|
|
31814
|
+
<goal>${cdata(executionInstruction)}</goal>
|
|
31815
|
+
<date display="local" iso="${isoDate}">${localeDate}</date>
|
|
31816
|
+
<note>You may think the date is different due to knowledge cutoff, but this is the actual date.</note>
|
|
31817
|
+
</task>
|
|
31818
|
+
<page>
|
|
31819
|
+
<startingUrl>you are starting your task on this url: ${url}</startingUrl>
|
|
31820
|
+
</page>
|
|
31821
|
+
<mindset>
|
|
31822
|
+
<note>Be very intentional about your action. The initial instruction is very important, and slight variations of the actual goal can lead to failures.</note>
|
|
31823
|
+
<importantNote>If something fails to meet a single condition of the task, move on from it rather than seeing if it meets other criteria. We only care that it meets all of it</importantNote>
|
|
31824
|
+
<note>When the task is complete, do not seek more information; you have completed the task.</note>
|
|
31825
|
+
</mindset>
|
|
31826
|
+
<guidelines>
|
|
31827
|
+
<item>Always start by understanding the current page state</item>
|
|
31828
|
+
<item>Use the screenshot tool to verify page state when needed</item>
|
|
31829
|
+
<item>Use appropriate tools for each action</item>
|
|
31830
|
+
<item>When the task is complete, use the "close" tool with taskComplete: true</item>
|
|
31831
|
+
<item>If the task cannot be completed, use "close" with taskComplete: false</item>
|
|
31832
|
+
</guidelines>
|
|
31833
|
+
${pageUnderstandingProtocol}
|
|
31834
|
+
<navigation>
|
|
31835
|
+
<rule>If you are confident in the URL, navigate directly to it.</rule>
|
|
31836
|
+
${hasSearch ? `<rule>If you are not confident in the URL, use the search tool to find it.</rule>` : ``}
|
|
31837
|
+
</navigation>
|
|
31838
|
+
${toolsSection}
|
|
31839
|
+
<strategy>
|
|
31840
|
+
${strategySection}
|
|
31841
|
+
${commonStrategyItems}
|
|
31842
|
+
</strategy>
|
|
31843
|
+
${roadblocksSection}
|
|
31844
|
+
<completion>
|
|
31845
|
+
<note>When you complete the task, explain any information that was found that was relevant to the original task.</note>
|
|
31846
|
+
<examples>
|
|
31847
|
+
<example>If you were asked for specific flights, list the flights you found.</example>
|
|
31848
|
+
<example>If you were asked for information about a product, list the product information you were asked for.</example>
|
|
31849
|
+
</examples>
|
|
31850
|
+
</completion>
|
|
31851
|
+
</system>`;
|
|
31131
31852
|
}
|
|
31132
31853
|
|
|
31133
31854
|
// lib/v3/handlers/v3AgentHandler.ts
|
|
31134
|
-
var
|
|
31855
|
+
var import_ai19 = require("ai");
|
|
31135
31856
|
|
|
31136
31857
|
// lib/v3/agent/utils/messageProcessing.ts
|
|
31137
31858
|
function isToolMessage(message) {
|
|
@@ -31330,13 +32051,14 @@ function getErrorMessage(error) {
|
|
|
31330
32051
|
return error instanceof Error ? error.message : String(error);
|
|
31331
32052
|
}
|
|
31332
32053
|
var V3AgentHandler = class {
|
|
31333
|
-
constructor(v3, logger, llmClient, executionModel, systemInstructions, mcpTools) {
|
|
32054
|
+
constructor(v3, logger, llmClient, executionModel, systemInstructions, mcpTools, mode) {
|
|
31334
32055
|
this.v3 = v3;
|
|
31335
32056
|
this.logger = logger;
|
|
31336
32057
|
this.llmClient = llmClient;
|
|
31337
32058
|
this.executionModel = executionModel;
|
|
31338
32059
|
this.systemInstructions = systemInstructions;
|
|
31339
32060
|
this.mcpTools = mcpTools;
|
|
32061
|
+
this.mode = mode != null ? mode : "dom";
|
|
31340
32062
|
}
|
|
31341
32063
|
prepareAgent(instructionOrOptions) {
|
|
31342
32064
|
return __async(this, null, function* () {
|
|
@@ -31344,10 +32066,14 @@ var V3AgentHandler = class {
|
|
|
31344
32066
|
try {
|
|
31345
32067
|
const options = typeof instructionOrOptions === "string" ? { instruction: instructionOrOptions } : instructionOrOptions;
|
|
31346
32068
|
const maxSteps = options.maxSteps || 20;
|
|
31347
|
-
const
|
|
31348
|
-
|
|
31349
|
-
|
|
31350
|
-
|
|
32069
|
+
const initialPageUrl = (yield this.v3.context.awaitActivePage()).url();
|
|
32070
|
+
const systemPrompt = buildAgentSystemPrompt({
|
|
32071
|
+
url: initialPageUrl,
|
|
32072
|
+
executionInstruction: options.instruction,
|
|
32073
|
+
mode: this.mode,
|
|
32074
|
+
systemInstructions: this.systemInstructions,
|
|
32075
|
+
isBrowserbase: this.v3.isBrowserbase
|
|
32076
|
+
});
|
|
31351
32077
|
const tools = this.createTools();
|
|
31352
32078
|
const allTools = __spreadValues(__spreadValues({}, tools), this.mcpTools);
|
|
31353
32079
|
const messages = ((_a4 = options.messages) == null ? void 0 : _a4.length) ? [...options.messages, { role: "user", content: options.instruction }] : [{ role: "user", content: options.instruction }];
|
|
@@ -31355,7 +32081,7 @@ var V3AgentHandler = class {
|
|
|
31355
32081
|
throw new MissingLLMConfigurationError();
|
|
31356
32082
|
}
|
|
31357
32083
|
const baseModel = this.llmClient.getLanguageModel();
|
|
31358
|
-
const wrappedModel = (0,
|
|
32084
|
+
const wrappedModel = (0, import_ai19.wrapLanguageModel)({
|
|
31359
32085
|
model: baseModel,
|
|
31360
32086
|
middleware: __spreadValues({
|
|
31361
32087
|
transformParams: (_0) => __async(this, [_0], function* ({ params }) {
|
|
@@ -31364,7 +32090,6 @@ var V3AgentHandler = class {
|
|
|
31364
32090
|
})
|
|
31365
32091
|
}, SessionFileLogger.createLlmLoggingMiddleware(baseModel.modelId))
|
|
31366
32092
|
});
|
|
31367
|
-
const initialPageUrl = (yield this.v3.context.awaitActivePage()).url();
|
|
31368
32093
|
return {
|
|
31369
32094
|
options,
|
|
31370
32095
|
maxSteps,
|
|
@@ -31426,14 +32151,16 @@ var V3AgentHandler = class {
|
|
|
31426
32151
|
}
|
|
31427
32152
|
}
|
|
31428
32153
|
state.currentPageUrl = (yield this.v3.context.awaitActivePage()).url();
|
|
31429
|
-
|
|
31430
|
-
|
|
31431
|
-
|
|
31432
|
-
|
|
31433
|
-
|
|
31434
|
-
|
|
31435
|
-
|
|
31436
|
-
|
|
32154
|
+
if (process.env.EVALS === "true") {
|
|
32155
|
+
try {
|
|
32156
|
+
yield this.captureAndEmitScreenshot();
|
|
32157
|
+
} catch (e2) {
|
|
32158
|
+
this.logger({
|
|
32159
|
+
category: "agent",
|
|
32160
|
+
message: `Warning: Failed to capture screenshot: ${getErrorMessage(e2)}`,
|
|
32161
|
+
level: 1
|
|
32162
|
+
});
|
|
32163
|
+
}
|
|
31437
32164
|
}
|
|
31438
32165
|
}
|
|
31439
32166
|
if (userCallback) {
|
|
@@ -31443,8 +32170,11 @@ var V3AgentHandler = class {
|
|
|
31443
32170
|
}
|
|
31444
32171
|
execute(instructionOrOptions) {
|
|
31445
32172
|
return __async(this, null, function* () {
|
|
32173
|
+
var _a4;
|
|
31446
32174
|
const startTime = Date.now();
|
|
31447
|
-
const
|
|
32175
|
+
const options = typeof instructionOrOptions === "object" ? instructionOrOptions : null;
|
|
32176
|
+
const signal = options == null ? void 0 : options.signal;
|
|
32177
|
+
const shouldHighlightCursor = (_a4 = options == null ? void 0 : options.highlightCursor) != null ? _a4 : this.mode === "hybrid";
|
|
31448
32178
|
const state = {
|
|
31449
32179
|
collectedReasoning: [],
|
|
31450
32180
|
actions: [],
|
|
@@ -31455,7 +32185,7 @@ var V3AgentHandler = class {
|
|
|
31455
32185
|
let messages = [];
|
|
31456
32186
|
try {
|
|
31457
32187
|
const {
|
|
31458
|
-
options,
|
|
32188
|
+
options: preparedOptions,
|
|
31459
32189
|
maxSteps,
|
|
31460
32190
|
systemPrompt,
|
|
31461
32191
|
allTools,
|
|
@@ -31463,6 +32193,11 @@ var V3AgentHandler = class {
|
|
|
31463
32193
|
wrappedModel,
|
|
31464
32194
|
initialPageUrl
|
|
31465
32195
|
} = yield this.prepareAgent(instructionOrOptions);
|
|
32196
|
+
if (shouldHighlightCursor && this.mode === "hybrid") {
|
|
32197
|
+
const page = yield this.v3.context.awaitActivePage();
|
|
32198
|
+
yield page.enableCursorOverlay().catch(() => {
|
|
32199
|
+
});
|
|
32200
|
+
}
|
|
31466
32201
|
messages = preparedMessages;
|
|
31467
32202
|
state.currentPageUrl = initialPageUrl;
|
|
31468
32203
|
const callbacks = instructionOrOptions.callbacks;
|
|
@@ -31490,7 +32225,7 @@ var V3AgentHandler = class {
|
|
|
31490
32225
|
toolChoice: "auto",
|
|
31491
32226
|
prepareStep: callbacks == null ? void 0 : callbacks.prepareStep,
|
|
31492
32227
|
onStepFinish: this.createStepHandler(state, callbacks == null ? void 0 : callbacks.onStepFinish),
|
|
31493
|
-
abortSignal:
|
|
32228
|
+
abortSignal: preparedOptions.signal
|
|
31494
32229
|
});
|
|
31495
32230
|
return this.consolidateMetricsAndResult(
|
|
31496
32231
|
startTime,
|
|
@@ -31524,6 +32259,9 @@ var V3AgentHandler = class {
|
|
|
31524
32259
|
}
|
|
31525
32260
|
stream(instructionOrOptions) {
|
|
31526
32261
|
return __async(this, null, function* () {
|
|
32262
|
+
var _a4;
|
|
32263
|
+
const streamOptions = typeof instructionOrOptions === "object" ? instructionOrOptions : null;
|
|
32264
|
+
const shouldHighlightCursor = (_a4 = streamOptions == null ? void 0 : streamOptions.highlightCursor) != null ? _a4 : this.mode === "hybrid";
|
|
31527
32265
|
const {
|
|
31528
32266
|
options,
|
|
31529
32267
|
maxSteps,
|
|
@@ -31533,6 +32271,11 @@ var V3AgentHandler = class {
|
|
|
31533
32271
|
wrappedModel,
|
|
31534
32272
|
initialPageUrl
|
|
31535
32273
|
} = yield this.prepareAgent(instructionOrOptions);
|
|
32274
|
+
if (shouldHighlightCursor && this.mode === "hybrid") {
|
|
32275
|
+
const page = yield this.v3.context.awaitActivePage();
|
|
32276
|
+
yield page.enableCursorOverlay().catch(() => {
|
|
32277
|
+
});
|
|
32278
|
+
}
|
|
31536
32279
|
const callbacks = instructionOrOptions.callbacks;
|
|
31537
32280
|
const state = {
|
|
31538
32281
|
collectedReasoning: [],
|
|
@@ -31587,11 +32330,11 @@ var V3AgentHandler = class {
|
|
|
31587
32330
|
resolveResult(result);
|
|
31588
32331
|
},
|
|
31589
32332
|
onAbort: (event) => {
|
|
31590
|
-
var
|
|
32333
|
+
var _a5;
|
|
31591
32334
|
if (callbacks == null ? void 0 : callbacks.onAbort) {
|
|
31592
32335
|
callbacks.onAbort(event);
|
|
31593
32336
|
}
|
|
31594
|
-
const reason = ((
|
|
32337
|
+
const reason = ((_a5 = options.signal) == null ? void 0 : _a5.reason) ? String(options.signal.reason) : "Stream was aborted";
|
|
31595
32338
|
rejectResult(new AgentAbortError(reason));
|
|
31596
32339
|
},
|
|
31597
32340
|
abortSignal: options.signal
|
|
@@ -31639,41 +32382,14 @@ var V3AgentHandler = class {
|
|
|
31639
32382
|
messages: fullMessages
|
|
31640
32383
|
};
|
|
31641
32384
|
}
|
|
31642
|
-
buildSystemPrompt(executionInstruction, systemInstructions) {
|
|
31643
|
-
if (systemInstructions) {
|
|
31644
|
-
return `${systemInstructions}
|
|
31645
|
-
Your current goal: ${executionInstruction} when the task is complete, use the "close" tool with taskComplete: true`;
|
|
31646
|
-
}
|
|
31647
|
-
return `You are a web automation assistant using browser automation tools to accomplish the user's goal.
|
|
31648
|
-
|
|
31649
|
-
Your task: ${executionInstruction}
|
|
31650
|
-
|
|
31651
|
-
You have access to various browser automation tools. Use them step by step to complete the task.
|
|
31652
|
-
|
|
31653
|
-
IMPORTANT GUIDELINES:
|
|
31654
|
-
1. Always start by understanding the current page state
|
|
31655
|
-
2. Use the screenshot tool to verify page state when needed
|
|
31656
|
-
3. Use appropriate tools for each action
|
|
31657
|
-
4. When the task is complete, use the "close" tool with taskComplete: true
|
|
31658
|
-
5. If the task cannot be completed, use "close" with taskComplete: false
|
|
31659
|
-
|
|
31660
|
-
TOOLS OVERVIEW:
|
|
31661
|
-
- screenshot: Take a PNG screenshot for quick visual context (use sparingly)
|
|
31662
|
-
- ariaTree: Get an accessibility (ARIA) hybrid tree for full page context
|
|
31663
|
-
- act: Perform a specific atomic action (click, type, etc.)
|
|
31664
|
-
- extract: Extract structured data
|
|
31665
|
-
- goto: Navigate to a URL
|
|
31666
|
-
- wait/navback/refresh: Control timing and navigation
|
|
31667
|
-
- scroll: Scroll the page x pixels up or down
|
|
31668
|
-
|
|
31669
|
-
STRATEGY:
|
|
31670
|
-
- Prefer ariaTree to understand the page before acting; use screenshot for confirmation.
|
|
31671
|
-
- Keep actions atomic and verify outcomes before proceeding.`;
|
|
31672
|
-
}
|
|
31673
32385
|
createTools() {
|
|
32386
|
+
var _a4, _b, _c;
|
|
32387
|
+
const provider = (_c = (_b = (_a4 = this.llmClient) == null ? void 0 : _a4.getLanguageModel) == null ? void 0 : _b.call(_a4)) == null ? void 0 : _c.provider;
|
|
31674
32388
|
return createAgentTools(this.v3, {
|
|
31675
32389
|
executionModel: this.executionModel,
|
|
31676
|
-
logger: this.logger
|
|
32390
|
+
logger: this.logger,
|
|
32391
|
+
mode: this.mode,
|
|
32392
|
+
provider
|
|
31677
32393
|
});
|
|
31678
32394
|
}
|
|
31679
32395
|
handleStop(result, maxSteps) {
|
|
@@ -31682,7 +32398,7 @@ STRATEGY:
|
|
|
31682
32398
|
if ((_a4 = lastStep == null ? void 0 : lastStep.toolCalls) == null ? void 0 : _a4.some((tc) => tc.toolName === "close")) {
|
|
31683
32399
|
return true;
|
|
31684
32400
|
}
|
|
31685
|
-
return (0,
|
|
32401
|
+
return (0, import_ai19.stepCountIs)(maxSteps)(result);
|
|
31686
32402
|
}
|
|
31687
32403
|
/**
|
|
31688
32404
|
* Capture a screenshot and emit it via the event bus
|
|
@@ -32164,8 +32880,8 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
32164
32880
|
betas: ["computer-use-2025-01-24"]
|
|
32165
32881
|
};
|
|
32166
32882
|
if (this.tools && Object.keys(this.tools).length > 0) {
|
|
32167
|
-
const customTools = Object.entries(this.tools).map(([name,
|
|
32168
|
-
const schema =
|
|
32883
|
+
const customTools = Object.entries(this.tools).map(([name, tool21]) => {
|
|
32884
|
+
const schema = tool21.inputSchema;
|
|
32169
32885
|
const jsonSchema3 = toJsonSchema(schema);
|
|
32170
32886
|
const inputSchema = {
|
|
32171
32887
|
type: "object",
|
|
@@ -32174,7 +32890,7 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
32174
32890
|
};
|
|
32175
32891
|
return {
|
|
32176
32892
|
name,
|
|
32177
|
-
description:
|
|
32893
|
+
description: tool21.description,
|
|
32178
32894
|
input_schema: inputSchema
|
|
32179
32895
|
};
|
|
32180
32896
|
});
|
|
@@ -32292,13 +33008,13 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
32292
33008
|
let toolResult = "Tool executed successfully";
|
|
32293
33009
|
if (this.tools && item.name in this.tools) {
|
|
32294
33010
|
try {
|
|
32295
|
-
const
|
|
33011
|
+
const tool21 = this.tools[item.name];
|
|
32296
33012
|
logger({
|
|
32297
33013
|
category: "agent",
|
|
32298
33014
|
message: `Executing tool call: ${item.name} with args: ${JSON.stringify(item.input)}`,
|
|
32299
33015
|
level: 1
|
|
32300
33016
|
});
|
|
32301
|
-
const result = yield
|
|
33017
|
+
const result = yield tool21.execute(item.input, {
|
|
32302
33018
|
toolCallId: item.id,
|
|
32303
33019
|
messages: []
|
|
32304
33020
|
});
|
|
@@ -32820,13 +33536,13 @@ var OpenAICUAClient = class extends AgentClient {
|
|
|
32820
33536
|
truncation: "auto"
|
|
32821
33537
|
};
|
|
32822
33538
|
if (this.tools && Object.keys(this.tools).length > 0) {
|
|
32823
|
-
const customTools = Object.entries(this.tools).map(([name,
|
|
33539
|
+
const customTools = Object.entries(this.tools).map(([name, tool21]) => ({
|
|
32824
33540
|
type: "function",
|
|
32825
33541
|
name,
|
|
32826
33542
|
function: {
|
|
32827
33543
|
name,
|
|
32828
|
-
description:
|
|
32829
|
-
parameters:
|
|
33544
|
+
description: tool21.description,
|
|
33545
|
+
parameters: tool21.inputSchema
|
|
32830
33546
|
}
|
|
32831
33547
|
}));
|
|
32832
33548
|
requestParams.tools = [
|
|
@@ -32966,14 +33682,14 @@ var OpenAICUAClient = class extends AgentClient {
|
|
|
32966
33682
|
let toolResult = "Tool executed successfully";
|
|
32967
33683
|
if (this.tools && item.name in this.tools) {
|
|
32968
33684
|
try {
|
|
32969
|
-
const
|
|
33685
|
+
const tool21 = this.tools[item.name];
|
|
32970
33686
|
const args = JSON.parse(item.arguments);
|
|
32971
33687
|
logger({
|
|
32972
33688
|
category: "agent",
|
|
32973
33689
|
message: `Executing tool call: ${item.name} with args: ${item.arguments}`,
|
|
32974
33690
|
level: 1
|
|
32975
33691
|
});
|
|
32976
|
-
const result = yield
|
|
33692
|
+
const result = yield tool21.execute(args, {
|
|
32977
33693
|
toolCallId: item.call_id,
|
|
32978
33694
|
messages: []
|
|
32979
33695
|
});
|
|
@@ -33129,8 +33845,8 @@ function executeGoogleCustomTool(toolName, toolArgs, tools, functionCall, logger
|
|
|
33129
33845
|
message: `Executing custom tool: ${toolName} with args: ${JSON.stringify(toolArgs)}`,
|
|
33130
33846
|
level: 1
|
|
33131
33847
|
});
|
|
33132
|
-
const
|
|
33133
|
-
const toolResult = yield
|
|
33848
|
+
const tool21 = tools[toolName];
|
|
33849
|
+
const toolResult = yield tool21.execute(toolArgs, {
|
|
33134
33850
|
toolCallId: `tool_${Date.now()}`,
|
|
33135
33851
|
messages: []
|
|
33136
33852
|
});
|
|
@@ -33178,22 +33894,22 @@ function isCustomTool(functionCall, tools) {
|
|
|
33178
33894
|
}
|
|
33179
33895
|
function convertToolSetToFunctionDeclarations(tools) {
|
|
33180
33896
|
const functionDeclarations = [];
|
|
33181
|
-
for (const [name,
|
|
33182
|
-
const functionDeclaration = convertToolToFunctionDeclaration(name,
|
|
33897
|
+
for (const [name, tool21] of Object.entries(tools)) {
|
|
33898
|
+
const functionDeclaration = convertToolToFunctionDeclaration(name, tool21);
|
|
33183
33899
|
if (functionDeclaration) {
|
|
33184
33900
|
functionDeclarations.push(functionDeclaration);
|
|
33185
33901
|
}
|
|
33186
33902
|
}
|
|
33187
33903
|
return functionDeclarations;
|
|
33188
33904
|
}
|
|
33189
|
-
function convertToolToFunctionDeclaration(name,
|
|
33905
|
+
function convertToolToFunctionDeclaration(name, tool21) {
|
|
33190
33906
|
try {
|
|
33191
|
-
const schema =
|
|
33907
|
+
const schema = tool21.inputSchema;
|
|
33192
33908
|
const jsonSchema3 = toJsonSchema(schema);
|
|
33193
33909
|
const parameters = convertJsonSchemaToGoogleParameters(jsonSchema3);
|
|
33194
33910
|
return {
|
|
33195
33911
|
name,
|
|
33196
|
-
description:
|
|
33912
|
+
description: tool21.description || `Execute ${name}`,
|
|
33197
33913
|
parameters
|
|
33198
33914
|
};
|
|
33199
33915
|
} catch (error) {
|
|
@@ -36321,23 +37037,23 @@ function waitForWebSocketDebuggerUrl(port, timeoutMs) {
|
|
|
36321
37037
|
init_sdkErrors();
|
|
36322
37038
|
|
|
36323
37039
|
// lib/v3/llm/aisdk.ts
|
|
36324
|
-
var
|
|
37040
|
+
var import_ai21 = require("ai");
|
|
36325
37041
|
var import_uuid5 = require("uuid");
|
|
36326
37042
|
|
|
36327
37043
|
// lib/v3/llm/LLMClient.ts
|
|
36328
|
-
var
|
|
37044
|
+
var import_ai20 = require("ai");
|
|
36329
37045
|
var AnnotatedScreenshotText = "This is a screenshot of the current page state with the elements annotated on it. Each element id is annotated with a number to the top left of it. Duplicate annotations at the same location are under each other vertically.";
|
|
36330
37046
|
var LLMClient = class {
|
|
36331
37047
|
constructor(modelName, userProvidedInstructions) {
|
|
36332
|
-
this.generateObject =
|
|
36333
|
-
this.generateText =
|
|
36334
|
-
this.streamText =
|
|
36335
|
-
this.streamObject =
|
|
36336
|
-
this.generateImage =
|
|
36337
|
-
this.embed =
|
|
36338
|
-
this.embedMany =
|
|
36339
|
-
this.transcribe =
|
|
36340
|
-
this.generateSpeech =
|
|
37048
|
+
this.generateObject = import_ai20.generateObject;
|
|
37049
|
+
this.generateText = import_ai20.generateText;
|
|
37050
|
+
this.streamText = import_ai20.streamText;
|
|
37051
|
+
this.streamObject = import_ai20.streamObject;
|
|
37052
|
+
this.generateImage = import_ai20.experimental_generateImage;
|
|
37053
|
+
this.embed = import_ai20.embed;
|
|
37054
|
+
this.embedMany = import_ai20.embedMany;
|
|
37055
|
+
this.transcribe = import_ai20.experimental_transcribe;
|
|
37056
|
+
this.generateSpeech = import_ai20.experimental_generateSpeech;
|
|
36341
37057
|
this.modelName = modelName;
|
|
36342
37058
|
this.userProvidedInstructions = userProvidedInstructions;
|
|
36343
37059
|
}
|
|
@@ -36449,7 +37165,7 @@ var AISdkClient = class extends LLMClient {
|
|
|
36449
37165
|
prompt: promptPreview2
|
|
36450
37166
|
});
|
|
36451
37167
|
try {
|
|
36452
|
-
objectResponse = yield (0,
|
|
37168
|
+
objectResponse = yield (0, import_ai21.generateObject)({
|
|
36453
37169
|
model: this.model,
|
|
36454
37170
|
messages: formattedMessages,
|
|
36455
37171
|
schema: options.response_model.schema,
|
|
@@ -36469,7 +37185,7 @@ var AISdkClient = class extends LLMClient {
|
|
|
36469
37185
|
operation: "generateObject",
|
|
36470
37186
|
output: `[error: ${err instanceof Error ? err.message : "unknown"}]`
|
|
36471
37187
|
});
|
|
36472
|
-
if (
|
|
37188
|
+
if (import_ai21.NoObjectGeneratedError.isInstance(err)) {
|
|
36473
37189
|
(_g = this.logger) == null ? void 0 : _g.call(this, {
|
|
36474
37190
|
category: "AISDK error",
|
|
36475
37191
|
message: err.message,
|
|
@@ -36547,10 +37263,10 @@ var AISdkClient = class extends LLMClient {
|
|
|
36547
37263
|
}
|
|
36548
37264
|
const tools = {};
|
|
36549
37265
|
if (options.tools && options.tools.length > 0) {
|
|
36550
|
-
for (const
|
|
36551
|
-
tools[
|
|
36552
|
-
description:
|
|
36553
|
-
inputSchema:
|
|
37266
|
+
for (const tool21 of options.tools) {
|
|
37267
|
+
tools[tool21.name] = {
|
|
37268
|
+
description: tool21.description,
|
|
37269
|
+
inputSchema: tool21.parameters
|
|
36554
37270
|
};
|
|
36555
37271
|
}
|
|
36556
37272
|
}
|
|
@@ -36567,7 +37283,7 @@ var AISdkClient = class extends LLMClient {
|
|
|
36567
37283
|
});
|
|
36568
37284
|
let textResponse;
|
|
36569
37285
|
try {
|
|
36570
|
-
textResponse = yield (0,
|
|
37286
|
+
textResponse = yield (0, import_ai21.generateText)({
|
|
36571
37287
|
model: this.model,
|
|
36572
37288
|
messages: formattedMessages,
|
|
36573
37289
|
tools: Object.keys(tools).length > 0 ? tools : void 0,
|
|
@@ -36749,14 +37465,14 @@ var AnthropicClient = class extends LLMClient {
|
|
|
36749
37465
|
}
|
|
36750
37466
|
formattedMessages.push(screenshotMessage);
|
|
36751
37467
|
}
|
|
36752
|
-
let anthropicTools2 = (_a4 = options.tools) == null ? void 0 : _a4.map((
|
|
37468
|
+
let anthropicTools2 = (_a4 = options.tools) == null ? void 0 : _a4.map((tool21) => {
|
|
36753
37469
|
return {
|
|
36754
|
-
name:
|
|
36755
|
-
description:
|
|
37470
|
+
name: tool21.name,
|
|
37471
|
+
description: tool21.description,
|
|
36756
37472
|
input_schema: {
|
|
36757
37473
|
type: "object",
|
|
36758
|
-
properties:
|
|
36759
|
-
required:
|
|
37474
|
+
properties: tool21.parameters.properties,
|
|
37475
|
+
required: tool21.parameters.required
|
|
36760
37476
|
}
|
|
36761
37477
|
};
|
|
36762
37478
|
});
|
|
@@ -36943,15 +37659,15 @@ var CerebrasClient = class extends LLMClient {
|
|
|
36943
37659
|
return __spreadProps(__spreadValues({}, baseMessage), { role: "user" });
|
|
36944
37660
|
}
|
|
36945
37661
|
});
|
|
36946
|
-
let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((
|
|
37662
|
+
let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((tool21) => ({
|
|
36947
37663
|
type: "function",
|
|
36948
37664
|
function: {
|
|
36949
|
-
name:
|
|
36950
|
-
description:
|
|
37665
|
+
name: tool21.name,
|
|
37666
|
+
description: tool21.description,
|
|
36951
37667
|
parameters: {
|
|
36952
37668
|
type: "object",
|
|
36953
|
-
properties:
|
|
36954
|
-
required:
|
|
37669
|
+
properties: tool21.parameters.properties,
|
|
37670
|
+
required: tool21.parameters.required
|
|
36955
37671
|
}
|
|
36956
37672
|
}
|
|
36957
37673
|
}));
|
|
@@ -37244,18 +37960,18 @@ ${firstPartText.text}`;
|
|
|
37244
37960
|
}
|
|
37245
37961
|
return [
|
|
37246
37962
|
{
|
|
37247
|
-
functionDeclarations: tools.map((
|
|
37963
|
+
functionDeclarations: tools.map((tool21) => {
|
|
37248
37964
|
let parameters = void 0;
|
|
37249
|
-
if (
|
|
37965
|
+
if (tool21.parameters) {
|
|
37250
37966
|
parameters = {
|
|
37251
37967
|
type: import_genai4.Type.OBJECT,
|
|
37252
|
-
properties:
|
|
37253
|
-
required:
|
|
37968
|
+
properties: tool21.parameters.properties,
|
|
37969
|
+
required: tool21.parameters.required
|
|
37254
37970
|
};
|
|
37255
37971
|
}
|
|
37256
37972
|
return {
|
|
37257
|
-
name:
|
|
37258
|
-
description:
|
|
37973
|
+
name: tool21.name,
|
|
37974
|
+
description: tool21.description,
|
|
37259
37975
|
parameters
|
|
37260
37976
|
};
|
|
37261
37977
|
})
|
|
@@ -37531,15 +38247,15 @@ var GroqClient = class extends LLMClient {
|
|
|
37531
38247
|
return __spreadProps(__spreadValues({}, baseMessage), { role: "user" });
|
|
37532
38248
|
}
|
|
37533
38249
|
});
|
|
37534
|
-
let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((
|
|
38250
|
+
let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((tool21) => ({
|
|
37535
38251
|
type: "function",
|
|
37536
38252
|
function: {
|
|
37537
|
-
name:
|
|
37538
|
-
description:
|
|
38253
|
+
name: tool21.name,
|
|
38254
|
+
description: tool21.description,
|
|
37539
38255
|
parameters: {
|
|
37540
38256
|
type: "object",
|
|
37541
|
-
properties:
|
|
37542
|
-
required:
|
|
38257
|
+
properties: tool21.parameters.properties,
|
|
38258
|
+
required: tool21.parameters.required
|
|
37543
38259
|
}
|
|
37544
38260
|
}
|
|
37545
38261
|
}));
|
|
@@ -37916,11 +38632,11 @@ ${parsedSchema}
|
|
|
37916
38632
|
messages: formattedMessages,
|
|
37917
38633
|
response_format: responseFormat,
|
|
37918
38634
|
stream: false,
|
|
37919
|
-
tools: (_e = options.tools) == null ? void 0 : _e.map((
|
|
38635
|
+
tools: (_e = options.tools) == null ? void 0 : _e.map((tool21) => ({
|
|
37920
38636
|
function: {
|
|
37921
|
-
name:
|
|
37922
|
-
description:
|
|
37923
|
-
parameters:
|
|
38637
|
+
name: tool21.name,
|
|
38638
|
+
description: tool21.description,
|
|
38639
|
+
parameters: tool21.parameters
|
|
37924
38640
|
},
|
|
37925
38641
|
type: "function"
|
|
37926
38642
|
}))
|
|
@@ -38713,7 +39429,7 @@ var postToApi = (_0) => __async(null, [_0], function* ({
|
|
|
38713
39429
|
throw handleFetchError({ error, url, requestBodyValues: body.values });
|
|
38714
39430
|
}
|
|
38715
39431
|
});
|
|
38716
|
-
function
|
|
39432
|
+
function tool19(tool22) {
|
|
38717
39433
|
return tool22;
|
|
38718
39434
|
}
|
|
38719
39435
|
function createProviderDefinedToolFactory({
|
|
@@ -38737,7 +39453,7 @@ function createProviderDefinedToolFactory({
|
|
|
38737
39453
|
"onInputDelta",
|
|
38738
39454
|
"onInputAvailable"
|
|
38739
39455
|
]);
|
|
38740
|
-
return
|
|
39456
|
+
return tool19({
|
|
38741
39457
|
type: "provider-defined",
|
|
38742
39458
|
id,
|
|
38743
39459
|
name,
|
|
@@ -38772,7 +39488,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
38772
39488
|
"onInputDelta",
|
|
38773
39489
|
"onInputAvailable"
|
|
38774
39490
|
]);
|
|
38775
|
-
return
|
|
39491
|
+
return tool19({
|
|
38776
39492
|
type: "provider-defined",
|
|
38777
39493
|
id,
|
|
38778
39494
|
name,
|
|
@@ -40586,21 +41302,21 @@ function prepareChatTools({
|
|
|
40586
41302
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
40587
41303
|
}
|
|
40588
41304
|
const openaiTools2 = [];
|
|
40589
|
-
for (const
|
|
40590
|
-
switch (
|
|
41305
|
+
for (const tool21 of tools) {
|
|
41306
|
+
switch (tool21.type) {
|
|
40591
41307
|
case "function":
|
|
40592
41308
|
openaiTools2.push({
|
|
40593
41309
|
type: "function",
|
|
40594
41310
|
function: {
|
|
40595
|
-
name:
|
|
40596
|
-
description:
|
|
40597
|
-
parameters:
|
|
41311
|
+
name: tool21.name,
|
|
41312
|
+
description: tool21.description,
|
|
41313
|
+
parameters: tool21.inputSchema,
|
|
40598
41314
|
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
40599
41315
|
}
|
|
40600
41316
|
});
|
|
40601
41317
|
break;
|
|
40602
41318
|
default:
|
|
40603
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
41319
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
40604
41320
|
break;
|
|
40605
41321
|
}
|
|
40606
41322
|
}
|
|
@@ -42916,22 +43632,22 @@ function prepareResponsesTools(_0) {
|
|
|
42916
43632
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
42917
43633
|
}
|
|
42918
43634
|
const openaiTools2 = [];
|
|
42919
|
-
for (const
|
|
42920
|
-
switch (
|
|
43635
|
+
for (const tool21 of tools) {
|
|
43636
|
+
switch (tool21.type) {
|
|
42921
43637
|
case "function":
|
|
42922
43638
|
openaiTools2.push({
|
|
42923
43639
|
type: "function",
|
|
42924
|
-
name:
|
|
42925
|
-
description:
|
|
42926
|
-
parameters:
|
|
43640
|
+
name: tool21.name,
|
|
43641
|
+
description: tool21.description,
|
|
43642
|
+
parameters: tool21.inputSchema,
|
|
42927
43643
|
strict: strictJsonSchema
|
|
42928
43644
|
});
|
|
42929
43645
|
break;
|
|
42930
43646
|
case "provider-defined": {
|
|
42931
|
-
switch (
|
|
43647
|
+
switch (tool21.id) {
|
|
42932
43648
|
case "openai.file_search": {
|
|
42933
43649
|
const args = yield validateTypes({
|
|
42934
|
-
value:
|
|
43650
|
+
value: tool21.args,
|
|
42935
43651
|
schema: fileSearchArgsSchema
|
|
42936
43652
|
});
|
|
42937
43653
|
openaiTools2.push({
|
|
@@ -42954,7 +43670,7 @@ function prepareResponsesTools(_0) {
|
|
|
42954
43670
|
}
|
|
42955
43671
|
case "openai.web_search_preview": {
|
|
42956
43672
|
const args = yield validateTypes({
|
|
42957
|
-
value:
|
|
43673
|
+
value: tool21.args,
|
|
42958
43674
|
schema: webSearchPreviewArgsSchema
|
|
42959
43675
|
});
|
|
42960
43676
|
openaiTools2.push({
|
|
@@ -42966,7 +43682,7 @@ function prepareResponsesTools(_0) {
|
|
|
42966
43682
|
}
|
|
42967
43683
|
case "openai.web_search": {
|
|
42968
43684
|
const args = yield validateTypes({
|
|
42969
|
-
value:
|
|
43685
|
+
value: tool21.args,
|
|
42970
43686
|
schema: webSearchArgsSchema
|
|
42971
43687
|
});
|
|
42972
43688
|
openaiTools2.push({
|
|
@@ -42979,7 +43695,7 @@ function prepareResponsesTools(_0) {
|
|
|
42979
43695
|
}
|
|
42980
43696
|
case "openai.code_interpreter": {
|
|
42981
43697
|
const args = yield validateTypes({
|
|
42982
|
-
value:
|
|
43698
|
+
value: tool21.args,
|
|
42983
43699
|
schema: codeInterpreterArgsSchema
|
|
42984
43700
|
});
|
|
42985
43701
|
openaiTools2.push({
|
|
@@ -42990,7 +43706,7 @@ function prepareResponsesTools(_0) {
|
|
|
42990
43706
|
}
|
|
42991
43707
|
case "openai.image_generation": {
|
|
42992
43708
|
const args = yield validateTypes({
|
|
42993
|
-
value:
|
|
43709
|
+
value: tool21.args,
|
|
42994
43710
|
schema: imageGenerationArgsSchema
|
|
42995
43711
|
});
|
|
42996
43712
|
openaiTools2.push({
|
|
@@ -43014,7 +43730,7 @@ function prepareResponsesTools(_0) {
|
|
|
43014
43730
|
break;
|
|
43015
43731
|
}
|
|
43016
43732
|
default:
|
|
43017
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
43733
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
43018
43734
|
break;
|
|
43019
43735
|
}
|
|
43020
43736
|
}
|
|
@@ -43119,7 +43835,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
43119
43835
|
}
|
|
43120
43836
|
function hasOpenAITool(id) {
|
|
43121
43837
|
return (tools == null ? void 0 : tools.find(
|
|
43122
|
-
(
|
|
43838
|
+
(tool21) => tool21.type === "provider-defined" && tool21.id === id
|
|
43123
43839
|
)) != null;
|
|
43124
43840
|
}
|
|
43125
43841
|
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
|
|
@@ -43127,7 +43843,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
43127
43843
|
addInclude("message.output_text.logprobs");
|
|
43128
43844
|
}
|
|
43129
43845
|
const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
|
|
43130
|
-
(
|
|
43846
|
+
(tool21) => tool21.type === "provider-defined" && (tool21.id === "openai.web_search" || tool21.id === "openai.web_search_preview")
|
|
43131
43847
|
)) == null ? void 0 : _c.name;
|
|
43132
43848
|
if (webSearchToolName) {
|
|
43133
43849
|
addInclude("web_search_call.action.sources");
|
|
@@ -44981,7 +45697,7 @@ var postToApi2 = (_0) => __async(null, [_0], function* ({
|
|
|
44981
45697
|
throw handleFetchError2({ error, url, requestBodyValues: body.values });
|
|
44982
45698
|
}
|
|
44983
45699
|
});
|
|
44984
|
-
function
|
|
45700
|
+
function tool20(tool22) {
|
|
44985
45701
|
return tool22;
|
|
44986
45702
|
}
|
|
44987
45703
|
function createProviderDefinedToolFactory2({
|
|
@@ -45005,7 +45721,7 @@ function createProviderDefinedToolFactory2({
|
|
|
45005
45721
|
"onInputDelta",
|
|
45006
45722
|
"onInputAvailable"
|
|
45007
45723
|
]);
|
|
45008
|
-
return
|
|
45724
|
+
return tool20({
|
|
45009
45725
|
type: "provider-defined",
|
|
45010
45726
|
id,
|
|
45011
45727
|
name,
|
|
@@ -45040,7 +45756,7 @@ function createProviderDefinedToolFactoryWithOutputSchema2({
|
|
|
45040
45756
|
"onInputDelta",
|
|
45041
45757
|
"onInputAvailable"
|
|
45042
45758
|
]);
|
|
45043
|
-
return
|
|
45759
|
+
return tool20({
|
|
45044
45760
|
type: "provider-defined",
|
|
45045
45761
|
id,
|
|
45046
45762
|
name,
|
|
@@ -46721,25 +47437,25 @@ function prepareTools({
|
|
|
46721
47437
|
if (tools == null) {
|
|
46722
47438
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
46723
47439
|
}
|
|
46724
|
-
const hasFunctionTools = tools.some((
|
|
47440
|
+
const hasFunctionTools = tools.some((tool21) => tool21.type === "function");
|
|
46725
47441
|
const hasProviderDefinedTools = tools.some(
|
|
46726
|
-
(
|
|
47442
|
+
(tool21) => tool21.type === "provider-defined"
|
|
46727
47443
|
);
|
|
46728
47444
|
if (hasFunctionTools && hasProviderDefinedTools) {
|
|
46729
|
-
const functionTools = tools.filter((
|
|
47445
|
+
const functionTools = tools.filter((tool21) => tool21.type === "function");
|
|
46730
47446
|
toolWarnings.push({
|
|
46731
47447
|
type: "unsupported-tool",
|
|
46732
|
-
tool: tools.find((
|
|
47448
|
+
tool: tools.find((tool21) => tool21.type === "function"),
|
|
46733
47449
|
details: `Cannot mix function tools with provider-defined tools in the same request. Falling back to provider-defined tools only. The following function tools will be ignored: ${functionTools.map((t2) => t2.name).join(", ")}. Please use either function tools or provider-defined tools, but not both.`
|
|
46734
47450
|
});
|
|
46735
47451
|
}
|
|
46736
47452
|
if (hasProviderDefinedTools) {
|
|
46737
47453
|
const googleTools22 = [];
|
|
46738
47454
|
const providerDefinedTools = tools.filter(
|
|
46739
|
-
(
|
|
47455
|
+
(tool21) => tool21.type === "provider-defined"
|
|
46740
47456
|
);
|
|
46741
|
-
providerDefinedTools.forEach((
|
|
46742
|
-
switch (
|
|
47457
|
+
providerDefinedTools.forEach((tool21) => {
|
|
47458
|
+
switch (tool21.id) {
|
|
46743
47459
|
case "google.google_search":
|
|
46744
47460
|
if (isGemini2orNewer) {
|
|
46745
47461
|
googleTools22.push({ googleSearch: {} });
|
|
@@ -46747,8 +47463,8 @@ function prepareTools({
|
|
|
46747
47463
|
googleTools22.push({
|
|
46748
47464
|
googleSearchRetrieval: {
|
|
46749
47465
|
dynamicRetrievalConfig: {
|
|
46750
|
-
mode:
|
|
46751
|
-
dynamicThreshold:
|
|
47466
|
+
mode: tool21.args.mode,
|
|
47467
|
+
dynamicThreshold: tool21.args.dynamicThreshold
|
|
46752
47468
|
}
|
|
46753
47469
|
}
|
|
46754
47470
|
});
|
|
@@ -46762,7 +47478,7 @@ function prepareTools({
|
|
|
46762
47478
|
} else {
|
|
46763
47479
|
toolWarnings.push({
|
|
46764
47480
|
type: "unsupported-tool",
|
|
46765
|
-
tool:
|
|
47481
|
+
tool: tool21,
|
|
46766
47482
|
details: "The URL context tool is not supported with other Gemini models than Gemini 2."
|
|
46767
47483
|
});
|
|
46768
47484
|
}
|
|
@@ -46773,18 +47489,18 @@ function prepareTools({
|
|
|
46773
47489
|
} else {
|
|
46774
47490
|
toolWarnings.push({
|
|
46775
47491
|
type: "unsupported-tool",
|
|
46776
|
-
tool:
|
|
47492
|
+
tool: tool21,
|
|
46777
47493
|
details: "The code execution tools is not supported with other Gemini models than Gemini 2."
|
|
46778
47494
|
});
|
|
46779
47495
|
}
|
|
46780
47496
|
break;
|
|
46781
47497
|
case "google.file_search":
|
|
46782
47498
|
if (supportsFileSearch) {
|
|
46783
|
-
googleTools22.push({ fileSearch: __spreadValues({},
|
|
47499
|
+
googleTools22.push({ fileSearch: __spreadValues({}, tool21.args) });
|
|
46784
47500
|
} else {
|
|
46785
47501
|
toolWarnings.push({
|
|
46786
47502
|
type: "unsupported-tool",
|
|
46787
|
-
tool:
|
|
47503
|
+
tool: tool21,
|
|
46788
47504
|
details: "The file search tool is only supported with Gemini 2.5 models."
|
|
46789
47505
|
});
|
|
46790
47506
|
}
|
|
@@ -46795,22 +47511,22 @@ function prepareTools({
|
|
|
46795
47511
|
retrieval: {
|
|
46796
47512
|
vertex_rag_store: {
|
|
46797
47513
|
rag_resources: {
|
|
46798
|
-
rag_corpus:
|
|
47514
|
+
rag_corpus: tool21.args.ragCorpus
|
|
46799
47515
|
},
|
|
46800
|
-
similarity_top_k:
|
|
47516
|
+
similarity_top_k: tool21.args.topK
|
|
46801
47517
|
}
|
|
46802
47518
|
}
|
|
46803
47519
|
});
|
|
46804
47520
|
} else {
|
|
46805
47521
|
toolWarnings.push({
|
|
46806
47522
|
type: "unsupported-tool",
|
|
46807
|
-
tool:
|
|
47523
|
+
tool: tool21,
|
|
46808
47524
|
details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
|
|
46809
47525
|
});
|
|
46810
47526
|
}
|
|
46811
47527
|
break;
|
|
46812
47528
|
default:
|
|
46813
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
47529
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
46814
47530
|
break;
|
|
46815
47531
|
}
|
|
46816
47532
|
});
|
|
@@ -46821,17 +47537,17 @@ function prepareTools({
|
|
|
46821
47537
|
};
|
|
46822
47538
|
}
|
|
46823
47539
|
const functionDeclarations = [];
|
|
46824
|
-
for (const
|
|
46825
|
-
switch (
|
|
47540
|
+
for (const tool21 of tools) {
|
|
47541
|
+
switch (tool21.type) {
|
|
46826
47542
|
case "function":
|
|
46827
47543
|
functionDeclarations.push({
|
|
46828
|
-
name:
|
|
46829
|
-
description: (_a4 =
|
|
46830
|
-
parameters: convertJSONSchemaToOpenAPISchema(
|
|
47544
|
+
name: tool21.name,
|
|
47545
|
+
description: (_a4 = tool21.description) != null ? _a4 : "",
|
|
47546
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool21.inputSchema)
|
|
46831
47547
|
});
|
|
46832
47548
|
break;
|
|
46833
47549
|
default:
|
|
46834
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
47550
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
46835
47551
|
break;
|
|
46836
47552
|
}
|
|
46837
47553
|
}
|
|
@@ -46945,7 +47661,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
46945
47661
|
schema: googleGenerativeAIProviderOptions
|
|
46946
47662
|
});
|
|
46947
47663
|
if ((tools == null ? void 0 : tools.some(
|
|
46948
|
-
(
|
|
47664
|
+
(tool21) => tool21.type === "provider-defined" && tool21.id === "google.vertex_rag_store"
|
|
46949
47665
|
)) && !this.config.provider.startsWith("google.vertex.")) {
|
|
46950
47666
|
warnings.push({
|
|
46951
47667
|
type: "other",
|
|
@@ -48807,23 +49523,23 @@ function prepareTools2(_0) {
|
|
|
48807
49523
|
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
48808
49524
|
}
|
|
48809
49525
|
const anthropicTools2 = [];
|
|
48810
|
-
for (const
|
|
48811
|
-
switch (
|
|
49526
|
+
for (const tool21 of tools) {
|
|
49527
|
+
switch (tool21.type) {
|
|
48812
49528
|
case "function": {
|
|
48813
|
-
const cacheControl = validator3.getCacheControl(
|
|
49529
|
+
const cacheControl = validator3.getCacheControl(tool21.providerOptions, {
|
|
48814
49530
|
type: "tool definition",
|
|
48815
49531
|
canCache: true
|
|
48816
49532
|
});
|
|
48817
49533
|
anthropicTools2.push({
|
|
48818
|
-
name:
|
|
48819
|
-
description:
|
|
48820
|
-
input_schema:
|
|
49534
|
+
name: tool21.name,
|
|
49535
|
+
description: tool21.description,
|
|
49536
|
+
input_schema: tool21.inputSchema,
|
|
48821
49537
|
cache_control: cacheControl
|
|
48822
49538
|
});
|
|
48823
49539
|
break;
|
|
48824
49540
|
}
|
|
48825
49541
|
case "provider-defined": {
|
|
48826
|
-
switch (
|
|
49542
|
+
switch (tool21.id) {
|
|
48827
49543
|
case "anthropic.code_execution_20250522": {
|
|
48828
49544
|
betas.add("code-execution-2025-05-22");
|
|
48829
49545
|
anthropicTools2.push({
|
|
@@ -48846,9 +49562,9 @@ function prepareTools2(_0) {
|
|
|
48846
49562
|
anthropicTools2.push({
|
|
48847
49563
|
name: "computer",
|
|
48848
49564
|
type: "computer_20250124",
|
|
48849
|
-
display_width_px:
|
|
48850
|
-
display_height_px:
|
|
48851
|
-
display_number:
|
|
49565
|
+
display_width_px: tool21.args.displayWidthPx,
|
|
49566
|
+
display_height_px: tool21.args.displayHeightPx,
|
|
49567
|
+
display_number: tool21.args.displayNumber,
|
|
48852
49568
|
cache_control: void 0
|
|
48853
49569
|
});
|
|
48854
49570
|
break;
|
|
@@ -48858,9 +49574,9 @@ function prepareTools2(_0) {
|
|
|
48858
49574
|
anthropicTools2.push({
|
|
48859
49575
|
name: "computer",
|
|
48860
49576
|
type: "computer_20241022",
|
|
48861
|
-
display_width_px:
|
|
48862
|
-
display_height_px:
|
|
48863
|
-
display_number:
|
|
49577
|
+
display_width_px: tool21.args.displayWidthPx,
|
|
49578
|
+
display_height_px: tool21.args.displayHeightPx,
|
|
49579
|
+
display_number: tool21.args.displayNumber,
|
|
48864
49580
|
cache_control: void 0
|
|
48865
49581
|
});
|
|
48866
49582
|
break;
|
|
@@ -48894,7 +49610,7 @@ function prepareTools2(_0) {
|
|
|
48894
49610
|
}
|
|
48895
49611
|
case "anthropic.text_editor_20250728": {
|
|
48896
49612
|
const args = yield validateTypes2({
|
|
48897
|
-
value:
|
|
49613
|
+
value: tool21.args,
|
|
48898
49614
|
schema: textEditor_20250728ArgsSchema
|
|
48899
49615
|
});
|
|
48900
49616
|
anthropicTools2.push({
|
|
@@ -48934,7 +49650,7 @@ function prepareTools2(_0) {
|
|
|
48934
49650
|
case "anthropic.web_fetch_20250910": {
|
|
48935
49651
|
betas.add("web-fetch-2025-09-10");
|
|
48936
49652
|
const args = yield validateTypes2({
|
|
48937
|
-
value:
|
|
49653
|
+
value: tool21.args,
|
|
48938
49654
|
schema: webFetch_20250910ArgsSchema
|
|
48939
49655
|
});
|
|
48940
49656
|
anthropicTools2.push({
|
|
@@ -48951,7 +49667,7 @@ function prepareTools2(_0) {
|
|
|
48951
49667
|
}
|
|
48952
49668
|
case "anthropic.web_search_20250305": {
|
|
48953
49669
|
const args = yield validateTypes2({
|
|
48954
|
-
value:
|
|
49670
|
+
value: tool21.args,
|
|
48955
49671
|
schema: webSearch_20250305ArgsSchema
|
|
48956
49672
|
});
|
|
48957
49673
|
anthropicTools2.push({
|
|
@@ -48966,14 +49682,14 @@ function prepareTools2(_0) {
|
|
|
48966
49682
|
break;
|
|
48967
49683
|
}
|
|
48968
49684
|
default: {
|
|
48969
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
49685
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
48970
49686
|
break;
|
|
48971
49687
|
}
|
|
48972
49688
|
}
|
|
48973
49689
|
break;
|
|
48974
49690
|
}
|
|
48975
49691
|
default: {
|
|
48976
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
49692
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
48977
49693
|
break;
|
|
48978
49694
|
}
|
|
48979
49695
|
}
|
|
@@ -49932,7 +50648,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49932
50648
|
betas.add("skills-2025-10-02");
|
|
49933
50649
|
betas.add("files-api-2025-04-14");
|
|
49934
50650
|
if (!(tools == null ? void 0 : tools.some(
|
|
49935
|
-
(
|
|
50651
|
+
(tool21) => tool21.type === "provider-defined" && tool21.id === "anthropic.code_execution_20250825"
|
|
49936
50652
|
))) {
|
|
49937
50653
|
warnings.push({
|
|
49938
50654
|
type: "other",
|
|
@@ -51770,24 +52486,24 @@ function prepareTools3({
|
|
|
51770
52486
|
if (tools == null) {
|
|
51771
52487
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
51772
52488
|
}
|
|
51773
|
-
const hasFunctionTools = tools.some((
|
|
52489
|
+
const hasFunctionTools = tools.some((tool21) => tool21.type === "function");
|
|
51774
52490
|
const hasProviderDefinedTools = tools.some(
|
|
51775
|
-
(
|
|
52491
|
+
(tool21) => tool21.type === "provider-defined"
|
|
51776
52492
|
);
|
|
51777
52493
|
if (hasFunctionTools && hasProviderDefinedTools) {
|
|
51778
52494
|
toolWarnings.push({
|
|
51779
52495
|
type: "unsupported-tool",
|
|
51780
|
-
tool: tools.find((
|
|
52496
|
+
tool: tools.find((tool21) => tool21.type === "function"),
|
|
51781
52497
|
details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
|
|
51782
52498
|
});
|
|
51783
52499
|
}
|
|
51784
52500
|
if (hasProviderDefinedTools) {
|
|
51785
52501
|
const googleTools22 = [];
|
|
51786
52502
|
const providerDefinedTools = tools.filter(
|
|
51787
|
-
(
|
|
52503
|
+
(tool21) => tool21.type === "provider-defined"
|
|
51788
52504
|
);
|
|
51789
|
-
providerDefinedTools.forEach((
|
|
51790
|
-
switch (
|
|
52505
|
+
providerDefinedTools.forEach((tool21) => {
|
|
52506
|
+
switch (tool21.id) {
|
|
51791
52507
|
case "google.google_search":
|
|
51792
52508
|
if (isGemini2) {
|
|
51793
52509
|
googleTools22.push({ googleSearch: {} });
|
|
@@ -51795,8 +52511,8 @@ function prepareTools3({
|
|
|
51795
52511
|
googleTools22.push({
|
|
51796
52512
|
googleSearchRetrieval: {
|
|
51797
52513
|
dynamicRetrievalConfig: {
|
|
51798
|
-
mode:
|
|
51799
|
-
dynamicThreshold:
|
|
52514
|
+
mode: tool21.args.mode,
|
|
52515
|
+
dynamicThreshold: tool21.args.dynamicThreshold
|
|
51800
52516
|
}
|
|
51801
52517
|
}
|
|
51802
52518
|
});
|
|
@@ -51810,7 +52526,7 @@ function prepareTools3({
|
|
|
51810
52526
|
} else {
|
|
51811
52527
|
toolWarnings.push({
|
|
51812
52528
|
type: "unsupported-tool",
|
|
51813
|
-
tool:
|
|
52529
|
+
tool: tool21,
|
|
51814
52530
|
details: "The URL context tool is not supported with other Gemini models than Gemini 2."
|
|
51815
52531
|
});
|
|
51816
52532
|
}
|
|
@@ -51821,13 +52537,13 @@ function prepareTools3({
|
|
|
51821
52537
|
} else {
|
|
51822
52538
|
toolWarnings.push({
|
|
51823
52539
|
type: "unsupported-tool",
|
|
51824
|
-
tool:
|
|
52540
|
+
tool: tool21,
|
|
51825
52541
|
details: "The code execution tools is not supported with other Gemini models than Gemini 2."
|
|
51826
52542
|
});
|
|
51827
52543
|
}
|
|
51828
52544
|
break;
|
|
51829
52545
|
default:
|
|
51830
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
52546
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
51831
52547
|
break;
|
|
51832
52548
|
}
|
|
51833
52549
|
});
|
|
@@ -51838,17 +52554,17 @@ function prepareTools3({
|
|
|
51838
52554
|
};
|
|
51839
52555
|
}
|
|
51840
52556
|
const functionDeclarations = [];
|
|
51841
|
-
for (const
|
|
51842
|
-
switch (
|
|
52557
|
+
for (const tool21 of tools) {
|
|
52558
|
+
switch (tool21.type) {
|
|
51843
52559
|
case "function":
|
|
51844
52560
|
functionDeclarations.push({
|
|
51845
|
-
name:
|
|
51846
|
-
description: (_a4 =
|
|
51847
|
-
parameters: convertJSONSchemaToOpenAPISchema2(
|
|
52561
|
+
name: tool21.name,
|
|
52562
|
+
description: (_a4 = tool21.description) != null ? _a4 : "",
|
|
52563
|
+
parameters: convertJSONSchemaToOpenAPISchema2(tool21.inputSchema)
|
|
51848
52564
|
});
|
|
51849
52565
|
break;
|
|
51850
52566
|
default:
|
|
51851
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
52567
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
51852
52568
|
break;
|
|
51853
52569
|
}
|
|
51854
52570
|
}
|
|
@@ -52971,16 +53687,16 @@ function prepareTools4({
|
|
|
52971
53687
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
52972
53688
|
}
|
|
52973
53689
|
const openaiCompatTools = [];
|
|
52974
|
-
for (const
|
|
52975
|
-
if (
|
|
52976
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
53690
|
+
for (const tool21 of tools) {
|
|
53691
|
+
if (tool21.type === "provider-defined") {
|
|
53692
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
52977
53693
|
} else {
|
|
52978
53694
|
openaiCompatTools.push({
|
|
52979
53695
|
type: "function",
|
|
52980
53696
|
function: {
|
|
52981
|
-
name:
|
|
52982
|
-
description:
|
|
52983
|
-
parameters:
|
|
53697
|
+
name: tool21.name,
|
|
53698
|
+
description: tool21.description,
|
|
53699
|
+
parameters: tool21.inputSchema
|
|
52984
53700
|
}
|
|
52985
53701
|
});
|
|
52986
53702
|
}
|
|
@@ -54325,16 +55041,16 @@ function prepareTools5({
|
|
|
54325
55041
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
54326
55042
|
}
|
|
54327
55043
|
const xaiTools = [];
|
|
54328
|
-
for (const
|
|
54329
|
-
if (
|
|
54330
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
55044
|
+
for (const tool21 of tools) {
|
|
55045
|
+
if (tool21.type === "provider-defined") {
|
|
55046
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
54331
55047
|
} else {
|
|
54332
55048
|
xaiTools.push({
|
|
54333
55049
|
type: "function",
|
|
54334
55050
|
function: {
|
|
54335
|
-
name:
|
|
54336
|
-
description:
|
|
54337
|
-
parameters:
|
|
55051
|
+
name: tool21.name,
|
|
55052
|
+
description: tool21.description,
|
|
55053
|
+
parameters: tool21.inputSchema
|
|
54338
55054
|
}
|
|
54339
55055
|
});
|
|
54340
55056
|
}
|
|
@@ -55334,21 +56050,21 @@ function prepareChatTools2({
|
|
|
55334
56050
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
55335
56051
|
}
|
|
55336
56052
|
const openaiTools2 = [];
|
|
55337
|
-
for (const
|
|
55338
|
-
switch (
|
|
56053
|
+
for (const tool21 of tools) {
|
|
56054
|
+
switch (tool21.type) {
|
|
55339
56055
|
case "function":
|
|
55340
56056
|
openaiTools2.push({
|
|
55341
56057
|
type: "function",
|
|
55342
56058
|
function: {
|
|
55343
|
-
name:
|
|
55344
|
-
description:
|
|
55345
|
-
parameters:
|
|
56059
|
+
name: tool21.name,
|
|
56060
|
+
description: tool21.description,
|
|
56061
|
+
parameters: tool21.inputSchema,
|
|
55346
56062
|
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
55347
56063
|
}
|
|
55348
56064
|
});
|
|
55349
56065
|
break;
|
|
55350
56066
|
default:
|
|
55351
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
56067
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
55352
56068
|
break;
|
|
55353
56069
|
}
|
|
55354
56070
|
}
|
|
@@ -57930,22 +58646,22 @@ function prepareResponsesTools2(_0) {
|
|
|
57930
58646
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
57931
58647
|
}
|
|
57932
58648
|
const openaiTools2 = [];
|
|
57933
|
-
for (const
|
|
57934
|
-
switch (
|
|
58649
|
+
for (const tool21 of tools) {
|
|
58650
|
+
switch (tool21.type) {
|
|
57935
58651
|
case "function":
|
|
57936
58652
|
openaiTools2.push({
|
|
57937
58653
|
type: "function",
|
|
57938
|
-
name:
|
|
57939
|
-
description:
|
|
57940
|
-
parameters:
|
|
58654
|
+
name: tool21.name,
|
|
58655
|
+
description: tool21.description,
|
|
58656
|
+
parameters: tool21.inputSchema,
|
|
57941
58657
|
strict: strictJsonSchema
|
|
57942
58658
|
});
|
|
57943
58659
|
break;
|
|
57944
58660
|
case "provider-defined": {
|
|
57945
|
-
switch (
|
|
58661
|
+
switch (tool21.id) {
|
|
57946
58662
|
case "openai.file_search": {
|
|
57947
58663
|
const args = yield validateTypes({
|
|
57948
|
-
value:
|
|
58664
|
+
value: tool21.args,
|
|
57949
58665
|
schema: fileSearchArgsSchema3
|
|
57950
58666
|
});
|
|
57951
58667
|
openaiTools2.push({
|
|
@@ -57968,7 +58684,7 @@ function prepareResponsesTools2(_0) {
|
|
|
57968
58684
|
}
|
|
57969
58685
|
case "openai.web_search_preview": {
|
|
57970
58686
|
const args = yield validateTypes({
|
|
57971
|
-
value:
|
|
58687
|
+
value: tool21.args,
|
|
57972
58688
|
schema: webSearchPreviewArgsSchema2
|
|
57973
58689
|
});
|
|
57974
58690
|
openaiTools2.push({
|
|
@@ -57980,7 +58696,7 @@ function prepareResponsesTools2(_0) {
|
|
|
57980
58696
|
}
|
|
57981
58697
|
case "openai.web_search": {
|
|
57982
58698
|
const args = yield validateTypes({
|
|
57983
|
-
value:
|
|
58699
|
+
value: tool21.args,
|
|
57984
58700
|
schema: webSearchArgsSchema2
|
|
57985
58701
|
});
|
|
57986
58702
|
openaiTools2.push({
|
|
@@ -57993,7 +58709,7 @@ function prepareResponsesTools2(_0) {
|
|
|
57993
58709
|
}
|
|
57994
58710
|
case "openai.code_interpreter": {
|
|
57995
58711
|
const args = yield validateTypes({
|
|
57996
|
-
value:
|
|
58712
|
+
value: tool21.args,
|
|
57997
58713
|
schema: codeInterpreterArgsSchema2
|
|
57998
58714
|
});
|
|
57999
58715
|
openaiTools2.push({
|
|
@@ -58004,7 +58720,7 @@ function prepareResponsesTools2(_0) {
|
|
|
58004
58720
|
}
|
|
58005
58721
|
case "openai.image_generation": {
|
|
58006
58722
|
const args = yield validateTypes({
|
|
58007
|
-
value:
|
|
58723
|
+
value: tool21.args,
|
|
58008
58724
|
schema: imageGenerationArgsSchema2
|
|
58009
58725
|
});
|
|
58010
58726
|
openaiTools2.push({
|
|
@@ -58028,7 +58744,7 @@ function prepareResponsesTools2(_0) {
|
|
|
58028
58744
|
break;
|
|
58029
58745
|
}
|
|
58030
58746
|
default:
|
|
58031
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
58747
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
58032
58748
|
break;
|
|
58033
58749
|
}
|
|
58034
58750
|
}
|
|
@@ -58133,7 +58849,7 @@ var OpenAIResponsesLanguageModel2 = class {
|
|
|
58133
58849
|
}
|
|
58134
58850
|
function hasOpenAITool(id) {
|
|
58135
58851
|
return (tools == null ? void 0 : tools.find(
|
|
58136
|
-
(
|
|
58852
|
+
(tool21) => tool21.type === "provider-defined" && tool21.id === id
|
|
58137
58853
|
)) != null;
|
|
58138
58854
|
}
|
|
58139
58855
|
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX2 : void 0;
|
|
@@ -58141,7 +58857,7 @@ var OpenAIResponsesLanguageModel2 = class {
|
|
|
58141
58857
|
addInclude("message.output_text.logprobs");
|
|
58142
58858
|
}
|
|
58143
58859
|
const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
|
|
58144
|
-
(
|
|
58860
|
+
(tool21) => tool21.type === "provider-defined" && (tool21.id === "openai.web_search" || tool21.id === "openai.web_search_preview")
|
|
58145
58861
|
)) == null ? void 0 : _c.name;
|
|
58146
58862
|
if (webSearchToolName) {
|
|
58147
58863
|
addInclude("web_search_call.action.sources");
|
|
@@ -59364,13 +60080,13 @@ function prepareTools6({
|
|
|
59364
60080
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
59365
60081
|
}
|
|
59366
60082
|
const groqTools2 = [];
|
|
59367
|
-
for (const
|
|
59368
|
-
if (
|
|
59369
|
-
if (
|
|
60083
|
+
for (const tool21 of tools) {
|
|
60084
|
+
if (tool21.type === "provider-defined") {
|
|
60085
|
+
if (tool21.id === "groq.browser_search") {
|
|
59370
60086
|
if (!isBrowserSearchSupportedModel(modelId)) {
|
|
59371
60087
|
toolWarnings.push({
|
|
59372
60088
|
type: "unsupported-tool",
|
|
59373
|
-
tool:
|
|
60089
|
+
tool: tool21,
|
|
59374
60090
|
details: `Browser search is only supported on the following models: ${getSupportedModelsString()}. Current model: ${modelId}`
|
|
59375
60091
|
});
|
|
59376
60092
|
} else {
|
|
@@ -59379,15 +60095,15 @@ function prepareTools6({
|
|
|
59379
60095
|
});
|
|
59380
60096
|
}
|
|
59381
60097
|
} else {
|
|
59382
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
60098
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
59383
60099
|
}
|
|
59384
60100
|
} else {
|
|
59385
60101
|
groqTools2.push({
|
|
59386
60102
|
type: "function",
|
|
59387
60103
|
function: {
|
|
59388
|
-
name:
|
|
59389
|
-
description:
|
|
59390
|
-
parameters:
|
|
60104
|
+
name: tool21.name,
|
|
60105
|
+
description: tool21.description,
|
|
60106
|
+
parameters: tool21.inputSchema
|
|
59391
60107
|
}
|
|
59392
60108
|
});
|
|
59393
60109
|
}
|
|
@@ -60439,16 +61155,16 @@ function prepareTools7({
|
|
|
60439
61155
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
60440
61156
|
}
|
|
60441
61157
|
const mistralTools = [];
|
|
60442
|
-
for (const
|
|
60443
|
-
if (
|
|
60444
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
61158
|
+
for (const tool21 of tools) {
|
|
61159
|
+
if (tool21.type === "provider-defined") {
|
|
61160
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
60445
61161
|
} else {
|
|
60446
61162
|
mistralTools.push({
|
|
60447
61163
|
type: "function",
|
|
60448
61164
|
function: {
|
|
60449
|
-
name:
|
|
60450
|
-
description:
|
|
60451
|
-
parameters:
|
|
61165
|
+
name: tool21.name,
|
|
61166
|
+
description: tool21.description,
|
|
61167
|
+
parameters: tool21.inputSchema
|
|
60452
61168
|
}
|
|
60453
61169
|
});
|
|
60454
61170
|
}
|
|
@@ -60468,7 +61184,7 @@ function prepareTools7({
|
|
|
60468
61184
|
case "tool":
|
|
60469
61185
|
return {
|
|
60470
61186
|
tools: mistralTools.filter(
|
|
60471
|
-
(
|
|
61187
|
+
(tool21) => tool21.function.name === toolChoice.toolName
|
|
60472
61188
|
),
|
|
60473
61189
|
toolChoice: "any",
|
|
60474
61190
|
toolWarnings
|
|
@@ -62251,10 +62967,10 @@ function prepareResponsesTools3({
|
|
|
62251
62967
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
62252
62968
|
}
|
|
62253
62969
|
const ollamaTools = [];
|
|
62254
|
-
for (const
|
|
62255
|
-
switch (
|
|
62970
|
+
for (const tool21 of tools) {
|
|
62971
|
+
switch (tool21.type) {
|
|
62256
62972
|
case "function": {
|
|
62257
|
-
let parameters =
|
|
62973
|
+
let parameters = tool21.inputSchema;
|
|
62258
62974
|
if (!parameters) {
|
|
62259
62975
|
parameters = {
|
|
62260
62976
|
type: "object",
|
|
@@ -62270,15 +62986,15 @@ function prepareResponsesTools3({
|
|
|
62270
62986
|
ollamaTools.push({
|
|
62271
62987
|
type: "function",
|
|
62272
62988
|
function: {
|
|
62273
|
-
name:
|
|
62274
|
-
description:
|
|
62989
|
+
name: tool21.name,
|
|
62990
|
+
description: tool21.description,
|
|
62275
62991
|
parameters
|
|
62276
62992
|
}
|
|
62277
62993
|
});
|
|
62278
62994
|
break;
|
|
62279
62995
|
}
|
|
62280
62996
|
default:
|
|
62281
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
62997
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool21 });
|
|
62282
62998
|
break;
|
|
62283
62999
|
}
|
|
62284
63000
|
}
|
|
@@ -63076,13 +63792,13 @@ var resolveTools = (clients, userTools) => __async(null, null, function* () {
|
|
|
63076
63792
|
const clientTools = yield clientInstance.listTools({
|
|
63077
63793
|
cursor: nextCursor
|
|
63078
63794
|
});
|
|
63079
|
-
for (const
|
|
63080
|
-
tools[
|
|
63081
|
-
description:
|
|
63082
|
-
inputSchema: jsonSchemaToZod(
|
|
63795
|
+
for (const tool21 of clientTools.tools) {
|
|
63796
|
+
tools[tool21.name] = {
|
|
63797
|
+
description: tool21.description,
|
|
63798
|
+
inputSchema: jsonSchemaToZod(tool21.inputSchema),
|
|
63083
63799
|
execute: (input) => __async(null, null, function* () {
|
|
63084
63800
|
const result = yield clientInstance.callTool({
|
|
63085
|
-
name:
|
|
63801
|
+
name: tool21.name,
|
|
63086
63802
|
arguments: input
|
|
63087
63803
|
});
|
|
63088
63804
|
return result;
|
|
@@ -63156,7 +63872,7 @@ init_response2();
|
|
|
63156
63872
|
init_sdkErrors();
|
|
63157
63873
|
|
|
63158
63874
|
// examples/external_clients/aisdk.ts
|
|
63159
|
-
var
|
|
63875
|
+
var import_ai22 = require("ai");
|
|
63160
63876
|
var AISdkClient2 = class extends LLMClient {
|
|
63161
63877
|
constructor({ model }) {
|
|
63162
63878
|
super(model.modelId);
|
|
@@ -63218,7 +63934,7 @@ var AISdkClient2 = class extends LLMClient {
|
|
|
63218
63934
|
}
|
|
63219
63935
|
);
|
|
63220
63936
|
if (options.response_model) {
|
|
63221
|
-
const response2 = yield (0,
|
|
63937
|
+
const response2 = yield (0, import_ai22.generateObject)({
|
|
63222
63938
|
model: this.model,
|
|
63223
63939
|
messages: formattedMessages,
|
|
63224
63940
|
schema: options.response_model.schema
|
|
@@ -63241,7 +63957,7 @@ var AISdkClient2 = class extends LLMClient {
|
|
|
63241
63957
|
inputSchema: rawTool.parameters
|
|
63242
63958
|
};
|
|
63243
63959
|
}
|
|
63244
|
-
const response = yield (0,
|
|
63960
|
+
const response = yield (0, import_ai22.generateText)({
|
|
63245
63961
|
model: this.model,
|
|
63246
63962
|
messages: formattedMessages,
|
|
63247
63963
|
tools
|
|
@@ -64575,7 +65291,7 @@ function validateExperimentalFeatures(options) {
|
|
|
64575
65291
|
init_flowLogger();
|
|
64576
65292
|
init_sdkErrors();
|
|
64577
65293
|
var DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
|
|
64578
|
-
var
|
|
65294
|
+
var DEFAULT_VIEWPORT2 = { width: 1288, height: 711 };
|
|
64579
65295
|
function resolveModelConfiguration(model) {
|
|
64580
65296
|
if (!model) {
|
|
64581
65297
|
return { modelName: DEFAULT_MODEL_NAME };
|
|
@@ -64768,6 +65484,12 @@ var _V3 = class _V3 {
|
|
|
64768
65484
|
get browserbaseDebugURL() {
|
|
64769
65485
|
return this.browserbaseDebugUrl;
|
|
64770
65486
|
}
|
|
65487
|
+
/**
|
|
65488
|
+
* Returns true if the browser is running on Browserbase.
|
|
65489
|
+
*/
|
|
65490
|
+
get isBrowserbase() {
|
|
65491
|
+
return this.state.kind === "BROWSERBASE";
|
|
65492
|
+
}
|
|
64771
65493
|
/**
|
|
64772
65494
|
* Async property for metrics so callers can `await v3.metrics`.
|
|
64773
65495
|
* When using API mode, fetches metrics from the API. Otherwise returns local metrics.
|
|
@@ -65109,7 +65831,7 @@ var _V3 = class _V3 {
|
|
|
65109
65831
|
if (lbo.devtools) chromeFlags.push("--auto-open-devtools-for-tabs");
|
|
65110
65832
|
if (lbo.locale) chromeFlags.push(`--lang=${lbo.locale}`);
|
|
65111
65833
|
if (!lbo.viewport) {
|
|
65112
|
-
lbo.viewport =
|
|
65834
|
+
lbo.viewport = DEFAULT_VIEWPORT2;
|
|
65113
65835
|
}
|
|
65114
65836
|
if (((_f = lbo.viewport) == null ? void 0 : _f.width) && ((_g = lbo.viewport) == null ? void 0 : _g.height)) {
|
|
65115
65837
|
chromeFlags.push(
|
|
@@ -65734,7 +66456,8 @@ var _V3 = class _V3 {
|
|
|
65734
66456
|
agentLlmClient,
|
|
65735
66457
|
typeof (options == null ? void 0 : options.executionModel) === "string" ? options.executionModel : (_b = options == null ? void 0 : options.executionModel) == null ? void 0 : _b.modelName,
|
|
65736
66458
|
options == null ? void 0 : options.systemPrompt,
|
|
65737
|
-
tools
|
|
66459
|
+
tools,
|
|
66460
|
+
options == null ? void 0 : options.mode
|
|
65738
66461
|
);
|
|
65739
66462
|
const resolvedOptions = typeof instructionOrOptions === "string" ? { instruction: instructionOrOptions } : instructionOrOptions;
|
|
65740
66463
|
if (resolvedOptions.page) {
|
|
@@ -65982,14 +66705,14 @@ function isObserveResult(v) {
|
|
|
65982
66705
|
|
|
65983
66706
|
// lib/v3Evaluator.ts
|
|
65984
66707
|
var import_dotenv2 = __toESM(require("dotenv"));
|
|
65985
|
-
var
|
|
66708
|
+
var import_zod23 = require("zod");
|
|
65986
66709
|
init_sdkErrors();
|
|
65987
66710
|
import_dotenv2.default.config();
|
|
65988
|
-
var EvaluationSchema =
|
|
65989
|
-
evaluation:
|
|
65990
|
-
reasoning:
|
|
66711
|
+
var EvaluationSchema = import_zod23.z.object({
|
|
66712
|
+
evaluation: import_zod23.z.enum(["YES", "NO"]),
|
|
66713
|
+
reasoning: import_zod23.z.string()
|
|
65991
66714
|
});
|
|
65992
|
-
var BatchEvaluationSchema =
|
|
66715
|
+
var BatchEvaluationSchema = import_zod23.z.array(EvaluationSchema);
|
|
65993
66716
|
var V3Evaluator = class {
|
|
65994
66717
|
constructor(v3, modelName, modelClientOptions) {
|
|
65995
66718
|
this.silentLogger = () => {
|