@browserbasehq/orca 3.0.2 → 3.0.3-patch
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 +37 -12
- package/dist/index.js +530 -314
- package/package.json +18 -17
- package/LICENSE +0 -21
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
61
61
|
));
|
|
62
62
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
63
63
|
var __async = (__this, __arguments, generator) => {
|
|
64
|
-
return new Promise((
|
|
64
|
+
return new Promise((resolve2, reject) => {
|
|
65
65
|
var fulfilled = (value) => {
|
|
66
66
|
try {
|
|
67
67
|
step(generator.next(value));
|
|
@@ -76,7 +76,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
76
76
|
reject(e);
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
-
var step = (x) => x.done ?
|
|
79
|
+
var step = (x) => x.done ? resolve2(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
80
80
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
81
81
|
});
|
|
82
82
|
};
|
|
@@ -85,7 +85,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
85
85
|
var STAGEHAND_VERSION;
|
|
86
86
|
var init_version = __esm({
|
|
87
87
|
"lib/version.ts"() {
|
|
88
|
-
STAGEHAND_VERSION = "3.0.
|
|
88
|
+
STAGEHAND_VERSION = "3.0.3-patch";
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
91
|
|
|
@@ -461,7 +461,7 @@ var init_executionContextRegistry = __esm({
|
|
|
461
461
|
});
|
|
462
462
|
const after = this.getMainWorld(session, frameId);
|
|
463
463
|
if (after) return after;
|
|
464
|
-
return yield new Promise((
|
|
464
|
+
return yield new Promise((resolve2, reject) => {
|
|
465
465
|
let done = false;
|
|
466
466
|
const onCreated = (evt) => {
|
|
467
467
|
var _a;
|
|
@@ -472,7 +472,7 @@ var init_executionContextRegistry = __esm({
|
|
|
472
472
|
done = true;
|
|
473
473
|
clearTimeout(timer);
|
|
474
474
|
session.off("Runtime.executionContextCreated", onCreated);
|
|
475
|
-
|
|
475
|
+
resolve2(evt.context.id);
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
478
|
};
|
|
@@ -1178,8 +1178,8 @@ function normalizeXPath(x) {
|
|
|
1178
1178
|
if (s.length > 1 && s.endsWith("/")) s = s.slice(0, -1);
|
|
1179
1179
|
return s;
|
|
1180
1180
|
}
|
|
1181
|
-
function parseXPathToSteps(
|
|
1182
|
-
const s =
|
|
1181
|
+
function parseXPathToSteps(path7) {
|
|
1182
|
+
const s = path7.trim();
|
|
1183
1183
|
let i = 0;
|
|
1184
1184
|
const steps = [];
|
|
1185
1185
|
while (i < s.length) {
|
|
@@ -1848,31 +1848,33 @@ var init_snapshot = __esm({
|
|
|
1848
1848
|
var locatorScriptBootstrap, locatorScriptSources, locatorScriptGlobalRefs;
|
|
1849
1849
|
var init_locatorScripts_generated = __esm({
|
|
1850
1850
|
"lib/v3/dom/build/locatorScripts.generated.ts"() {
|
|
1851
|
-
locatorScriptBootstrap = 'if (!globalThis.__stagehandLocatorScripts) { var __stagehandLocatorScriptsFactory=(()=>{var L=Object.defineProperty;var C=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 r of k(e))!H.call(t,r)&&r!==c&&L(t,r,{get:()=>e[r],enumerable:!(n=C(e,r))||n.enumerable});return t};var _=t=>A(L({},"__esModule",{value:!0}),t);var ne={};D(ne,{countCssMatchesPierce:()=>Z,countCssMatchesPrimary:()=>Q,countTextMatches:()=>ee,countXPathMatchesMainWorld:()=>te,dispatchDomClick:()=>W,ensureFileInputElement:()=>I,fillElementValue:()=>O,focusElement:()=>P,isElementChecked:()=>Y,isElementVisible:()=>X,prepareElementForTyping:()=>b,readElementInnerHTML:()=>j,readElementInnerText:()=>K,readElementInputValue:()=>$,readElementTextContent:()=>B,resolveCssSelector:()=>U,resolveCssSelectorPierce:()=>z,resolveTextSelector:()=>G,resolveXPathMainWorld:()=>J,scrollElementToPercent:()=>q,selectElementOptions:()=>V});function I(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}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 r=parseFloat(n.replace("%",""));return Number.isNaN(r)||!Number.isFinite(r)?0:r};try{let c=Math.max(0,Math.min(e(t),100)),n=this,r=n.tagName?.toLowerCase()??"";if(r==="html"||r==="body"){let d=(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,d-s)*(c/100);return n.ownerDocument?.defaultView?.scrollTo({top:g,left:n.ownerDocument?.defaultView?.scrollX??window.scrollX??0,behavior:"smooth"}),!0}let f=n.scrollHeight??0,u=n.clientHeight??0,i=Math.max(0,f-u)*(c/100);return n.scrollTo({top:i,left:n.scrollLeft??0,behavior:"smooth"}),!0}catch{return!1}}var R=new Set(["color","date","datetime-local","month","range","time","week"]),F=new Set(["","email","number","password","search","tel","text","url"]);function b(){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?.(),r=e.createRange?.();if(n&&r)try{r.selectNodeContents(t),n.removeAllRanges(),n.addRange(r)}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,r=t??"";try{let y=f=>{let u;if(typeof n.InputEvent=="function")try{u=new n.InputEvent("input",{bubbles:!0,composed:!0,data:f,inputType:"insertText"})}catch{u=new n.Event("input",{bubbles:!0,composed:!0})}else u=new n.Event("input",{bubbles:!0,composed:!0});e.dispatchEvent(u);let l=new n.Event("change",{bubbles:!0});e.dispatchEvent(l)};if(e instanceof n.HTMLInputElement){let f=(e.type||"").toLowerCase();if(!F.has(f)&&!R.has(f))return{status:"error",reason:`unsupported-input-type:${f}`};let u=t;if(f==="number"){let l=t.trim();if(l!==""&&Number.isNaN(Number(l)))return{status:"error",reason:"invalid-number-value"};u=l}if(r=u,R.has(f)){let l=t.trim();r=l,b.call(e);let i=n.HTMLInputElement.prototype,d=Object.getOwnPropertyDescriptor(i,"value")?.set;return typeof d=="function"?d.call(e,l):e.value=l,e._valueTracker?.setValue?.(l),e.value!==l?{status:"error",reason:"malformed-value"}:(y(l),{status:"done"})}return b.call(e),{status:"needsinput",value:u}}return e instanceof n.HTMLTextAreaElement?(b.call(e),r=t,{status:"needsinput",value:t}):e instanceof n.HTMLSelectElement?{status:"error",reason:"unsupported-element"}:e.isContentEditable?(b.call(e),r=t,{status:"needsinput",value:t}):{status:"error",reason:"unsupported-element"}}catch(y){let f="exception";if(y&&typeof y=="object"){let u=y.message;typeof u=="string"&&u.trim().length>0&&(f=`exception:${u}`)}return{status:"needsinput",value:r,reason:f}}}function P(){try{typeof this.focus=="function"&&this.focus()}catch{}}function V(t){try{if(!(this instanceof HTMLSelectElement))return[];let e=Array.isArray(t)?t:[t],c=new Set(e.map(f=>String(f??"").trim())),n=f=>{let u=(f.label||f.textContent||"").trim(),l=String(f.value??"").trim();return c.has(u)||c.has(l)};if(this.multiple)for(let f of Array.from(this.options))f.selected=n(f);else{let f=!1;for(let u of Array.from(this.options))!f&&n(u)?(u.selected=!0,this.value=u.value,f=!0):u.selected=!1}let r=new Event("input",{bubbles:!0}),y=new Event("change",{bubbles:!0});return this.dispatchEvent(r),this.dispatchEvent(y),Array.from(this.selectedOptions).map(f=>f.value)}catch{return[]}}function X(){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 Y(){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 B(){try{return String(this.textContent??"")}catch{return""}}function j(){try{return String(this.innerHTML??"")}catch{return""}}function K(){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)},v=(t,e)=>{if(!t)return[];let c=new WeakSet,n=new Set,r=[],y=[document],f=u=>{if(!(!u||c.has(u)||r.length>=e)){c.add(u);try{let l=u.querySelectorAll(t);for(let i of l)if(!n.has(i)&&(n.add(i),r.push(i),r.length>=e))return}catch{}try{let i=(u instanceof Document?u:u.host?.ownerDocument??document).createTreeWalker(u,NodeFilter.SHOW_ELEMENT),h;for(;h=i.nextNode();){if(!(h instanceof Element))continue;let d=h.shadowRoot;d&&y.push(d)}}catch{}}};for(;y.length&&r.length<e;){let u=y.shift();u&&f(u)}return r};function U(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e);return v(c,n+1)[n]??null}function z(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e),r=window.__stagehandV3__;if(!r||typeof r.getClosedRoot!="function")return v(c,n+1)[n]??null;let y=d=>{try{return r.getClosedRoot(d)??null}catch{return null}},f=new WeakSet,u=new Set,l=[],i=[document],h=d=>{if(!(!d||f.has(d)||l.length>=n+1)){f.add(d);try{let s=d.querySelectorAll(c);for(let m of s)if(!u.has(m)&&(u.add(m),l.push(m),l.length>=n+1))return}catch{}try{let m=(d instanceof Document?d:d.host?.ownerDocument??document).createTreeWalker(d,NodeFilter.SHOW_ELEMENT),g;for(;g=m.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 d=i.shift();d&&h(d)}return l[n]??null}function G(t,e){let c=String(t??"");if(!c)return null;let n=c.toLowerCase(),r=N(e),y=new Set(["SCRIPT","STYLE","TEMPLATE","NOSCRIPT","HEAD","TITLE","LINK","META","HTML","BODY"]),f=o=>{if(!o)return!1;let p=o.tagName?.toUpperCase()??"";return y.has(p)},u=o=>{try{if(f(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=u(o);return!!p&&p.toLowerCase().includes(n)},i=window.__stagehandV3__,h=i&&typeof i.getClosedRoot=="function"?o=>{try{return i.getClosedRoot(o)??null}catch{return null}}:o=>null,d=new WeakSet,s=[],m=[],g=o=>{!o||d.has(o)||(d.add(o),s.push(o))},w=o=>{try{return(o instanceof Document?o:o?.ownerDocument??document).createTreeWalker(o,NodeFilter.SHOW_ELEMENT)}catch{return null}};for(g(document);s.length;){let o=s.shift();if(!o)continue;o instanceof Element&&l(o)&&m.push({element:o,tag:o.tagName??"",id:o.id??"",className:o.className??"",text:u(o)});let p=w(o);if(!p)continue;let x;for(;x=p.nextNode();){if(!(x instanceof Element))continue;l(x)&&m.push({element:x,tag:x.tagName??"",id:x.id??"",className:x.className??"",text:u(x)});let S=x.shadowRoot;S&&g(S);let T=h(x);T&&g(T)}}let E=[];for(let o of m){let p=o.element,x=!1;for(let S of m)if(o!==S)try{if(p.contains(S.element)){x=!0;break}}catch{}x||E.push(o)}return E[r]?.element??null}function J(t,e){let c=String(t??"").trim();if(!c)return null;let n=N(e),r=window.__stagehandV3__;if(n===0){try{if(r&&typeof r.resolveSimpleXPath=="function"){let s=r.resolveSimpleXPath(c);if(s)return s}}catch{}try{return document.evaluate(c,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch{}}let f=(s=>{let m=String(s||"").trim();if(!m)return[];let g=m.replace(/^xpath=/i,""),w=[],E=0;for(;E<g.length;){let a="child";g.startsWith("//",E)?(a="desc",E+=2):g[E]==="/"&&(a="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),S=(x?.[1]??p).trim(),T=x?.[3]?Math.max(1,Number(x[3])):null,M=S===""?"*":S.toLowerCase();w.push({axis:a,tag:M,index:T})}return w})(c);if(!f.length)return null;let u=r&&typeof r.getClosedRoot=="function"?s=>{try{return r.getClosedRoot(s)??null}catch{return null}}:s=>null,l=s=>{let m=[];if(!s)return m;if(s instanceof Document)return s.documentElement&&m.push(s.documentElement),m;if(s instanceof ShadowRoot||s instanceof DocumentFragment)return m.push(...Array.from(s.children??[])),m;if(s instanceof Element){m.push(...Array.from(s.children??[]));let g=s.shadowRoot;g&&m.push(...Array.from(g.children??[]));let w=u(s);return w&&m.push(...Array.from(w.children??[])),m}return m},i=s=>{let m=[],g=new Set,w=[...l(s)];for(;w.length;){let E=w.shift();!E||g.has(E)||(g.add(E),m.push(E),w.push(...l(E)))}return m},h=[document];for(let s of f){let m=[],g=new Set;for(let w of h){if(!w)continue;let E=s.axis==="child"?l(w):i(w);if(!E.length)continue;let a=E.filter(o=>o instanceof Element?s.tag==="*"?!0:o.localName===s.tag:!1);if(s.index!=null){let o=s.index-1,p=o>=0&&o<a.length?a[o]:null;p&&!g.has(p)&&(g.add(p),m.push(p))}else for(let o of a)g.has(o)||(g.add(o),m.push(o))}if(!m.length)return null;h=m}return h[n]??null}function Q(t){let e=String(t??"").trim();if(!e)return 0;let c=new WeakSet,n=r=>{if(!r||c.has(r))return 0;c.add(r);let y=0;try{let f=r;typeof f.querySelectorAll=="function"&&(y+=f.querySelectorAll(e).length)}catch{}try{let u=(r instanceof Document?r:r?.ownerDocument??document).createTreeWalker(r,NodeFilter.SHOW_ELEMENT),l;for(;l=u.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 Z(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,r=[],y=l=>{!l||n.has(l)||(n.add(l),r.push(l))};y(document);let f=0,u=l=>{let i=l.shadowRoot;i&&y(i);try{let h=c.getClosedRoot(l);h&&y(h)}catch{}};for(;r.length;){let l=r.shift();if(l){try{let i=l;typeof i.querySelectorAll=="function"&&(f+=i.querySelectorAll(e).length)}catch{}try{let h=(l instanceof Document?l:l instanceof ShadowRoot?l.host?.ownerDocument??document:l.ownerDocument??document).createTreeWalker(l,NodeFilter.SHOW_ELEMENT),d;for(;d=h.nextNode();)d instanceof Element&&u(d)}catch{}}}return f}function ee(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"]),r=a=>{if(!a)return!1;let o=a.tagName?.toUpperCase()??"";return n.has(o)},y=a=>{try{if(r(a))return"";let o=a.innerText;if(typeof o=="string"&&o.trim())return o.trim()}catch{}try{let o=a.textContent;if(typeof o=="string")return o.trim()}catch{}return""},f=a=>{let o=y(a);return!!o&&o.toLowerCase().includes(c)},u=window.__stagehandV3__,l=u&&typeof u.getClosedRoot=="function"?a=>{try{return u.getClosedRoot(a)??null}catch{return null}}:a=>null,i=new WeakSet,h=[],d=a=>{!a||i.has(a)||(i.add(a),h.push(a))},s=a=>{try{return(a instanceof Document?a:a?.ownerDocument??document).createTreeWalker(a,NodeFilter.SHOW_ELEMENT)}catch{return null}},m=[];for(d(document);h.length;){let a=h.shift();if(!a)continue;a instanceof Element&&f(a)&&m.push({element:a,tag:a.tagName??"",id:a.id??"",className:a.className??"",text:y(a)});let o=s(a);if(!o)continue;let p;for(;p=o.nextNode();){if(!(p instanceof Element))continue;f(p)&&m.push({element:p,tag:p.tagName??"",id:p.id??"",className:p.className??"",text:y(p)});let x=p.shadowRoot;x&&d(x);let S=l(p);S&&d(S)}}let g=[];for(let a of m){let o=a.element,p=!1;for(let x of m)if(a!==x)try{if(o.contains(x.element)){p=!0;break}}catch{}p||g.push(a)}let w=g.length,E=g.slice(0,5).map(a=>({tag:a.tag,id:a.id,class:a.className,text:a.text}));return{count:w,sample:E,error:null}}function te(t){let e=String(t??"").trim();if(!e)return 0;let n=(i=>{let h=String(i||"").trim().replace(/^xpath=/i,"");if(!h)return[];let d=[],s=0;for(;s<h.length;){let m="child";h.startsWith("//",s)?(m="desc",s+=2):h[s]==="/"&&(m="child",s+=1);let g=s;for(;s<h.length&&h[s]!=="/";)s+=1;let w=h.slice(g,s).trim();if(!w)continue;let E=w.match(/^(.*?)(\\[(\\d+)\\])?$/u),a=(E?.[1]??w).trim(),o=E?.[3]?Math.max(1,Number(E[3])):null,p=a===""?"*":a.toLowerCase();d.push({axis:m,tag:p,index:o})}return d})(e);if(!n.length)return 0;let r=window.__stagehandV3__,y=r&&typeof r.getClosedRoot=="function"?i=>{try{return r.getClosedRoot(i)??null}catch{return null}}:i=>null,f=i=>{let h=[];if(!i)return h;if(i instanceof Document)return i.documentElement&&h.push(i.documentElement),h;if(i instanceof ShadowRoot||i instanceof DocumentFragment)return h.push(...Array.from(i.children??[])),h;if(i instanceof Element){h.push(...Array.from(i.children??[]));let d=i.shadowRoot;d&&h.push(...Array.from(d.children??[]));let s=y(i);return s&&h.push(...Array.from(s.children??[])),h}return h},u=i=>{let h=[],d=new Set,s=[...f(i)];for(;s.length;){let m=s.shift();!m||d.has(m)||(d.add(m),h.push(m),s.push(...f(m)))}return h},l=[document];for(let i of n){let h=[],d=new Set;for(let s of l){if(!s)continue;let m=i.axis==="child"?f(s):u(s);if(!m.length)continue;let g=m.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&&!d.has(E)&&(d.add(E),h.push(E))}else for(let w of g)d.has(w)||(d.add(w),h.push(w))}if(!h.length)return 0;l=h}return l.length}return _(ne);})();\n globalThis.__stagehandLocatorScripts = __stagehandLocatorScriptsFactory;\n}';
|
|
1851
|
+
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}';
|
|
1852
1852
|
locatorScriptSources = {
|
|
1853
|
-
"
|
|
1854
|
-
"
|
|
1855
|
-
"
|
|
1856
|
-
"
|
|
1857
|
-
"
|
|
1858
|
-
"
|
|
1859
|
-
"
|
|
1860
|
-
"
|
|
1853
|
+
"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}}',
|
|
1854
|
+
"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}',
|
|
1855
|
+
"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}}}',
|
|
1856
|
+
"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}}',
|
|
1857
|
+
"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}',
|
|
1858
|
+
"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{}}}',
|
|
1859
|
+
"ensureFileInputElement": 'function R(){try{return(this.tagName?.toLowerCase()??"")!=="input"?!1:String(this.type??"").toLowerCase()==="file"}catch{return!1}}',
|
|
1860
|
+
"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}}}',
|
|
1861
|
+
"focusElement": 'function _(){try{typeof this.focus=="function"&&this.focus()}catch{}}',
|
|
1861
1862
|
"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}}',
|
|
1862
|
-
"isElementVisible": 'function
|
|
1863
|
-
"prepareElementForTyping": 'function
|
|
1863
|
+
"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}}',
|
|
1864
|
+
"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}}',
|
|
1864
1865
|
"readElementInnerHTML": 'function O(){try{return String(this.innerHTML??"")}catch{return""}}',
|
|
1865
|
-
"readElementInnerText": 'function
|
|
1866
|
+
"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""}}',
|
|
1866
1867
|
"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""}}',
|
|
1867
|
-
"readElementTextContent": 'function
|
|
1868
|
-
"resolveCssSelector": 'function
|
|
1869
|
-
"resolveCssSelectorPierce": 'function
|
|
1870
|
-
"resolveTextSelector": 'function $(t,e){let i=String(t??"");if(!i)return null;let n=i.toLowerCase(),
|
|
1871
|
-
"resolveXPathMainWorld": 'function
|
|
1872
|
-
"scrollElementToPercent": 'function
|
|
1873
|
-
"selectElementOptions": 'function
|
|
1868
|
+
"readElementTextContent": 'function P(){try{return String(this.textContent??"")}catch{return""}}',
|
|
1869
|
+
"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}',
|
|
1870
|
+
"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}',
|
|
1871
|
+
"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}',
|
|
1872
|
+
"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}',
|
|
1873
|
+
"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}}',
|
|
1874
|
+
"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[]}}'
|
|
1874
1875
|
};
|
|
1875
1876
|
locatorScriptGlobalRefs = {
|
|
1877
|
+
"assignFilePayloadsToInputElement": "globalThis.__stagehandLocatorScripts.assignFilePayloadsToInputElement",
|
|
1876
1878
|
"countCssMatchesPierce": "globalThis.__stagehandLocatorScripts.countCssMatchesPierce",
|
|
1877
1879
|
"countCssMatchesPrimary": "globalThis.__stagehandLocatorScripts.countCssMatchesPrimary",
|
|
1878
1880
|
"countTextMatches": "globalThis.__stagehandLocatorScripts.countTextMatches",
|
|
@@ -2258,17 +2260,99 @@ var init_selectorResolver = __esm({
|
|
|
2258
2260
|
}
|
|
2259
2261
|
});
|
|
2260
2262
|
|
|
2263
|
+
// lib/v3/understudy/fileUploadUtils.ts
|
|
2264
|
+
function normalizeInputFiles(_0) {
|
|
2265
|
+
return __async(this, arguments, function* (files, opts = {}) {
|
|
2266
|
+
var _a;
|
|
2267
|
+
if (files === null || files === void 0) return [];
|
|
2268
|
+
const flattened = Array.isArray(files) ? files : [files];
|
|
2269
|
+
if (!flattened.length) return [];
|
|
2270
|
+
const baseDir = (_a = opts.baseDir) != null ? _a : process.cwd();
|
|
2271
|
+
const normalized = [];
|
|
2272
|
+
for (const entry of flattened) {
|
|
2273
|
+
if (typeof entry === "string") {
|
|
2274
|
+
const absolutePath = import_path3.default.isAbsolute(entry) ? entry : import_path3.default.resolve(baseDir, entry);
|
|
2275
|
+
const stat = yield statFile(absolutePath);
|
|
2276
|
+
if (!stat.isFile()) {
|
|
2277
|
+
throw new StagehandInvalidArgumentError(
|
|
2278
|
+
`setInputFiles(): expected a file but received directory or special entry at ${absolutePath}`
|
|
2279
|
+
);
|
|
2280
|
+
}
|
|
2281
|
+
const buffer = yield import_fs3.promises.readFile(absolutePath);
|
|
2282
|
+
normalized.push({
|
|
2283
|
+
name: import_path3.default.basename(absolutePath) || "upload.bin",
|
|
2284
|
+
mimeType: DEFAULT_MIME_TYPE,
|
|
2285
|
+
buffer,
|
|
2286
|
+
lastModified: stat.mtimeMs || Date.now(),
|
|
2287
|
+
absolutePath
|
|
2288
|
+
});
|
|
2289
|
+
continue;
|
|
2290
|
+
}
|
|
2291
|
+
if (entry && typeof entry === "object" && "buffer" in entry) {
|
|
2292
|
+
const payload = entry;
|
|
2293
|
+
const buffer = toBuffer(payload.buffer);
|
|
2294
|
+
normalized.push({
|
|
2295
|
+
name: payload.name || "upload.bin",
|
|
2296
|
+
mimeType: payload.mimeType || DEFAULT_MIME_TYPE,
|
|
2297
|
+
buffer,
|
|
2298
|
+
lastModified: typeof payload.lastModified === "number" ? payload.lastModified : Date.now()
|
|
2299
|
+
});
|
|
2300
|
+
continue;
|
|
2301
|
+
}
|
|
2302
|
+
throw new StagehandInvalidArgumentError(
|
|
2303
|
+
"setInputFiles(): expected file path(s) or payload object(s)"
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
return normalized;
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
function statFile(absolutePath) {
|
|
2310
|
+
return __async(this, null, function* () {
|
|
2311
|
+
try {
|
|
2312
|
+
return yield import_fs3.promises.stat(absolutePath);
|
|
2313
|
+
} catch (error) {
|
|
2314
|
+
const code = error == null ? void 0 : error.code;
|
|
2315
|
+
if (code === "ENOENT") {
|
|
2316
|
+
throw new StagehandInvalidArgumentError(
|
|
2317
|
+
`setInputFiles(): file not found at ${absolutePath}`
|
|
2318
|
+
);
|
|
2319
|
+
}
|
|
2320
|
+
throw error;
|
|
2321
|
+
}
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
function toBuffer(data) {
|
|
2325
|
+
if (import_buffer.Buffer.isBuffer(data)) return data;
|
|
2326
|
+
if (data instanceof Uint8Array) return import_buffer.Buffer.from(data);
|
|
2327
|
+
if (typeof data === "string") return import_buffer.Buffer.from(data);
|
|
2328
|
+
if (data instanceof ArrayBuffer) return import_buffer.Buffer.from(new Uint8Array(data));
|
|
2329
|
+
throw new StagehandInvalidArgumentError(
|
|
2330
|
+
"Unsupported file payload buffer type"
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
var import_fs3, import_path3, import_buffer, DEFAULT_MIME_TYPE;
|
|
2334
|
+
var init_fileUploadUtils = __esm({
|
|
2335
|
+
"lib/v3/understudy/fileUploadUtils.ts"() {
|
|
2336
|
+
import_fs3 = require("fs");
|
|
2337
|
+
import_path3 = __toESM(require("path"));
|
|
2338
|
+
import_buffer = require("buffer");
|
|
2339
|
+
init_sdkErrors();
|
|
2340
|
+
DEFAULT_MIME_TYPE = "application/octet-stream";
|
|
2341
|
+
}
|
|
2342
|
+
});
|
|
2343
|
+
|
|
2261
2344
|
// lib/v3/understudy/locator.ts
|
|
2262
|
-
var
|
|
2345
|
+
var fs4, os, path4, MAX_REMOTE_UPLOAD_BYTES, Locator;
|
|
2263
2346
|
var init_locator = __esm({
|
|
2264
2347
|
"lib/v3/understudy/locator.ts"() {
|
|
2265
|
-
|
|
2348
|
+
fs4 = __toESM(require("fs"));
|
|
2266
2349
|
os = __toESM(require("os"));
|
|
2267
|
-
|
|
2268
|
-
import_buffer = require("buffer");
|
|
2350
|
+
path4 = __toESM(require("path"));
|
|
2269
2351
|
init_locatorScripts_generated();
|
|
2270
2352
|
init_selectorResolver();
|
|
2271
2353
|
init_sdkErrors();
|
|
2354
|
+
init_fileUploadUtils();
|
|
2355
|
+
MAX_REMOTE_UPLOAD_BYTES = 50 * 1024 * 1024;
|
|
2272
2356
|
Locator = class _Locator {
|
|
2273
2357
|
constructor(frame, selector, options, nthIndex = 0) {
|
|
2274
2358
|
this.frame = frame;
|
|
@@ -2298,18 +2382,7 @@ var init_locator = __esm({
|
|
|
2298
2382
|
return __async(this, null, function* () {
|
|
2299
2383
|
const session = this.frame.session;
|
|
2300
2384
|
const { objectId } = yield this.resolveNode();
|
|
2301
|
-
const items = Array.isArray(files) ? files : [files];
|
|
2302
2385
|
const tempFiles = [];
|
|
2303
|
-
const filePaths = [];
|
|
2304
|
-
const toBuffer = (data) => {
|
|
2305
|
-
if (import_buffer.Buffer.isBuffer(data)) return data;
|
|
2306
|
-
if (data instanceof Uint8Array) return import_buffer.Buffer.from(data);
|
|
2307
|
-
if (typeof data === "string") return import_buffer.Buffer.from(data);
|
|
2308
|
-
if (data instanceof ArrayBuffer) return import_buffer.Buffer.from(new Uint8Array(data));
|
|
2309
|
-
throw new StagehandInvalidArgumentError(
|
|
2310
|
-
"Unsupported file payload buffer type"
|
|
2311
|
-
);
|
|
2312
|
-
};
|
|
2313
2386
|
try {
|
|
2314
2387
|
try {
|
|
2315
2388
|
const res = yield session.send(
|
|
@@ -2330,28 +2403,32 @@ var init_locator = __esm({
|
|
|
2330
2403
|
e instanceof Error ? e.message : "Unable to verify file input element"
|
|
2331
2404
|
);
|
|
2332
2405
|
}
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
filePaths.push(tmp);
|
|
2406
|
+
const normalized = yield normalizeInputFiles(files);
|
|
2407
|
+
if (!normalized.length) {
|
|
2408
|
+
yield session.send("DOM.setFileInputFiles", {
|
|
2409
|
+
objectId,
|
|
2410
|
+
files: []
|
|
2411
|
+
});
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2414
|
+
if (this.frame.isBrowserRemote()) {
|
|
2415
|
+
yield this.assignFilesViaPayloadInjection(objectId, normalized);
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
const filePaths = [];
|
|
2419
|
+
for (const payload of normalized) {
|
|
2420
|
+
if (payload.absolutePath) {
|
|
2421
|
+
filePaths.push(payload.absolutePath);
|
|
2350
2422
|
continue;
|
|
2351
2423
|
}
|
|
2352
|
-
|
|
2353
|
-
|
|
2424
|
+
const ext = path4.extname(payload.name);
|
|
2425
|
+
const tmp = path4.join(
|
|
2426
|
+
os.tmpdir(),
|
|
2427
|
+
`stagehand-upload-${Date.now()}-${Math.random().toString(36).slice(2)}${ext}`
|
|
2354
2428
|
);
|
|
2429
|
+
yield fs4.promises.writeFile(tmp, payload.buffer);
|
|
2430
|
+
tempFiles.push(tmp);
|
|
2431
|
+
filePaths.push(tmp);
|
|
2355
2432
|
}
|
|
2356
2433
|
yield session.send("DOM.setFileInputFiles", {
|
|
2357
2434
|
objectId,
|
|
@@ -2362,13 +2439,59 @@ var init_locator = __esm({
|
|
|
2362
2439
|
});
|
|
2363
2440
|
for (const p of tempFiles) {
|
|
2364
2441
|
try {
|
|
2365
|
-
yield
|
|
2442
|
+
yield fs4.promises.unlink(p);
|
|
2366
2443
|
} catch (e) {
|
|
2367
2444
|
}
|
|
2368
2445
|
}
|
|
2369
2446
|
}
|
|
2370
2447
|
});
|
|
2371
2448
|
}
|
|
2449
|
+
/**
|
|
2450
|
+
* Remote browser fallback: build File objects inside the page and attach them via JS.
|
|
2451
|
+
*
|
|
2452
|
+
* When Stagehand is driving a browser that cannot see the local filesystem (Browserbase,
|
|
2453
|
+
* remote CDP, etc.), CDP's DOM.setFileInputFiles would fail because Chrome can't reach
|
|
2454
|
+
* our temp files. Instead we base64-encode the payloads, send them into the page, and
|
|
2455
|
+
* let a DOM helper create File objects + dispatch change/input events.
|
|
2456
|
+
*/
|
|
2457
|
+
assignFilesViaPayloadInjection(objectId, files) {
|
|
2458
|
+
return __async(this, null, function* () {
|
|
2459
|
+
var _a;
|
|
2460
|
+
const session = this.frame.session;
|
|
2461
|
+
for (const payload of files) {
|
|
2462
|
+
if (payload.buffer.length > MAX_REMOTE_UPLOAD_BYTES) {
|
|
2463
|
+
throw new StagehandInvalidArgumentError(
|
|
2464
|
+
`setInputFiles(): file "${payload.name}" is larger than the 50MB limit for remote uploads`
|
|
2465
|
+
);
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
const serialized = files.map((payload) => ({
|
|
2469
|
+
name: payload.name,
|
|
2470
|
+
mimeType: payload.mimeType,
|
|
2471
|
+
lastModified: payload.lastModified,
|
|
2472
|
+
base64: payload.buffer.toString("base64")
|
|
2473
|
+
}));
|
|
2474
|
+
const res = yield session.send(
|
|
2475
|
+
"Runtime.callFunctionOn",
|
|
2476
|
+
{
|
|
2477
|
+
objectId,
|
|
2478
|
+
functionDeclaration: locatorScriptSources.assignFilePayloadsToInputElement,
|
|
2479
|
+
arguments: [
|
|
2480
|
+
{
|
|
2481
|
+
value: serialized
|
|
2482
|
+
}
|
|
2483
|
+
],
|
|
2484
|
+
returnByValue: true
|
|
2485
|
+
}
|
|
2486
|
+
);
|
|
2487
|
+
const ok = Boolean((_a = res.result) == null ? void 0 : _a.value);
|
|
2488
|
+
if (!ok) {
|
|
2489
|
+
throw new StagehandInvalidArgumentError(
|
|
2490
|
+
"Unable to assign file payloads to remote input element"
|
|
2491
|
+
);
|
|
2492
|
+
}
|
|
2493
|
+
});
|
|
2494
|
+
}
|
|
2372
2495
|
/**
|
|
2373
2496
|
* Return the DOM backendNodeId for this locator's target element.
|
|
2374
2497
|
* Useful for identity comparisons without needing element handles.
|
|
@@ -3031,13 +3154,13 @@ function ensureChildFrameReady(page, parentFrame, childFrameId, budgetMs) {
|
|
|
3031
3154
|
});
|
|
3032
3155
|
yield parentSession2.send("Runtime.enable").catch(() => {
|
|
3033
3156
|
});
|
|
3034
|
-
yield new Promise((
|
|
3157
|
+
yield new Promise((resolve2) => {
|
|
3035
3158
|
let done = false;
|
|
3036
3159
|
const finish = () => {
|
|
3037
3160
|
if (done) return;
|
|
3038
3161
|
done = true;
|
|
3039
3162
|
parentSession2.off("Page.lifecycleEvent", onLifecycle);
|
|
3040
|
-
|
|
3163
|
+
resolve2();
|
|
3041
3164
|
};
|
|
3042
3165
|
const onLifecycle = (evt) => {
|
|
3043
3166
|
if (evt.frameId !== childFrameId || evt.name !== "DOMContentLoaded" && evt.name !== "load" && evt.name !== "networkIdle" && evt.name !== "networkidle") {
|
|
@@ -3217,8 +3340,8 @@ var init_frameLocator = __esm({
|
|
|
3217
3340
|
});
|
|
3218
3341
|
|
|
3219
3342
|
// lib/v3/understudy/deepLocator.ts
|
|
3220
|
-
function parseXPath(
|
|
3221
|
-
const s =
|
|
3343
|
+
function parseXPath(path7) {
|
|
3344
|
+
const s = path7.trim();
|
|
3222
3345
|
let i = 0;
|
|
3223
3346
|
const steps = [];
|
|
3224
3347
|
while (i < s.length) {
|
|
@@ -3249,10 +3372,10 @@ function buildXPathFromSteps2(steps) {
|
|
|
3249
3372
|
}
|
|
3250
3373
|
function deepLocatorThroughIframes(page, root, xpathOrSelector) {
|
|
3251
3374
|
return __async(this, null, function* () {
|
|
3252
|
-
let
|
|
3253
|
-
if (
|
|
3254
|
-
if (!
|
|
3255
|
-
const steps = parseXPath(
|
|
3375
|
+
let path7 = xpathOrSelector.trim();
|
|
3376
|
+
if (path7.startsWith("xpath=")) path7 = path7.slice("xpath=".length).trim();
|
|
3377
|
+
if (!path7.startsWith("/")) path7 = "/" + path7;
|
|
3378
|
+
const steps = parseXPath(path7);
|
|
3256
3379
|
let fl;
|
|
3257
3380
|
let buf = [];
|
|
3258
3381
|
const flushIntoFrameLocator = () => {
|
|
@@ -4227,11 +4350,11 @@ var require_src = __commonJS({
|
|
|
4227
4350
|
var require_is_docker = __commonJS({
|
|
4228
4351
|
"../../node_modules/.pnpm/is-docker@2.2.1/node_modules/is-docker/index.js"(exports2, module2) {
|
|
4229
4352
|
"use strict";
|
|
4230
|
-
var
|
|
4353
|
+
var fs9 = require("fs");
|
|
4231
4354
|
var isDocker;
|
|
4232
4355
|
function hasDockerEnv() {
|
|
4233
4356
|
try {
|
|
4234
|
-
|
|
4357
|
+
fs9.statSync("/.dockerenv");
|
|
4235
4358
|
return true;
|
|
4236
4359
|
} catch (_) {
|
|
4237
4360
|
return false;
|
|
@@ -4239,7 +4362,7 @@ var require_is_docker = __commonJS({
|
|
|
4239
4362
|
}
|
|
4240
4363
|
function hasDockerCGroup() {
|
|
4241
4364
|
try {
|
|
4242
|
-
return
|
|
4365
|
+
return fs9.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
4243
4366
|
} catch (_) {
|
|
4244
4367
|
return false;
|
|
4245
4368
|
}
|
|
@@ -4258,7 +4381,7 @@ var require_is_wsl = __commonJS({
|
|
|
4258
4381
|
"../../node_modules/.pnpm/is-wsl@2.2.0/node_modules/is-wsl/index.js"(exports2, module2) {
|
|
4259
4382
|
"use strict";
|
|
4260
4383
|
var os3 = require("os");
|
|
4261
|
-
var
|
|
4384
|
+
var fs9 = require("fs");
|
|
4262
4385
|
var isDocker = require_is_docker();
|
|
4263
4386
|
var isWsl3 = () => {
|
|
4264
4387
|
if (process.platform !== "linux") {
|
|
@@ -4271,7 +4394,7 @@ var require_is_wsl = __commonJS({
|
|
|
4271
4394
|
return true;
|
|
4272
4395
|
}
|
|
4273
4396
|
try {
|
|
4274
|
-
return
|
|
4397
|
+
return fs9.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isDocker() : false;
|
|
4275
4398
|
} catch (_) {
|
|
4276
4399
|
return false;
|
|
4277
4400
|
}
|
|
@@ -4357,13 +4480,13 @@ function isSerializableResponse(value) {
|
|
|
4357
4480
|
return true;
|
|
4358
4481
|
}
|
|
4359
4482
|
function createDeferred() {
|
|
4360
|
-
let
|
|
4483
|
+
let resolve2;
|
|
4361
4484
|
let reject;
|
|
4362
4485
|
const promise = new Promise((res, rej) => {
|
|
4363
|
-
|
|
4486
|
+
resolve2 = res;
|
|
4364
4487
|
reject = rej;
|
|
4365
4488
|
});
|
|
4366
|
-
return { promise, resolve:
|
|
4489
|
+
return { promise, resolve: resolve2, reject };
|
|
4367
4490
|
}
|
|
4368
4491
|
function normaliseHeaderName(name) {
|
|
4369
4492
|
return name.toLowerCase();
|
|
@@ -4664,13 +4787,18 @@ var init_frame = __esm({
|
|
|
4664
4787
|
init_locator();
|
|
4665
4788
|
init_sdkErrors();
|
|
4666
4789
|
Frame = class _Frame {
|
|
4667
|
-
constructor(session, frameId, pageId) {
|
|
4790
|
+
constructor(session, frameId, pageId, remoteBrowser) {
|
|
4668
4791
|
this.session = session;
|
|
4669
4792
|
this.frameId = frameId;
|
|
4670
4793
|
this.pageId = pageId;
|
|
4794
|
+
this.remoteBrowser = remoteBrowser;
|
|
4671
4795
|
var _a;
|
|
4672
4796
|
this.sessionId = (_a = this.session.id) != null ? _a : null;
|
|
4673
4797
|
}
|
|
4798
|
+
/** True when the controlled browser runs on a different machine. */
|
|
4799
|
+
isBrowserRemote() {
|
|
4800
|
+
return this.remoteBrowser;
|
|
4801
|
+
}
|
|
4674
4802
|
/** DOM.getNodeForLocation → DOM.describeNode */
|
|
4675
4803
|
getNodeAtLocation(x, y) {
|
|
4676
4804
|
return __async(this, null, function* () {
|
|
@@ -4820,7 +4948,14 @@ var init_frame = __esm({
|
|
|
4820
4948
|
const collect = (tree) => {
|
|
4821
4949
|
var _a;
|
|
4822
4950
|
if (tree.frame.parentId === this.frameId) {
|
|
4823
|
-
frames.push(
|
|
4951
|
+
frames.push(
|
|
4952
|
+
new _Frame(
|
|
4953
|
+
this.session,
|
|
4954
|
+
tree.frame.id,
|
|
4955
|
+
this.pageId,
|
|
4956
|
+
this.remoteBrowser
|
|
4957
|
+
)
|
|
4958
|
+
);
|
|
4824
4959
|
}
|
|
4825
4960
|
(_a = tree.childFrames) == null ? void 0 : _a.forEach(collect);
|
|
4826
4961
|
};
|
|
@@ -4832,11 +4967,11 @@ var init_frame = __esm({
|
|
|
4832
4967
|
waitForLoadState(state = "load") {
|
|
4833
4968
|
return __async(this, null, function* () {
|
|
4834
4969
|
yield this.session.send("Page.enable");
|
|
4835
|
-
yield new Promise((
|
|
4970
|
+
yield new Promise((resolve2) => {
|
|
4836
4971
|
const handler = (evt) => {
|
|
4837
4972
|
if (evt.frameId === this.frameId && evt.name === state) {
|
|
4838
4973
|
this.session.off("Page.lifecycleEvent", handler);
|
|
4839
|
-
|
|
4974
|
+
resolve2();
|
|
4840
4975
|
}
|
|
4841
4976
|
};
|
|
4842
4977
|
this.session.on("Page.lifecycleEvent", handler);
|
|
@@ -5357,8 +5492,8 @@ var init_networkManager = __esm({
|
|
|
5357
5492
|
}
|
|
5358
5493
|
};
|
|
5359
5494
|
const removeObserver = this.addObserver(observer);
|
|
5360
|
-
const promise = new Promise((
|
|
5361
|
-
resolveFn =
|
|
5495
|
+
const promise = new Promise((resolve2, reject) => {
|
|
5496
|
+
resolveFn = resolve2;
|
|
5362
5497
|
rejectFn = reject;
|
|
5363
5498
|
});
|
|
5364
5499
|
maybeIdle();
|
|
@@ -5663,11 +5798,11 @@ var init_navigationResponseTracker = __esm({
|
|
|
5663
5798
|
this.page = params.page;
|
|
5664
5799
|
this.session = params.session;
|
|
5665
5800
|
this.navigationCommandId = params.navigationCommandId;
|
|
5666
|
-
this.responsePromise = new Promise((
|
|
5801
|
+
this.responsePromise = new Promise((resolve2) => {
|
|
5667
5802
|
this.resolveResponse = (value) => {
|
|
5668
5803
|
if (this.responseResolved) return;
|
|
5669
5804
|
this.responseResolved = true;
|
|
5670
|
-
|
|
5805
|
+
resolve2(value);
|
|
5671
5806
|
};
|
|
5672
5807
|
});
|
|
5673
5808
|
this.installListeners();
|
|
@@ -6165,10 +6300,10 @@ var page_exports = {};
|
|
|
6165
6300
|
__export(page_exports, {
|
|
6166
6301
|
Page: () => Page
|
|
6167
6302
|
});
|
|
6168
|
-
var
|
|
6303
|
+
var import_fs6, LIFECYCLE_NAME, Page;
|
|
6169
6304
|
var init_page = __esm({
|
|
6170
6305
|
"lib/v3/understudy/page.ts"() {
|
|
6171
|
-
|
|
6306
|
+
import_fs6 = require("fs");
|
|
6172
6307
|
init_logger();
|
|
6173
6308
|
init_frame();
|
|
6174
6309
|
init_frameLocator();
|
|
@@ -6188,7 +6323,7 @@ var init_page = __esm({
|
|
|
6188
6323
|
networkidle: "networkIdle"
|
|
6189
6324
|
};
|
|
6190
6325
|
Page = class _Page {
|
|
6191
|
-
constructor(conn, mainSession, _targetId, mainFrameId, apiClient) {
|
|
6326
|
+
constructor(conn, mainSession, _targetId, mainFrameId, apiClient, browserIsRemote = false) {
|
|
6192
6327
|
this.conn = conn;
|
|
6193
6328
|
this.mainSession = mainSession;
|
|
6194
6329
|
this._targetId = _targetId;
|
|
@@ -6213,12 +6348,14 @@ var init_page = __esm({
|
|
|
6213
6348
|
this._pressedModifiers = /* @__PURE__ */ new Set();
|
|
6214
6349
|
this.pageId = _targetId;
|
|
6215
6350
|
this.apiClient = apiClient != null ? apiClient : null;
|
|
6351
|
+
this.browserIsRemote = browserIsRemote;
|
|
6216
6352
|
if (mainSession.id) this.sessions.set(mainSession.id, mainSession);
|
|
6217
6353
|
this.registry = new FrameRegistry(_targetId, mainFrameId);
|
|
6218
6354
|
this.mainFrameWrapper = new Frame(
|
|
6219
6355
|
this.mainSession,
|
|
6220
6356
|
mainFrameId,
|
|
6221
|
-
this.pageId
|
|
6357
|
+
this.pageId,
|
|
6358
|
+
this.browserIsRemote
|
|
6222
6359
|
);
|
|
6223
6360
|
this.networkManager = new NetworkManager();
|
|
6224
6361
|
this.networkManager.trackSession(this.mainSession);
|
|
@@ -6318,7 +6455,7 @@ var init_page = __esm({
|
|
|
6318
6455
|
* Factory: create Page and seed registry with the shallow tree from Page.getFrameTree.
|
|
6319
6456
|
* Assumes Page domain is already enabled on the session passed in.
|
|
6320
6457
|
*/
|
|
6321
|
-
static create(conn, session, targetId, apiClient, localBrowserLaunchOptions) {
|
|
6458
|
+
static create(conn, session, targetId, apiClient, localBrowserLaunchOptions, browserIsRemote = false) {
|
|
6322
6459
|
return __async(this, null, function* () {
|
|
6323
6460
|
var _a, _b, _c, _d;
|
|
6324
6461
|
yield session.send("Page.enable").catch(() => {
|
|
@@ -6327,7 +6464,14 @@ var init_page = __esm({
|
|
|
6327
6464
|
});
|
|
6328
6465
|
const { frameTree } = yield session.send("Page.getFrameTree");
|
|
6329
6466
|
const mainFrameId = frameTree.frame.id;
|
|
6330
|
-
const page = new _Page(
|
|
6467
|
+
const page = new _Page(
|
|
6468
|
+
conn,
|
|
6469
|
+
session,
|
|
6470
|
+
targetId,
|
|
6471
|
+
mainFrameId,
|
|
6472
|
+
apiClient,
|
|
6473
|
+
browserIsRemote
|
|
6474
|
+
);
|
|
6331
6475
|
try {
|
|
6332
6476
|
page._currentUrl = String((_b = (_a = frameTree == null ? void 0 : frameTree.frame) == null ? void 0 : _a.url) != null ? _b : page._currentUrl);
|
|
6333
6477
|
if (localBrowserLaunchOptions == null ? void 0 : localBrowserLaunchOptions.viewport) {
|
|
@@ -6375,7 +6519,12 @@ var init_page = __esm({
|
|
|
6375
6519
|
if (newRoot !== prevRoot) {
|
|
6376
6520
|
const oldOrd = (_b = this.frameOrdinals.get(prevRoot)) != null ? _b : 0;
|
|
6377
6521
|
this.frameOrdinals.set(newRoot, oldOrd);
|
|
6378
|
-
this.mainFrameWrapper = new Frame(
|
|
6522
|
+
this.mainFrameWrapper = new Frame(
|
|
6523
|
+
this.mainSession,
|
|
6524
|
+
newRoot,
|
|
6525
|
+
this.pageId,
|
|
6526
|
+
this.browserIsRemote
|
|
6527
|
+
);
|
|
6379
6528
|
}
|
|
6380
6529
|
if (frame.id === this.mainFrameId()) {
|
|
6381
6530
|
try {
|
|
@@ -6481,7 +6630,7 @@ var init_page = __esm({
|
|
|
6481
6630
|
const hit = this.frameCache.get(frameId);
|
|
6482
6631
|
if (hit) return hit;
|
|
6483
6632
|
const sess = this.getSessionForFrame(frameId);
|
|
6484
|
-
const f = new Frame(sess, frameId, this.pageId);
|
|
6633
|
+
const f = new Frame(sess, frameId, this.pageId, this.browserIsRemote);
|
|
6485
6634
|
this.frameCache.set(frameId, f);
|
|
6486
6635
|
return f;
|
|
6487
6636
|
}
|
|
@@ -6998,7 +7147,7 @@ var init_page = __esm({
|
|
|
6998
7147
|
scale: captureScale
|
|
6999
7148
|
});
|
|
7000
7149
|
if (opts.path) {
|
|
7001
|
-
yield
|
|
7150
|
+
yield import_fs6.promises.writeFile(opts.path, buffer);
|
|
7002
7151
|
}
|
|
7003
7152
|
return buffer;
|
|
7004
7153
|
} finally {
|
|
@@ -7672,7 +7821,7 @@ var init_page = __esm({
|
|
|
7672
7821
|
} catch (e) {
|
|
7673
7822
|
}
|
|
7674
7823
|
const wanted = LIFECYCLE_NAME[state];
|
|
7675
|
-
return new Promise((
|
|
7824
|
+
return new Promise((resolve2, reject) => {
|
|
7676
7825
|
let done = false;
|
|
7677
7826
|
let timer = null;
|
|
7678
7827
|
const off = () => {
|
|
@@ -7688,7 +7837,7 @@ var init_page = __esm({
|
|
|
7688
7837
|
timer = null;
|
|
7689
7838
|
}
|
|
7690
7839
|
off();
|
|
7691
|
-
|
|
7840
|
+
resolve2();
|
|
7692
7841
|
};
|
|
7693
7842
|
const onLifecycle = (evt) => {
|
|
7694
7843
|
if (evt.name !== wanted) return;
|
|
@@ -7800,9 +7949,9 @@ module.exports = __toCommonJS(v3_exports);
|
|
|
7800
7949
|
|
|
7801
7950
|
// lib/v3/v3.ts
|
|
7802
7951
|
var import_dotenv = __toESM(require("dotenv"));
|
|
7803
|
-
var
|
|
7952
|
+
var import_fs7 = __toESM(require("fs"));
|
|
7804
7953
|
var import_os2 = __toESM(require("os"));
|
|
7805
|
-
var
|
|
7954
|
+
var import_path6 = __toESM(require("path"));
|
|
7806
7955
|
var import_process2 = __toESM(require("process"));
|
|
7807
7956
|
|
|
7808
7957
|
// lib/utils.ts
|
|
@@ -8045,9 +8194,9 @@ function transformSchema(schema, currentPath) {
|
|
|
8045
8194
|
}
|
|
8046
8195
|
return [schema, []];
|
|
8047
8196
|
}
|
|
8048
|
-
function injectUrls(obj,
|
|
8197
|
+
function injectUrls(obj, path7, idToUrlMapping) {
|
|
8049
8198
|
var _a, _b;
|
|
8050
|
-
if (
|
|
8199
|
+
if (path7.length === 0) return;
|
|
8051
8200
|
const toId = (value) => {
|
|
8052
8201
|
if (typeof value === "number") {
|
|
8053
8202
|
return String(value);
|
|
@@ -8057,7 +8206,7 @@ function injectUrls(obj, path6, idToUrlMapping) {
|
|
|
8057
8206
|
}
|
|
8058
8207
|
return void 0;
|
|
8059
8208
|
};
|
|
8060
|
-
const [key, ...rest] =
|
|
8209
|
+
const [key, ...rest] = path7;
|
|
8061
8210
|
if (key === "*") {
|
|
8062
8211
|
if (Array.isArray(obj)) {
|
|
8063
8212
|
if (rest.length === 0) {
|
|
@@ -8075,7 +8224,7 @@ function injectUrls(obj, path6, idToUrlMapping) {
|
|
|
8075
8224
|
}
|
|
8076
8225
|
if (obj && typeof obj === "object") {
|
|
8077
8226
|
const record = obj;
|
|
8078
|
-
if (
|
|
8227
|
+
if (path7.length === 1) {
|
|
8079
8228
|
const fieldValue = record[key];
|
|
8080
8229
|
const id = toId(fieldValue);
|
|
8081
8230
|
if (id !== void 0) {
|
|
@@ -8132,8 +8281,8 @@ function loadApiKeyFromEnv(provider, logger) {
|
|
|
8132
8281
|
}
|
|
8133
8282
|
return void 0;
|
|
8134
8283
|
}
|
|
8135
|
-
function trimTrailingTextNode(
|
|
8136
|
-
return
|
|
8284
|
+
function trimTrailingTextNode(path7) {
|
|
8285
|
+
return path7 == null ? void 0 : path7.replace(/\/text\(\)(\[\d+\])?$/iu, "");
|
|
8137
8286
|
}
|
|
8138
8287
|
function jsonSchemaToZod(schema) {
|
|
8139
8288
|
switch (schema.type) {
|
|
@@ -8510,12 +8659,12 @@ var ActCache = class {
|
|
|
8510
8659
|
const {
|
|
8511
8660
|
value: entry,
|
|
8512
8661
|
error,
|
|
8513
|
-
path:
|
|
8662
|
+
path: path7
|
|
8514
8663
|
} = yield this.storage.readJson(`${context.cacheKey}.json`);
|
|
8515
|
-
if (error &&
|
|
8664
|
+
if (error && path7) {
|
|
8516
8665
|
this.logger({
|
|
8517
8666
|
category: "cache",
|
|
8518
|
-
message: `failed to read act cache entry: ${
|
|
8667
|
+
message: `failed to read act cache entry: ${path7}`,
|
|
8519
8668
|
level: 2,
|
|
8520
8669
|
auxiliary: {
|
|
8521
8670
|
error: { value: String(error), type: "string" }
|
|
@@ -8556,11 +8705,11 @@ var ActCache = class {
|
|
|
8556
8705
|
actionDescription: result.actionDescription,
|
|
8557
8706
|
message: result.message
|
|
8558
8707
|
};
|
|
8559
|
-
const { error, path:
|
|
8708
|
+
const { error, path: path7 } = yield this.storage.writeJson(
|
|
8560
8709
|
`${context.cacheKey}.json`,
|
|
8561
8710
|
entry
|
|
8562
8711
|
);
|
|
8563
|
-
if (error &&
|
|
8712
|
+
if (error && path7) {
|
|
8564
8713
|
this.logger({
|
|
8565
8714
|
category: "cache",
|
|
8566
8715
|
message: "failed to write act cache entry",
|
|
@@ -8678,11 +8827,11 @@ var ActCache = class {
|
|
|
8678
8827
|
}
|
|
8679
8828
|
refreshCacheEntry(context, entry) {
|
|
8680
8829
|
return __async(this, null, function* () {
|
|
8681
|
-
const { error, path:
|
|
8830
|
+
const { error, path: path7 } = yield this.storage.writeJson(
|
|
8682
8831
|
`${context.cacheKey}.json`,
|
|
8683
8832
|
entry
|
|
8684
8833
|
);
|
|
8685
|
-
if (error &&
|
|
8834
|
+
if (error && path7) {
|
|
8686
8835
|
this.logger({
|
|
8687
8836
|
category: "cache",
|
|
8688
8837
|
message: "failed to update act cache entry after self-heal",
|
|
@@ -8709,14 +8858,14 @@ var ActCache = class {
|
|
|
8709
8858
|
if (!timeout) {
|
|
8710
8859
|
return yield run();
|
|
8711
8860
|
}
|
|
8712
|
-
return yield new Promise((
|
|
8861
|
+
return yield new Promise((resolve2, reject) => {
|
|
8713
8862
|
const timer = setTimeout(() => {
|
|
8714
8863
|
reject(new Error(`act() timed out after ${timeout}ms`));
|
|
8715
8864
|
}, timeout);
|
|
8716
8865
|
void run().then(
|
|
8717
8866
|
(value) => {
|
|
8718
8867
|
clearTimeout(timer);
|
|
8719
|
-
|
|
8868
|
+
resolve2(value);
|
|
8720
8869
|
},
|
|
8721
8870
|
(err) => {
|
|
8722
8871
|
clearTimeout(timer);
|
|
@@ -8824,14 +8973,14 @@ var AgentCache = class {
|
|
|
8824
8973
|
const {
|
|
8825
8974
|
value: entry,
|
|
8826
8975
|
error,
|
|
8827
|
-
path:
|
|
8976
|
+
path: path7
|
|
8828
8977
|
} = yield this.storage.readJson(
|
|
8829
8978
|
`agent-${context.cacheKey}.json`
|
|
8830
8979
|
);
|
|
8831
|
-
if (error &&
|
|
8980
|
+
if (error && path7) {
|
|
8832
8981
|
this.logger({
|
|
8833
8982
|
category: "cache",
|
|
8834
|
-
message: `failed to read agent cache entry: ${
|
|
8983
|
+
message: `failed to read agent cache entry: ${path7}`,
|
|
8835
8984
|
level: 1,
|
|
8836
8985
|
auxiliary: {
|
|
8837
8986
|
error: { value: String(error), type: "string" }
|
|
@@ -8867,11 +9016,11 @@ var AgentCache = class {
|
|
|
8867
9016
|
result: cloneForCache(result),
|
|
8868
9017
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
8869
9018
|
};
|
|
8870
|
-
const { error, path:
|
|
9019
|
+
const { error, path: path7 } = yield this.storage.writeJson(
|
|
8871
9020
|
`agent-${context.cacheKey}.json`,
|
|
8872
9021
|
entry
|
|
8873
9022
|
);
|
|
8874
|
-
if (error &&
|
|
9023
|
+
if (error && path7) {
|
|
8875
9024
|
this.logger({
|
|
8876
9025
|
category: "cache",
|
|
8877
9026
|
message: "failed to write agent cache entry",
|
|
@@ -8983,6 +9132,8 @@ var AgentCache = class {
|
|
|
8983
9132
|
result.usage = {
|
|
8984
9133
|
input_tokens: 0,
|
|
8985
9134
|
output_tokens: 0,
|
|
9135
|
+
reasoning_tokens: 0,
|
|
9136
|
+
cached_input_tokens: 0,
|
|
8986
9137
|
inference_time_ms: 0
|
|
8987
9138
|
};
|
|
8988
9139
|
result.metadata = __spreadProps(__spreadValues({}, (_b = result.metadata) != null ? _b : {}), {
|
|
@@ -9107,7 +9258,7 @@ var AgentCache = class {
|
|
|
9107
9258
|
replayAgentWaitStep(step) {
|
|
9108
9259
|
return __async(this, null, function* () {
|
|
9109
9260
|
if (!step.timeMs || step.timeMs <= 0) return;
|
|
9110
|
-
yield new Promise((
|
|
9261
|
+
yield new Promise((resolve2) => setTimeout(resolve2, step.timeMs));
|
|
9111
9262
|
});
|
|
9112
9263
|
}
|
|
9113
9264
|
replayAgentNavBackStep(step, ctx) {
|
|
@@ -9457,7 +9608,7 @@ function extract(_0) {
|
|
|
9457
9608
|
userProvidedInstructions,
|
|
9458
9609
|
logInferenceToFile = false
|
|
9459
9610
|
}) {
|
|
9460
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9611
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
9461
9612
|
const metadataSchema = import_v32.z.object({
|
|
9462
9613
|
progress: import_v32.z.string().describe(
|
|
9463
9614
|
"progress of what has been extracted so far, as concise as possible"
|
|
@@ -9521,6 +9672,8 @@ function extract(_0) {
|
|
|
9521
9672
|
LLM_output_file: extractResponseFile,
|
|
9522
9673
|
prompt_tokens: (_a = extractUsage == null ? void 0 : extractUsage.prompt_tokens) != null ? _a : 0,
|
|
9523
9674
|
completion_tokens: (_b = extractUsage == null ? void 0 : extractUsage.completion_tokens) != null ? _b : 0,
|
|
9675
|
+
reasoning_tokens: (_c = extractUsage == null ? void 0 : extractUsage.reasoning_tokens) != null ? _c : 0,
|
|
9676
|
+
cached_input_tokens: (_d = extractUsage == null ? void 0 : extractUsage.cached_input_tokens) != null ? _d : 0,
|
|
9524
9677
|
inference_time_ms: extractEndTime - extractStartTime
|
|
9525
9678
|
});
|
|
9526
9679
|
}
|
|
@@ -9582,14 +9735,18 @@ function extract(_0) {
|
|
|
9582
9735
|
timestamp: metadataCallTimestamp,
|
|
9583
9736
|
LLM_input_file: metadataCallFile,
|
|
9584
9737
|
LLM_output_file: metadataResponseFile,
|
|
9585
|
-
prompt_tokens: (
|
|
9586
|
-
completion_tokens: (
|
|
9738
|
+
prompt_tokens: (_e = metadataResponseUsage == null ? void 0 : metadataResponseUsage.prompt_tokens) != null ? _e : 0,
|
|
9739
|
+
completion_tokens: (_f = metadataResponseUsage == null ? void 0 : metadataResponseUsage.completion_tokens) != null ? _f : 0,
|
|
9740
|
+
reasoning_tokens: (_g = metadataResponseUsage == null ? void 0 : metadataResponseUsage.reasoning_tokens) != null ? _g : 0,
|
|
9741
|
+
cached_input_tokens: (_h = metadataResponseUsage == null ? void 0 : metadataResponseUsage.cached_input_tokens) != null ? _h : 0,
|
|
9587
9742
|
inference_time_ms: metadataEndTime - metadataStartTime
|
|
9588
9743
|
});
|
|
9589
9744
|
}
|
|
9590
|
-
const totalPromptTokens = ((
|
|
9591
|
-
const totalCompletionTokens = ((
|
|
9745
|
+
const totalPromptTokens = ((_i = extractUsage == null ? void 0 : extractUsage.prompt_tokens) != null ? _i : 0) + ((_j = metadataResponseUsage == null ? void 0 : metadataResponseUsage.prompt_tokens) != null ? _j : 0);
|
|
9746
|
+
const totalCompletionTokens = ((_k = extractUsage == null ? void 0 : extractUsage.completion_tokens) != null ? _k : 0) + ((_l = metadataResponseUsage == null ? void 0 : metadataResponseUsage.completion_tokens) != null ? _l : 0);
|
|
9592
9747
|
const totalInferenceTimeMs = extractEndTime - extractStartTime + (metadataEndTime - metadataStartTime);
|
|
9748
|
+
const totalReasoningTokens = ((_m = extractUsage == null ? void 0 : extractUsage.reasoning_tokens) != null ? _m : 0) + ((_n = metadataResponseUsage == null ? void 0 : metadataResponseUsage.reasoning_tokens) != null ? _n : 0);
|
|
9749
|
+
const totalCachedInputTokens = ((_o = extractUsage == null ? void 0 : extractUsage.cached_input_tokens) != null ? _o : 0) + ((_p = metadataResponseUsage == null ? void 0 : metadataResponseUsage.cached_input_tokens) != null ? _p : 0);
|
|
9593
9750
|
return __spreadProps(__spreadValues({}, extractedData), {
|
|
9594
9751
|
metadata: {
|
|
9595
9752
|
completed: metadataResponseCompleted,
|
|
@@ -9597,6 +9754,8 @@ function extract(_0) {
|
|
|
9597
9754
|
},
|
|
9598
9755
|
prompt_tokens: totalPromptTokens,
|
|
9599
9756
|
completion_tokens: totalCompletionTokens,
|
|
9757
|
+
reasoning_tokens: totalReasoningTokens,
|
|
9758
|
+
cached_input_tokens: totalCachedInputTokens,
|
|
9600
9759
|
inference_time_ms: totalInferenceTimeMs
|
|
9601
9760
|
});
|
|
9602
9761
|
});
|
|
@@ -9610,7 +9769,7 @@ function observe(_0) {
|
|
|
9610
9769
|
logger,
|
|
9611
9770
|
logInferenceToFile = false
|
|
9612
9771
|
}) {
|
|
9613
|
-
var _a, _b, _c, _d;
|
|
9772
|
+
var _a, _b, _c, _d, _e, _f;
|
|
9614
9773
|
const isGPT5 = llmClient.modelName.includes("gpt-5");
|
|
9615
9774
|
const observeSchema = import_v32.z.object({
|
|
9616
9775
|
elements: import_v32.z.array(
|
|
@@ -9670,6 +9829,8 @@ function observe(_0) {
|
|
|
9670
9829
|
const { data: observeData, usage: observeUsage } = rawResponse;
|
|
9671
9830
|
const promptTokens = (_a = observeUsage == null ? void 0 : observeUsage.prompt_tokens) != null ? _a : 0;
|
|
9672
9831
|
const completionTokens = (_b = observeUsage == null ? void 0 : observeUsage.completion_tokens) != null ? _b : 0;
|
|
9832
|
+
const reasoningTokens = (_c = observeUsage == null ? void 0 : observeUsage.reasoning_tokens) != null ? _c : 0;
|
|
9833
|
+
const cachedInputTokens = (_d = observeUsage == null ? void 0 : observeUsage.cached_input_tokens) != null ? _d : 0;
|
|
9673
9834
|
let responseFile = "";
|
|
9674
9835
|
if (logInferenceToFile) {
|
|
9675
9836
|
const { fileName: responseFileName } = writeTimestampedTxtFile(
|
|
@@ -9688,10 +9849,12 @@ function observe(_0) {
|
|
|
9688
9849
|
LLM_output_file: responseFile,
|
|
9689
9850
|
prompt_tokens: promptTokens,
|
|
9690
9851
|
completion_tokens: completionTokens,
|
|
9852
|
+
reasoning_tokens: reasoningTokens,
|
|
9853
|
+
cached_input_tokens: cachedInputTokens,
|
|
9691
9854
|
inference_time_ms: usageTimeMs
|
|
9692
9855
|
});
|
|
9693
9856
|
}
|
|
9694
|
-
const parsedElements = (
|
|
9857
|
+
const parsedElements = (_f = (_e = observeData.elements) == null ? void 0 : _e.map((el) => {
|
|
9695
9858
|
const base = {
|
|
9696
9859
|
elementId: el.elementId,
|
|
9697
9860
|
description: String(el.description),
|
|
@@ -9699,11 +9862,13 @@ function observe(_0) {
|
|
|
9699
9862
|
arguments: el.arguments
|
|
9700
9863
|
};
|
|
9701
9864
|
return base;
|
|
9702
|
-
})) != null ?
|
|
9865
|
+
})) != null ? _f : [];
|
|
9703
9866
|
return {
|
|
9704
9867
|
elements: parsedElements,
|
|
9705
9868
|
prompt_tokens: promptTokens,
|
|
9706
9869
|
completion_tokens: completionTokens,
|
|
9870
|
+
reasoning_tokens: reasoningTokens,
|
|
9871
|
+
cached_input_tokens: cachedInputTokens,
|
|
9707
9872
|
inference_time_ms: usageTimeMs
|
|
9708
9873
|
};
|
|
9709
9874
|
});
|
|
@@ -9717,7 +9882,7 @@ function act(_0) {
|
|
|
9717
9882
|
logger,
|
|
9718
9883
|
logInferenceToFile = false
|
|
9719
9884
|
}) {
|
|
9720
|
-
var _a, _b;
|
|
9885
|
+
var _a, _b, _c, _d;
|
|
9721
9886
|
const isGPT5 = llmClient.modelName.includes("gpt-5");
|
|
9722
9887
|
const actSchema = import_v32.z.object({
|
|
9723
9888
|
elementId: import_v32.z.string().describe(
|
|
@@ -9772,6 +9937,8 @@ function act(_0) {
|
|
|
9772
9937
|
const { data: actData, usage: actUsage } = rawResponse;
|
|
9773
9938
|
const promptTokens = (_a = actUsage == null ? void 0 : actUsage.prompt_tokens) != null ? _a : 0;
|
|
9774
9939
|
const completionTokens = (_b = actUsage == null ? void 0 : actUsage.completion_tokens) != null ? _b : 0;
|
|
9940
|
+
const reasoningTokens = (_c = actUsage == null ? void 0 : actUsage.reasoning_tokens) != null ? _c : 0;
|
|
9941
|
+
const cachedInputTokens = (_d = actUsage == null ? void 0 : actUsage.cached_input_tokens) != null ? _d : 0;
|
|
9775
9942
|
let responseFile = "";
|
|
9776
9943
|
if (logInferenceToFile) {
|
|
9777
9944
|
const { fileName: responseFileName } = writeTimestampedTxtFile(
|
|
@@ -9790,6 +9957,8 @@ function act(_0) {
|
|
|
9790
9957
|
LLM_output_file: responseFile,
|
|
9791
9958
|
prompt_tokens: promptTokens,
|
|
9792
9959
|
completion_tokens: completionTokens,
|
|
9960
|
+
reasoning_tokens: reasoningTokens,
|
|
9961
|
+
cached_input_tokens: cachedInputTokens,
|
|
9793
9962
|
inference_time_ms: usageTimeMs
|
|
9794
9963
|
});
|
|
9795
9964
|
}
|
|
@@ -9803,6 +9972,8 @@ function act(_0) {
|
|
|
9803
9972
|
element: parsedElement,
|
|
9804
9973
|
prompt_tokens: promptTokens,
|
|
9805
9974
|
completion_tokens: completionTokens,
|
|
9975
|
+
reasoning_tokens: reasoningTokens,
|
|
9976
|
+
cached_input_tokens: cachedInputTokens,
|
|
9806
9977
|
inference_time_ms: usageTimeMs,
|
|
9807
9978
|
twoStep: actData.twoStep
|
|
9808
9979
|
};
|
|
@@ -10352,7 +10523,7 @@ function waitForDomNetworkQuiet(frame, timeoutMs) {
|
|
|
10352
10523
|
]
|
|
10353
10524
|
}).catch(() => {
|
|
10354
10525
|
});
|
|
10355
|
-
return new Promise((
|
|
10526
|
+
return new Promise((resolve2) => {
|
|
10356
10527
|
const inflight = /* @__PURE__ */ new Set();
|
|
10357
10528
|
const meta = /* @__PURE__ */ new Map();
|
|
10358
10529
|
const docByFrame = /* @__PURE__ */ new Map();
|
|
@@ -10443,7 +10614,7 @@ function waitForDomNetworkQuiet(frame, timeoutMs) {
|
|
|
10443
10614
|
if (quietTimer) clearTimeout(quietTimer);
|
|
10444
10615
|
if (stalledRequestSweepTimer) clearInterval(stalledRequestSweepTimer);
|
|
10445
10616
|
clearTimeout(guard);
|
|
10446
|
-
|
|
10617
|
+
resolve2();
|
|
10447
10618
|
};
|
|
10448
10619
|
});
|
|
10449
10620
|
});
|
|
@@ -10493,7 +10664,7 @@ var ActHandler = class {
|
|
|
10493
10664
|
const { instruction, page, variables, timeout, model } = params;
|
|
10494
10665
|
const llmClient = this.resolveLlmClient(model);
|
|
10495
10666
|
const doObserveAndAct = () => __async(this, null, function* () {
|
|
10496
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
10667
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
10497
10668
|
yield waitForDomNetworkQuiet(
|
|
10498
10669
|
page.mainFrame(),
|
|
10499
10670
|
this.defaultDomSettleTimeoutMs
|
|
@@ -10518,12 +10689,16 @@ var ActHandler = class {
|
|
|
10518
10689
|
});
|
|
10519
10690
|
const actPromptTokens = (_b = actInferenceResponse.prompt_tokens) != null ? _b : 0;
|
|
10520
10691
|
const actCompletionTokens = (_c = actInferenceResponse.completion_tokens) != null ? _c : 0;
|
|
10521
|
-
const
|
|
10522
|
-
(_e =
|
|
10692
|
+
const actReasoningTokens = (_d = actInferenceResponse.reasoning_tokens) != null ? _d : 0;
|
|
10693
|
+
const actCachedInputTokens = (_e = actInferenceResponse.cached_input_tokens) != null ? _e : 0;
|
|
10694
|
+
const actInferenceTimeMs = (_f = actInferenceResponse.inference_time_ms) != null ? _f : 0;
|
|
10695
|
+
(_g = this.onMetrics) == null ? void 0 : _g.call(
|
|
10523
10696
|
this,
|
|
10524
10697
|
"ACT" /* ACT */,
|
|
10525
10698
|
actPromptTokens,
|
|
10526
10699
|
actCompletionTokens,
|
|
10700
|
+
actReasoningTokens,
|
|
10701
|
+
actCachedInputTokens,
|
|
10527
10702
|
actInferenceTimeMs
|
|
10528
10703
|
);
|
|
10529
10704
|
const raw = actInferenceResponse.element;
|
|
@@ -10588,7 +10763,7 @@ var ActHandler = class {
|
|
|
10588
10763
|
if (!diffedTree.trim()) {
|
|
10589
10764
|
diffedTree = combinedTree2;
|
|
10590
10765
|
}
|
|
10591
|
-
const combinedXpathMap2 = (
|
|
10766
|
+
const combinedXpathMap2 = (_h = secondSnapshot.combinedXpathMap) != null ? _h : {};
|
|
10592
10767
|
const previousAction = `method: ${chosen.method}, description: ${chosen.description}, arguments: ${chosen.arguments}`;
|
|
10593
10768
|
const stepTwoInstructions = buildStepTwoPrompt(
|
|
10594
10769
|
instruction,
|
|
@@ -10606,12 +10781,14 @@ var ActHandler = class {
|
|
|
10606
10781
|
logger: v3Logger,
|
|
10607
10782
|
logInferenceToFile: this.logInferenceToFile
|
|
10608
10783
|
});
|
|
10609
|
-
(
|
|
10784
|
+
(_n = this.onMetrics) == null ? void 0 : _n.call(
|
|
10610
10785
|
this,
|
|
10611
10786
|
"ACT" /* ACT */,
|
|
10612
|
-
(
|
|
10613
|
-
(
|
|
10614
|
-
(
|
|
10787
|
+
(_i = action2.prompt_tokens) != null ? _i : 0,
|
|
10788
|
+
(_j = action2.completion_tokens) != null ? _j : 0,
|
|
10789
|
+
(_k = action2.reasoning_tokens) != null ? _k : 0,
|
|
10790
|
+
(_l = action2.cached_input_tokens) != null ? _l : 0,
|
|
10791
|
+
(_m = action2.inference_time_ms) != null ? _m : 0
|
|
10615
10792
|
);
|
|
10616
10793
|
const raw2 = action2.element;
|
|
10617
10794
|
const result2 = (() => {
|
|
@@ -10679,7 +10856,7 @@ var ActHandler = class {
|
|
|
10679
10856
|
}
|
|
10680
10857
|
actFromObserveResult(action, page, domSettleTimeoutMs, llmClientOverride) {
|
|
10681
10858
|
return __async(this, null, function* () {
|
|
10682
|
-
var _a, _b, _c, _d, _e, _f;
|
|
10859
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10683
10860
|
const settleTimeout = domSettleTimeoutMs != null ? domSettleTimeoutMs : this.defaultDomSettleTimeoutMs;
|
|
10684
10861
|
const effectiveClient = llmClientOverride != null ? llmClientOverride : this.llmClient;
|
|
10685
10862
|
const method = (_a = action.method) == null ? void 0 : _a.trim();
|
|
@@ -10756,12 +10933,14 @@ var ActHandler = class {
|
|
|
10756
10933
|
logger: v3Logger,
|
|
10757
10934
|
logInferenceToFile: this.logInferenceToFile
|
|
10758
10935
|
});
|
|
10759
|
-
(
|
|
10936
|
+
(_g = this.onMetrics) == null ? void 0 : _g.call(
|
|
10760
10937
|
this,
|
|
10761
10938
|
"ACT" /* ACT */,
|
|
10762
10939
|
(_b = actInferenceResponse.prompt_tokens) != null ? _b : 0,
|
|
10763
10940
|
(_c = actInferenceResponse.completion_tokens) != null ? _c : 0,
|
|
10764
|
-
(_d = actInferenceResponse.
|
|
10941
|
+
(_d = actInferenceResponse.reasoning_tokens) != null ? _d : 0,
|
|
10942
|
+
(_e = actInferenceResponse.cached_input_tokens) != null ? _e : 0,
|
|
10943
|
+
(_f = actInferenceResponse.inference_time_ms) != null ? _f : 0
|
|
10765
10944
|
);
|
|
10766
10945
|
const fallback = actInferenceResponse.element;
|
|
10767
10946
|
if (!fallback) {
|
|
@@ -10775,7 +10954,7 @@ var ActHandler = class {
|
|
|
10775
10954
|
let newSelector = action.selector;
|
|
10776
10955
|
if (typeof fallback.elementId === "string") {
|
|
10777
10956
|
const enc = fallback.elementId;
|
|
10778
|
-
const rawXp = ((
|
|
10957
|
+
const rawXp = ((_h = snapshot.combinedXpathMap) != null ? _h : {})[enc];
|
|
10779
10958
|
const trimmed = trimTrailingTextNode(rawXp);
|
|
10780
10959
|
if (trimmed) newSelector = `xpath=${trimmed}`;
|
|
10781
10960
|
}
|
|
@@ -10894,11 +11073,15 @@ var ExtractHandler = class {
|
|
|
10894
11073
|
metadata: { completed },
|
|
10895
11074
|
prompt_tokens,
|
|
10896
11075
|
completion_tokens,
|
|
11076
|
+
reasoning_tokens = 0,
|
|
11077
|
+
cached_input_tokens = 0,
|
|
10897
11078
|
inference_time_ms
|
|
10898
11079
|
} = _d, rest = __objRest(_d, [
|
|
10899
11080
|
"metadata",
|
|
10900
11081
|
"prompt_tokens",
|
|
10901
11082
|
"completion_tokens",
|
|
11083
|
+
"reasoning_tokens",
|
|
11084
|
+
"cached_input_tokens",
|
|
10902
11085
|
"inference_time_ms"
|
|
10903
11086
|
]);
|
|
10904
11087
|
let output = rest;
|
|
@@ -10923,6 +11106,8 @@ var ExtractHandler = class {
|
|
|
10923
11106
|
"EXTRACT" /* EXTRACT */,
|
|
10924
11107
|
prompt_tokens,
|
|
10925
11108
|
completion_tokens,
|
|
11109
|
+
reasoning_tokens,
|
|
11110
|
+
cached_input_tokens,
|
|
10926
11111
|
inference_time_ms
|
|
10927
11112
|
);
|
|
10928
11113
|
const idToUrl = combinedUrlMap != null ? combinedUrlMap : {};
|
|
@@ -11007,6 +11192,8 @@ var ObserveHandler = class {
|
|
|
11007
11192
|
const {
|
|
11008
11193
|
prompt_tokens = 0,
|
|
11009
11194
|
completion_tokens = 0,
|
|
11195
|
+
reasoning_tokens = 0,
|
|
11196
|
+
cached_input_tokens = 0,
|
|
11010
11197
|
inference_time_ms = 0
|
|
11011
11198
|
} = observationResponse;
|
|
11012
11199
|
(_c = this.onMetrics) == null ? void 0 : _c.call(
|
|
@@ -11014,6 +11201,8 @@ var ObserveHandler = class {
|
|
|
11014
11201
|
"OBSERVE" /* OBSERVE */,
|
|
11015
11202
|
prompt_tokens,
|
|
11016
11203
|
completion_tokens,
|
|
11204
|
+
reasoning_tokens,
|
|
11205
|
+
cached_input_tokens,
|
|
11017
11206
|
inference_time_ms
|
|
11018
11207
|
);
|
|
11019
11208
|
const elementsWithSelectors = (yield Promise.all(
|
|
@@ -11188,7 +11377,7 @@ var createWaitTool = (v3) => (0, import_ai4.tool)({
|
|
|
11188
11377
|
}
|
|
11189
11378
|
}
|
|
11190
11379
|
});
|
|
11191
|
-
yield new Promise((
|
|
11380
|
+
yield new Promise((resolve2) => setTimeout(resolve2, timeMs));
|
|
11192
11381
|
if (timeMs > 0) {
|
|
11193
11382
|
v3.recordAgentReplayStep({ type: "wait", timeMs });
|
|
11194
11383
|
}
|
|
@@ -11724,6 +11913,8 @@ var V3AgentHandler = class {
|
|
|
11724
11913
|
"AGENT" /* AGENT */,
|
|
11725
11914
|
result.usage.inputTokens || 0,
|
|
11726
11915
|
result.usage.outputTokens || 0,
|
|
11916
|
+
result.usage.reasoningTokens || 0,
|
|
11917
|
+
result.usage.cachedInputTokens || 0,
|
|
11727
11918
|
inferenceTimeMs
|
|
11728
11919
|
);
|
|
11729
11920
|
}
|
|
@@ -11735,6 +11926,8 @@ var V3AgentHandler = class {
|
|
|
11735
11926
|
usage: result.usage ? {
|
|
11736
11927
|
input_tokens: result.usage.inputTokens || 0,
|
|
11737
11928
|
output_tokens: result.usage.outputTokens || 0,
|
|
11929
|
+
reasoning_tokens: result.usage.reasoningTokens || 0,
|
|
11930
|
+
cached_input_tokens: result.usage.cachedInputTokens || 0,
|
|
11738
11931
|
inference_time_ms: inferenceTimeMs
|
|
11739
11932
|
} : void 0
|
|
11740
11933
|
};
|
|
@@ -12615,7 +12808,7 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
12615
12808
|
y
|
|
12616
12809
|
}, input);
|
|
12617
12810
|
} else if (action === "drag" || action === "left_click_drag") {
|
|
12618
|
-
const
|
|
12811
|
+
const path7 = input.path || (input.coordinate ? [
|
|
12619
12812
|
{
|
|
12620
12813
|
x: input.start_coordinate[0],
|
|
12621
12814
|
y: input.start_coordinate[1]
|
|
@@ -12627,7 +12820,7 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
12627
12820
|
] : []);
|
|
12628
12821
|
return __spreadValues({
|
|
12629
12822
|
type: "drag",
|
|
12630
|
-
path:
|
|
12823
|
+
path: path7
|
|
12631
12824
|
}, input);
|
|
12632
12825
|
} else if (action === "wait") {
|
|
12633
12826
|
return __spreadValues({
|
|
@@ -13296,9 +13489,11 @@ var GoogleCUAClient = class extends AgentClient {
|
|
|
13296
13489
|
this.environment = "ENVIRONMENT_BROWSER";
|
|
13297
13490
|
this.tools = tools;
|
|
13298
13491
|
this.apiKey = (clientOptions == null ? void 0 : clientOptions.apiKey) || process.env.GEMINI_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY || "";
|
|
13299
|
-
this.
|
|
13492
|
+
this.baseURL = clientOptions == null ? void 0 : clientOptions.baseURL;
|
|
13493
|
+
const genAIOptions = __spreadValues({
|
|
13300
13494
|
apiKey: this.apiKey
|
|
13301
|
-
});
|
|
13495
|
+
}, this.baseURL ? { httpOptions: { baseUrl: this.baseURL } } : {});
|
|
13496
|
+
this.client = new import_genai3.GoogleGenAI(genAIOptions);
|
|
13302
13497
|
if ((clientOptions == null ? void 0 : clientOptions.environment) && typeof clientOptions.environment === "string") {
|
|
13303
13498
|
this.environment = clientOptions.environment;
|
|
13304
13499
|
}
|
|
@@ -13318,9 +13513,9 @@ var GoogleCUAClient = class extends AgentClient {
|
|
|
13318
13513
|
}
|
|
13319
13514
|
]
|
|
13320
13515
|
};
|
|
13321
|
-
this.clientOptions = {
|
|
13516
|
+
this.clientOptions = __spreadValues({
|
|
13322
13517
|
apiKey: this.apiKey
|
|
13323
|
-
};
|
|
13518
|
+
}, this.baseURL ? { baseURL: this.baseURL } : {});
|
|
13324
13519
|
if (this.tools && Object.keys(this.tools).length > 0) {
|
|
13325
13520
|
this.updateGenerateContentConfig();
|
|
13326
13521
|
}
|
|
@@ -13476,7 +13671,7 @@ var GoogleCUAClient = class extends AgentClient {
|
|
|
13476
13671
|
message: `Generating content failed on attempt ${attempt + 1}. Retrying in ${delay2 / 1e3} seconds...`,
|
|
13477
13672
|
level: 2
|
|
13478
13673
|
});
|
|
13479
|
-
yield new Promise((
|
|
13674
|
+
yield new Promise((resolve2) => setTimeout(resolve2, delay2));
|
|
13480
13675
|
}
|
|
13481
13676
|
response = yield this.client.models.generateContent({
|
|
13482
13677
|
model: this.modelName,
|
|
@@ -13574,7 +13769,7 @@ var GoogleCUAClient = class extends AgentClient {
|
|
|
13574
13769
|
const nextAction = result.actions[i + 1];
|
|
13575
13770
|
const isTypingAction = action.type === "type" || nextAction.type === "type";
|
|
13576
13771
|
const delay2 = isTypingAction ? 500 : 200;
|
|
13577
|
-
yield new Promise((
|
|
13772
|
+
yield new Promise((resolve2) => setTimeout(resolve2, delay2));
|
|
13578
13773
|
}
|
|
13579
13774
|
} catch (actionError) {
|
|
13580
13775
|
logger({
|
|
@@ -14089,6 +14284,7 @@ var V3CuaAgentHandler = class {
|
|
|
14089
14284
|
}
|
|
14090
14285
|
execute(optionsOrInstruction) {
|
|
14091
14286
|
return __async(this, null, function* () {
|
|
14287
|
+
var _a, _b;
|
|
14092
14288
|
const options = typeof optionsOrInstruction === "string" ? { instruction: optionsOrInstruction } : optionsOrInstruction;
|
|
14093
14289
|
this.highlightCursor = options.highlightCursor !== false;
|
|
14094
14290
|
const page = yield this.v3.context.awaitActivePage();
|
|
@@ -14121,6 +14317,8 @@ var V3CuaAgentHandler = class {
|
|
|
14121
14317
|
"AGENT" /* AGENT */,
|
|
14122
14318
|
result.usage.input_tokens,
|
|
14123
14319
|
result.usage.output_tokens,
|
|
14320
|
+
(_a = result.usage.reasoning_tokens) != null ? _a : 0,
|
|
14321
|
+
(_b = result.usage.cached_input_tokens) != null ? _b : 0,
|
|
14124
14322
|
inferenceTimeMs
|
|
14125
14323
|
);
|
|
14126
14324
|
}
|
|
@@ -14287,13 +14485,13 @@ var V3CuaAgentHandler = class {
|
|
|
14287
14485
|
return { success: true };
|
|
14288
14486
|
}
|
|
14289
14487
|
case "drag": {
|
|
14290
|
-
const { path:
|
|
14291
|
-
if (Array.isArray(
|
|
14292
|
-
const start =
|
|
14293
|
-
const end =
|
|
14488
|
+
const { path: path7 } = action;
|
|
14489
|
+
if (Array.isArray(path7) && path7.length >= 2) {
|
|
14490
|
+
const start = path7[0];
|
|
14491
|
+
const end = path7[path7.length - 1];
|
|
14294
14492
|
if (recording) {
|
|
14295
14493
|
const xps = yield page.dragAndDrop(start.x, start.y, end.x, end.y, {
|
|
14296
|
-
steps: Math.min(20, Math.max(5,
|
|
14494
|
+
steps: Math.min(20, Math.max(5, path7.length)),
|
|
14297
14495
|
delay: 10,
|
|
14298
14496
|
returnXpath: true
|
|
14299
14497
|
});
|
|
@@ -14315,7 +14513,7 @@ var V3CuaAgentHandler = class {
|
|
|
14315
14513
|
}
|
|
14316
14514
|
} else {
|
|
14317
14515
|
yield page.dragAndDrop(start.x, start.y, end.x, end.y, {
|
|
14318
|
-
steps: Math.min(20, Math.max(5,
|
|
14516
|
+
steps: Math.min(20, Math.max(5, path7.length)),
|
|
14319
14517
|
delay: 10
|
|
14320
14518
|
});
|
|
14321
14519
|
}
|
|
@@ -14534,7 +14732,7 @@ function createBrowserbaseSession(apiKey, projectId, params, resumeSessionId) {
|
|
|
14534
14732
|
}
|
|
14535
14733
|
|
|
14536
14734
|
// ../../node_modules/.pnpm/chrome-launcher@1.2.0/node_modules/chrome-launcher/dist/chrome-launcher.js
|
|
14537
|
-
var
|
|
14735
|
+
var fs6 = __toESM(require("fs"), 1);
|
|
14538
14736
|
var net = __toESM(require("net"), 1);
|
|
14539
14737
|
|
|
14540
14738
|
// ../../node_modules/.pnpm/chrome-launcher@1.2.0/node_modules/chrome-launcher/dist/chrome-finder.js
|
|
@@ -14546,8 +14744,8 @@ __export(chrome_finder_exports, {
|
|
|
14546
14744
|
win32: () => win32,
|
|
14547
14745
|
wsl: () => wsl
|
|
14548
14746
|
});
|
|
14549
|
-
var
|
|
14550
|
-
var
|
|
14747
|
+
var import_fs5 = __toESM(require("fs"), 1);
|
|
14748
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
14551
14749
|
var import_os = require("os");
|
|
14552
14750
|
var import_child_process2 = require("child_process");
|
|
14553
14751
|
var import_escape_string_regexp = __toESM(require_escape_string_regexp(), 1);
|
|
@@ -14891,16 +15089,16 @@ Log.getTimeEntries = () => getEntries();
|
|
|
14891
15089
|
var lighthouse_logger_default = Log;
|
|
14892
15090
|
|
|
14893
15091
|
// ../../node_modules/.pnpm/chrome-launcher@1.2.0/node_modules/chrome-launcher/dist/utils.js
|
|
14894
|
-
var
|
|
15092
|
+
var import_path4 = require("path");
|
|
14895
15093
|
var import_child_process = __toESM(require("child_process"), 1);
|
|
14896
|
-
var
|
|
15094
|
+
var import_fs4 = require("fs");
|
|
14897
15095
|
var import_is_wsl = __toESM(require_is_wsl(), 1);
|
|
14898
15096
|
function defaults(val, def) {
|
|
14899
15097
|
return typeof val === "undefined" ? def : val;
|
|
14900
15098
|
}
|
|
14901
15099
|
function delay(time) {
|
|
14902
15100
|
return __async(this, null, function* () {
|
|
14903
|
-
return new Promise((
|
|
15101
|
+
return new Promise((resolve2) => setTimeout(resolve2, time));
|
|
14904
15102
|
});
|
|
14905
15103
|
}
|
|
14906
15104
|
var LauncherError = class extends Error {
|
|
@@ -14981,15 +15179,15 @@ function toWSLPath(dir, fallback) {
|
|
|
14981
15179
|
return fallback;
|
|
14982
15180
|
}
|
|
14983
15181
|
}
|
|
14984
|
-
function getLocalAppDataPath(
|
|
15182
|
+
function getLocalAppDataPath(path7) {
|
|
14985
15183
|
const userRegExp = /\/mnt\/([a-z])\/Users\/([^\/:]+)\/AppData\//;
|
|
14986
|
-
const results = userRegExp.exec(
|
|
15184
|
+
const results = userRegExp.exec(path7) || [];
|
|
14987
15185
|
return `/mnt/${results[1]}/Users/${results[2]}/AppData/Local`;
|
|
14988
15186
|
}
|
|
14989
|
-
function getWSLLocalAppDataPath(
|
|
15187
|
+
function getWSLLocalAppDataPath(path7) {
|
|
14990
15188
|
const userRegExp = /\/([a-z])\/Users\/([^\/:]+)\/AppData\//;
|
|
14991
|
-
const results = userRegExp.exec(
|
|
14992
|
-
return toWSLPath(`${results[1]}:\\Users\\${results[2]}\\AppData\\Local`, getLocalAppDataPath(
|
|
15189
|
+
const results = userRegExp.exec(path7) || [];
|
|
15190
|
+
return toWSLPath(`${results[1]}:\\Users\\${results[2]}\\AppData\\Local`, getLocalAppDataPath(path7));
|
|
14993
15191
|
}
|
|
14994
15192
|
function makeUnixTmpDir() {
|
|
14995
15193
|
return import_child_process.default.execSync("mktemp -d -t lighthouse.XXXXXXX").toString().trim();
|
|
@@ -14997,8 +15195,8 @@ function makeUnixTmpDir() {
|
|
|
14997
15195
|
function makeWin32TmpDir() {
|
|
14998
15196
|
const winTmpPath = process.env.TEMP || process.env.TMP || (process.env.SystemRoot || process.env.windir) + "\\temp";
|
|
14999
15197
|
const randomNumber = Math.floor(Math.random() * 9e7 + 1e7);
|
|
15000
|
-
const tmpdir2 = (0,
|
|
15001
|
-
(0,
|
|
15198
|
+
const tmpdir2 = (0, import_path4.join)(winTmpPath, "lighthouse." + randomNumber);
|
|
15199
|
+
(0, import_fs4.mkdirSync)(tmpdir2, { recursive: true });
|
|
15002
15200
|
return tmpdir2;
|
|
15003
15201
|
}
|
|
15004
15202
|
|
|
@@ -15027,7 +15225,7 @@ function darwin() {
|
|
|
15027
15225
|
}
|
|
15028
15226
|
(0, import_child_process2.execSync)(`${LSREGISTER} -dump | grep -i 'google chrome\\( canary\\)\\?\\.app' | awk '{$1=""; print $0}'`).toString().split(newLineRegex).forEach((inst) => {
|
|
15029
15227
|
suffixes.forEach((suffix) => {
|
|
15030
|
-
const execPath =
|
|
15228
|
+
const execPath = import_path5.default.join(inst.substring(0, inst.indexOf(".app") + 4).trim(), suffix);
|
|
15031
15229
|
if (canAccess(execPath) && installations.indexOf(execPath) === -1) {
|
|
15032
15230
|
installations.push(execPath);
|
|
15033
15231
|
}
|
|
@@ -15067,7 +15265,7 @@ function linux() {
|
|
|
15067
15265
|
installations.push(customChromePath);
|
|
15068
15266
|
}
|
|
15069
15267
|
const desktopInstallationFolders = [
|
|
15070
|
-
|
|
15268
|
+
import_path5.default.join((0, import_os.homedir)(), ".local/share/applications/"),
|
|
15071
15269
|
"/usr/share/applications/"
|
|
15072
15270
|
];
|
|
15073
15271
|
desktopInstallationFolders.forEach((folder) => {
|
|
@@ -15115,8 +15313,8 @@ function wsl() {
|
|
|
15115
15313
|
function win32() {
|
|
15116
15314
|
const installations = [];
|
|
15117
15315
|
const suffixes = [
|
|
15118
|
-
`${
|
|
15119
|
-
`${
|
|
15316
|
+
`${import_path5.default.sep}Google${import_path5.default.sep}Chrome SxS${import_path5.default.sep}Application${import_path5.default.sep}chrome.exe`,
|
|
15317
|
+
`${import_path5.default.sep}Google${import_path5.default.sep}Chrome${import_path5.default.sep}Application${import_path5.default.sep}chrome.exe`
|
|
15120
15318
|
];
|
|
15121
15319
|
const prefixes = [
|
|
15122
15320
|
process.env.LOCALAPPDATA,
|
|
@@ -15128,7 +15326,7 @@ function win32() {
|
|
|
15128
15326
|
installations.push(customChromePath);
|
|
15129
15327
|
}
|
|
15130
15328
|
prefixes.forEach((prefix) => suffixes.forEach((suffix) => {
|
|
15131
|
-
const chromePath =
|
|
15329
|
+
const chromePath = import_path5.default.join(prefix, suffix);
|
|
15132
15330
|
if (canAccess(chromePath)) {
|
|
15133
15331
|
installations.push(chromePath);
|
|
15134
15332
|
}
|
|
@@ -15151,7 +15349,7 @@ function canAccess(file) {
|
|
|
15151
15349
|
return false;
|
|
15152
15350
|
}
|
|
15153
15351
|
try {
|
|
15154
|
-
|
|
15352
|
+
import_fs5.default.accessSync(file);
|
|
15155
15353
|
return true;
|
|
15156
15354
|
} catch (e) {
|
|
15157
15355
|
return false;
|
|
@@ -15180,12 +15378,12 @@ function findChromeExecutables(folder) {
|
|
|
15180
15378
|
// ../../node_modules/.pnpm/chrome-launcher@1.2.0/node_modules/chrome-launcher/dist/random-port.js
|
|
15181
15379
|
var import_http = require("http");
|
|
15182
15380
|
function getRandomPort() {
|
|
15183
|
-
return new Promise((
|
|
15381
|
+
return new Promise((resolve2, reject) => {
|
|
15184
15382
|
const server = (0, import_http.createServer)();
|
|
15185
15383
|
server.listen(0);
|
|
15186
15384
|
server.once("listening", () => {
|
|
15187
15385
|
const { port } = server.address();
|
|
15188
|
-
server.close(() =>
|
|
15386
|
+
server.close(() => resolve2(port));
|
|
15189
15387
|
});
|
|
15190
15388
|
server.once("error", reject);
|
|
15191
15389
|
});
|
|
@@ -15314,7 +15512,7 @@ var Launcher = class _Launcher {
|
|
|
15314
15512
|
this.opts = opts;
|
|
15315
15513
|
this.tmpDirandPidFileReady = false;
|
|
15316
15514
|
this.remoteDebuggingPipes = null;
|
|
15317
|
-
this.fs = moduleOverrides.fs ||
|
|
15515
|
+
this.fs = moduleOverrides.fs || fs6;
|
|
15318
15516
|
this.spawn = moduleOverrides.spawn || import_child_process3.spawn;
|
|
15319
15517
|
lighthouse_logger_default.setLevel(defaults(this.opts.logLevel, "silent"));
|
|
15320
15518
|
this.startingUrl = defaults(this.opts.startingUrl, "about:blank");
|
|
@@ -15490,7 +15688,7 @@ var Launcher = class _Launcher {
|
|
|
15490
15688
|
}
|
|
15491
15689
|
// resolves if ready, rejects otherwise
|
|
15492
15690
|
isDebuggerReady() {
|
|
15493
|
-
return new Promise((
|
|
15691
|
+
return new Promise((resolve2, reject) => {
|
|
15494
15692
|
const client = net.createConnection(this.port, "127.0.0.1");
|
|
15495
15693
|
client.once("error", (err) => {
|
|
15496
15694
|
this.cleanup(client);
|
|
@@ -15498,14 +15696,14 @@ var Launcher = class _Launcher {
|
|
|
15498
15696
|
});
|
|
15499
15697
|
client.once("connect", () => {
|
|
15500
15698
|
this.cleanup(client);
|
|
15501
|
-
|
|
15699
|
+
resolve2();
|
|
15502
15700
|
});
|
|
15503
15701
|
});
|
|
15504
15702
|
}
|
|
15505
15703
|
// resolves when debugger is ready, rejects after 10 polls
|
|
15506
15704
|
waitUntilReady() {
|
|
15507
15705
|
const launcher = this;
|
|
15508
|
-
return new Promise((
|
|
15706
|
+
return new Promise((resolve2, reject) => {
|
|
15509
15707
|
let retries = 0;
|
|
15510
15708
|
let waitStatus = "Waiting for browser.";
|
|
15511
15709
|
const poll = () => {
|
|
@@ -15517,7 +15715,7 @@ var Launcher = class _Launcher {
|
|
|
15517
15715
|
lighthouse_logger_default.log("ChromeLauncher", waitStatus);
|
|
15518
15716
|
launcher.isDebuggerReady().then(() => {
|
|
15519
15717
|
lighthouse_logger_default.log("ChromeLauncher", waitStatus + `${lighthouse_logger_default.greenify(lighthouse_logger_default.tick)}`);
|
|
15520
|
-
|
|
15718
|
+
resolve2();
|
|
15521
15719
|
}).catch((err) => {
|
|
15522
15720
|
if (retries > launcher.maxConnectionRetries) {
|
|
15523
15721
|
lighthouse_logger_default.error("ChromeLauncher", err.message);
|
|
@@ -15670,7 +15868,7 @@ var AISdkClient = class extends LLMClient {
|
|
|
15670
15868
|
return __async(this, arguments, function* ({
|
|
15671
15869
|
options
|
|
15672
15870
|
}) {
|
|
15673
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
15871
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
15674
15872
|
(_a = this.logger) == null ? void 0 : _a.call(this, {
|
|
15675
15873
|
category: "aisdk",
|
|
15676
15874
|
message: "creating chat completion",
|
|
@@ -15801,10 +15999,12 @@ var AISdkClient = class extends LLMClient {
|
|
|
15801
15999
|
usage: {
|
|
15802
16000
|
prompt_tokens: (_h = objectResponse.usage.inputTokens) != null ? _h : 0,
|
|
15803
16001
|
completion_tokens: (_i = objectResponse.usage.outputTokens) != null ? _i : 0,
|
|
15804
|
-
|
|
16002
|
+
reasoning_tokens: (_j = objectResponse.usage.reasoningTokens) != null ? _j : 0,
|
|
16003
|
+
cached_input_tokens: (_k = objectResponse.usage.cachedInputTokens) != null ? _k : 0,
|
|
16004
|
+
total_tokens: (_l = objectResponse.usage.totalTokens) != null ? _l : 0
|
|
15805
16005
|
}
|
|
15806
16006
|
};
|
|
15807
|
-
(
|
|
16007
|
+
(_m = this.logger) == null ? void 0 : _m.call(this, {
|
|
15808
16008
|
category: "aisdk",
|
|
15809
16009
|
message: "response",
|
|
15810
16010
|
level: 1,
|
|
@@ -15869,12 +16069,14 @@ var AISdkClient = class extends LLMClient {
|
|
|
15869
16069
|
}
|
|
15870
16070
|
],
|
|
15871
16071
|
usage: {
|
|
15872
|
-
prompt_tokens: (
|
|
15873
|
-
completion_tokens: (
|
|
15874
|
-
|
|
16072
|
+
prompt_tokens: (_n = textResponse.usage.inputTokens) != null ? _n : 0,
|
|
16073
|
+
completion_tokens: (_o = textResponse.usage.outputTokens) != null ? _o : 0,
|
|
16074
|
+
reasoning_tokens: (_p = textResponse.usage.reasoningTokens) != null ? _p : 0,
|
|
16075
|
+
cached_input_tokens: (_q = textResponse.usage.cachedInputTokens) != null ? _q : 0,
|
|
16076
|
+
total_tokens: (_r = textResponse.usage.totalTokens) != null ? _r : 0
|
|
15875
16077
|
}
|
|
15876
16078
|
};
|
|
15877
|
-
(
|
|
16079
|
+
(_s = this.logger) == null ? void 0 : _s.call(this, {
|
|
15878
16080
|
category: "aisdk",
|
|
15879
16081
|
message: "response",
|
|
15880
16082
|
level: 2,
|
|
@@ -16712,7 +16914,7 @@ ${firstPartText.text}`;
|
|
|
16712
16914
|
level: 1
|
|
16713
16915
|
});
|
|
16714
16916
|
yield new Promise(
|
|
16715
|
-
(
|
|
16917
|
+
(resolve2) => setTimeout(resolve2, 1e3 * (4 - retries))
|
|
16716
16918
|
);
|
|
16717
16919
|
return this.createChatCompletion({
|
|
16718
16920
|
options,
|
|
@@ -18038,7 +18240,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
18038
18240
|
});
|
|
18039
18241
|
};
|
|
18040
18242
|
}
|
|
18041
|
-
function
|
|
18243
|
+
function resolve(value) {
|
|
18042
18244
|
return __async(this, null, function* () {
|
|
18043
18245
|
if (typeof value === "function") {
|
|
18044
18246
|
value = value();
|
|
@@ -23672,37 +23874,37 @@ function createOpenAI(options = {}) {
|
|
|
23672
23874
|
);
|
|
23673
23875
|
const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
|
|
23674
23876
|
provider: `${providerName}.chat`,
|
|
23675
|
-
url: ({ path:
|
|
23877
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
23676
23878
|
headers: getHeaders,
|
|
23677
23879
|
fetch: options.fetch
|
|
23678
23880
|
});
|
|
23679
23881
|
const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
|
|
23680
23882
|
provider: `${providerName}.completion`,
|
|
23681
|
-
url: ({ path:
|
|
23883
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
23682
23884
|
headers: getHeaders,
|
|
23683
23885
|
fetch: options.fetch
|
|
23684
23886
|
});
|
|
23685
23887
|
const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
|
|
23686
23888
|
provider: `${providerName}.embedding`,
|
|
23687
|
-
url: ({ path:
|
|
23889
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
23688
23890
|
headers: getHeaders,
|
|
23689
23891
|
fetch: options.fetch
|
|
23690
23892
|
});
|
|
23691
23893
|
const createImageModel = (modelId) => new OpenAIImageModel(modelId, {
|
|
23692
23894
|
provider: `${providerName}.image`,
|
|
23693
|
-
url: ({ path:
|
|
23895
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
23694
23896
|
headers: getHeaders,
|
|
23695
23897
|
fetch: options.fetch
|
|
23696
23898
|
});
|
|
23697
23899
|
const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
|
|
23698
23900
|
provider: `${providerName}.transcription`,
|
|
23699
|
-
url: ({ path:
|
|
23901
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
23700
23902
|
headers: getHeaders,
|
|
23701
23903
|
fetch: options.fetch
|
|
23702
23904
|
});
|
|
23703
23905
|
const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
|
|
23704
23906
|
provider: `${providerName}.speech`,
|
|
23705
|
-
url: ({ path:
|
|
23907
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
23706
23908
|
headers: getHeaders,
|
|
23707
23909
|
fetch: options.fetch
|
|
23708
23910
|
});
|
|
@@ -23717,7 +23919,7 @@ function createOpenAI(options = {}) {
|
|
|
23717
23919
|
const createResponsesModel = (modelId) => {
|
|
23718
23920
|
return new OpenAIResponsesLanguageModel(modelId, {
|
|
23719
23921
|
provider: `${providerName}.responses`,
|
|
23720
|
-
url: ({ path:
|
|
23922
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
23721
23923
|
headers: getHeaders,
|
|
23722
23924
|
fetch: options.fetch,
|
|
23723
23925
|
fileIdPrefixes: ["file-"]
|
|
@@ -25625,7 +25827,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
25625
25827
|
headers
|
|
25626
25828
|
}) {
|
|
25627
25829
|
return combineHeaders(
|
|
25628
|
-
yield
|
|
25830
|
+
yield resolve(this.config.headers),
|
|
25629
25831
|
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
|
|
25630
25832
|
headers
|
|
25631
25833
|
);
|
|
@@ -26877,7 +27079,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
26877
27079
|
});
|
|
26878
27080
|
}
|
|
26879
27081
|
const mergedHeaders = combineHeaders(
|
|
26880
|
-
yield
|
|
27082
|
+
yield resolve(this.config.headers),
|
|
26881
27083
|
headers
|
|
26882
27084
|
);
|
|
26883
27085
|
if (values.length === 1) {
|
|
@@ -27584,7 +27786,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
27584
27786
|
const { args, warnings } = yield this.getArgs(options);
|
|
27585
27787
|
const body = JSON.stringify(args);
|
|
27586
27788
|
const mergedHeaders = combineHeaders(
|
|
27587
|
-
yield
|
|
27789
|
+
yield resolve(this.config.headers),
|
|
27588
27790
|
options.headers
|
|
27589
27791
|
);
|
|
27590
27792
|
const {
|
|
@@ -27697,7 +27899,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
27697
27899
|
const { args, warnings } = yield this.getArgs(options);
|
|
27698
27900
|
const body = JSON.stringify(args);
|
|
27699
27901
|
const headers = combineHeaders(
|
|
27700
|
-
yield
|
|
27902
|
+
yield resolve(this.config.headers),
|
|
27701
27903
|
options.headers
|
|
27702
27904
|
);
|
|
27703
27905
|
const { responseHeaders, value: response } = yield postJsonToApi({
|
|
@@ -28222,7 +28424,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
28222
28424
|
};
|
|
28223
28425
|
const { responseHeaders, value: response } = yield postJsonToApi({
|
|
28224
28426
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
28225
|
-
headers: combineHeaders(yield
|
|
28427
|
+
headers: combineHeaders(yield resolve(this.config.headers), headers),
|
|
28226
28428
|
body,
|
|
28227
28429
|
failedResponseHandler: googleFailedResponseHandler,
|
|
28228
28430
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -30389,7 +30591,7 @@ function createXai(options = {}) {
|
|
|
30389
30591
|
const createImageModel = (modelId) => {
|
|
30390
30592
|
return new OpenAICompatibleImageModel(modelId, {
|
|
30391
30593
|
provider: "xai.image",
|
|
30392
|
-
url: ({ path:
|
|
30594
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
30393
30595
|
headers: getHeaders,
|
|
30394
30596
|
fetch: options.fetch,
|
|
30395
30597
|
errorStructure: xaiErrorStructure
|
|
@@ -34656,14 +34858,14 @@ function createAzure(options = {}) {
|
|
|
34656
34858
|
description: "Azure OpenAI resource name"
|
|
34657
34859
|
});
|
|
34658
34860
|
const apiVersion = (_a = options.apiVersion) != null ? _a : "v1";
|
|
34659
|
-
const url = ({ path:
|
|
34861
|
+
const url = ({ path: path7, modelId }) => {
|
|
34660
34862
|
var _a2;
|
|
34661
34863
|
const baseUrlPrefix = (_a2 = options.baseURL) != null ? _a2 : `https://${getResourceName()}.openai.azure.com/openai`;
|
|
34662
34864
|
let fullUrl;
|
|
34663
34865
|
if (options.useDeploymentBasedUrls) {
|
|
34664
|
-
fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${
|
|
34866
|
+
fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path7}`);
|
|
34665
34867
|
} else {
|
|
34666
|
-
fullUrl = new URL(`${baseUrlPrefix}/v1${
|
|
34868
|
+
fullUrl = new URL(`${baseUrlPrefix}/v1${path7}`);
|
|
34667
34869
|
}
|
|
34668
34870
|
fullUrl.searchParams.set("api-version", apiVersion);
|
|
34669
34871
|
return fullUrl.toString();
|
|
@@ -35579,7 +35781,7 @@ function createGroq(options = {}) {
|
|
|
35579
35781
|
);
|
|
35580
35782
|
const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
|
|
35581
35783
|
provider: "groq.chat",
|
|
35582
|
-
url: ({ path:
|
|
35784
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
35583
35785
|
headers: getHeaders,
|
|
35584
35786
|
fetch: options.fetch
|
|
35585
35787
|
});
|
|
@@ -35594,7 +35796,7 @@ function createGroq(options = {}) {
|
|
|
35594
35796
|
const createTranscriptionModel = (modelId) => {
|
|
35595
35797
|
return new GroqTranscriptionModel(modelId, {
|
|
35596
35798
|
provider: "groq.transcription",
|
|
35597
|
-
url: ({ path:
|
|
35799
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
35598
35800
|
headers: getHeaders,
|
|
35599
35801
|
fetch: options.fetch
|
|
35600
35802
|
});
|
|
@@ -35649,7 +35851,7 @@ function createCerebras(options = {}) {
|
|
|
35649
35851
|
const createLanguageModel = (modelId) => {
|
|
35650
35852
|
return new OpenAICompatibleChatLanguageModel(modelId, {
|
|
35651
35853
|
provider: `cerebras.chat`,
|
|
35652
|
-
url: ({ path:
|
|
35854
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
35653
35855
|
headers: getHeaders,
|
|
35654
35856
|
fetch: options.fetch,
|
|
35655
35857
|
errorStructure: cerebrasErrorStructure,
|
|
@@ -35768,7 +35970,7 @@ function createTogetherAI(options = {}) {
|
|
|
35768
35970
|
);
|
|
35769
35971
|
const getCommonModelConfig = (modelType) => ({
|
|
35770
35972
|
provider: `togetherai.${modelType}`,
|
|
35771
|
-
url: ({ path:
|
|
35973
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
35772
35974
|
headers: getHeaders,
|
|
35773
35975
|
fetch: options.fetch
|
|
35774
35976
|
});
|
|
@@ -36654,7 +36856,7 @@ function createDeepSeek(options = {}) {
|
|
|
36654
36856
|
const createLanguageModel = (modelId) => {
|
|
36655
36857
|
return new OpenAICompatibleChatLanguageModel(modelId, {
|
|
36656
36858
|
provider: `deepseek.chat`,
|
|
36657
|
-
url: ({ path:
|
|
36859
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
36658
36860
|
headers: getHeaders,
|
|
36659
36861
|
fetch: options.fetch,
|
|
36660
36862
|
metadataExtractor: deepSeekMetadataExtractor
|
|
@@ -38364,13 +38566,13 @@ function createOllama(options = {}) {
|
|
|
38364
38566
|
}, options.headers);
|
|
38365
38567
|
const createCompletionModel = (modelId, settings = {}) => new OllamaCompletionLanguageModel(modelId, settings, {
|
|
38366
38568
|
provider: `${providerName}.completion`,
|
|
38367
|
-
url: ({ path:
|
|
38569
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
38368
38570
|
headers: getHeaders,
|
|
38369
38571
|
fetch: options.fetch
|
|
38370
38572
|
});
|
|
38371
38573
|
const createEmbeddingModel = (modelId, settings = {}) => new OllamaEmbeddingModel(modelId, settings, {
|
|
38372
38574
|
provider: `${providerName}.embedding`,
|
|
38373
|
-
url: ({ path:
|
|
38575
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
38374
38576
|
headers: getHeaders,
|
|
38375
38577
|
fetch: options.fetch
|
|
38376
38578
|
});
|
|
@@ -38385,7 +38587,7 @@ function createOllama(options = {}) {
|
|
|
38385
38587
|
const createResponsesModel = (modelId) => {
|
|
38386
38588
|
return new OllamaResponsesLanguageModel(modelId, {
|
|
38387
38589
|
provider: `${providerName}.responses`,
|
|
38388
|
-
url: ({ path:
|
|
38590
|
+
url: ({ path: path7 }) => `${baseURL}${path7}`,
|
|
38389
38591
|
headers: getHeaders,
|
|
38390
38592
|
fetch: options.fetch
|
|
38391
38593
|
});
|
|
@@ -38721,7 +38923,7 @@ var AISdkClient2 = class extends LLMClient {
|
|
|
38721
38923
|
return __async(this, arguments, function* ({
|
|
38722
38924
|
options
|
|
38723
38925
|
}) {
|
|
38724
|
-
var _a, _b, _c, _d, _e, _f;
|
|
38926
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
38725
38927
|
const formattedMessages = options.messages.map(
|
|
38726
38928
|
(message) => {
|
|
38727
38929
|
if (Array.isArray(message.content)) {
|
|
@@ -38782,7 +38984,9 @@ var AISdkClient2 = class extends LLMClient {
|
|
|
38782
38984
|
usage: {
|
|
38783
38985
|
prompt_tokens: (_a = response2.usage.inputTokens) != null ? _a : 0,
|
|
38784
38986
|
completion_tokens: (_b = response2.usage.outputTokens) != null ? _b : 0,
|
|
38785
|
-
|
|
38987
|
+
reasoning_tokens: (_c = response2.usage.reasoningTokens) != null ? _c : 0,
|
|
38988
|
+
cached_input_tokens: (_d = response2.usage.cachedInputTokens) != null ? _d : 0,
|
|
38989
|
+
total_tokens: (_e = response2.usage.totalTokens) != null ? _e : 0
|
|
38786
38990
|
}
|
|
38787
38991
|
};
|
|
38788
38992
|
}
|
|
@@ -38801,9 +39005,11 @@ var AISdkClient2 = class extends LLMClient {
|
|
|
38801
39005
|
return {
|
|
38802
39006
|
data: response.text,
|
|
38803
39007
|
usage: {
|
|
38804
|
-
prompt_tokens: (
|
|
38805
|
-
completion_tokens: (
|
|
38806
|
-
|
|
39008
|
+
prompt_tokens: (_f = response.usage.inputTokens) != null ? _f : 0,
|
|
39009
|
+
completion_tokens: (_g = response.usage.outputTokens) != null ? _g : 0,
|
|
39010
|
+
reasoning_tokens: (_h = response.usage.reasoningTokens) != null ? _h : 0,
|
|
39011
|
+
cached_input_tokens: (_i = response.usage.cachedInputTokens) != null ? _i : 0,
|
|
39012
|
+
total_tokens: (_j = response.usage.totalTokens) != null ? _j : 0
|
|
38807
39013
|
}
|
|
38808
39014
|
};
|
|
38809
39015
|
});
|
|
@@ -38853,8 +39059,8 @@ var CdpConnection = class _CdpConnection {
|
|
|
38853
39059
|
static connect(wsUrl) {
|
|
38854
39060
|
return __async(this, null, function* () {
|
|
38855
39061
|
const ws = new import_ws.default(wsUrl);
|
|
38856
|
-
yield new Promise((
|
|
38857
|
-
ws.once("open", () =>
|
|
39062
|
+
yield new Promise((resolve2, reject) => {
|
|
39063
|
+
ws.once("open", () => resolve2());
|
|
38858
39064
|
ws.once("error", (e) => reject(e));
|
|
38859
39065
|
});
|
|
38860
39066
|
return new _CdpConnection(ws);
|
|
@@ -38865,7 +39071,7 @@ var CdpConnection = class _CdpConnection {
|
|
|
38865
39071
|
yield this.send("Target.setAutoAttach", {
|
|
38866
39072
|
autoAttach: true,
|
|
38867
39073
|
flatten: true,
|
|
38868
|
-
waitForDebuggerOnStart:
|
|
39074
|
+
waitForDebuggerOnStart: false,
|
|
38869
39075
|
filter: [
|
|
38870
39076
|
{ type: "worker", exclude: true },
|
|
38871
39077
|
{ type: "shared_worker", exclude: true },
|
|
@@ -38881,9 +39087,9 @@ var CdpConnection = class _CdpConnection {
|
|
|
38881
39087
|
const id = this.nextId++;
|
|
38882
39088
|
const payload = { id, method, params };
|
|
38883
39089
|
const stack = (_a = new Error().stack) == null ? void 0 : _a.split("\n").slice(1, 4).join("\n");
|
|
38884
|
-
const p = new Promise((
|
|
39090
|
+
const p = new Promise((resolve2, reject) => {
|
|
38885
39091
|
this.inflight.set(id, {
|
|
38886
|
-
resolve:
|
|
39092
|
+
resolve: resolve2,
|
|
38887
39093
|
reject,
|
|
38888
39094
|
sessionId: null,
|
|
38889
39095
|
method,
|
|
@@ -38908,8 +39114,8 @@ var CdpConnection = class _CdpConnection {
|
|
|
38908
39114
|
}
|
|
38909
39115
|
close() {
|
|
38910
39116
|
return __async(this, null, function* () {
|
|
38911
|
-
yield new Promise((
|
|
38912
|
-
this.ws.once("close", () =>
|
|
39117
|
+
yield new Promise((resolve2) => {
|
|
39118
|
+
this.ws.once("close", () => resolve2());
|
|
38913
39119
|
this.ws.close();
|
|
38914
39120
|
});
|
|
38915
39121
|
});
|
|
@@ -38981,9 +39187,9 @@ var CdpConnection = class _CdpConnection {
|
|
|
38981
39187
|
const id = this.nextId++;
|
|
38982
39188
|
const payload = { id, method, params, sessionId };
|
|
38983
39189
|
const stack = (_a = new Error().stack) == null ? void 0 : _a.split("\n").slice(1, 4).join("\n");
|
|
38984
|
-
const p = new Promise((
|
|
39190
|
+
const p = new Promise((resolve2, reject) => {
|
|
38985
39191
|
this.inflight.set(id, {
|
|
38986
|
-
resolve:
|
|
39192
|
+
resolve: resolve2,
|
|
38987
39193
|
reject,
|
|
38988
39194
|
sessionId,
|
|
38989
39195
|
method,
|
|
@@ -39048,12 +39254,15 @@ init_logger();
|
|
|
39048
39254
|
// lib/v3/dom/build/scriptV3Content.ts
|
|
39049
39255
|
var v3ScriptContent = '(()=>{function b(_={}){let S=n=>{let{hostToRoot:l}=n,m=t=>{let o=[];if(t instanceof Document)return t.documentElement&&o.push(t.documentElement),o;if(t instanceof ShadowRoot||t instanceof DocumentFragment)return o.push(...Array.from(t.children)),o;if(t instanceof Element){o.push(...Array.from(t.children));let a=t.shadowRoot;a&&o.push(...Array.from(a.children));let r=l.get(t);return r&&o.push(...Array.from(r.children)),o}return o},v=t=>{let o=[],a=[...m(t)];for(;a.length;){let r=a.shift();o.push(r),a.push(...m(r))}return o},y=t=>{let o=String(t||"").trim();if(!o)return null;let a=o.replace(/^xpath=/i,""),r=[];{let e=0;for(;e<a.length;){let d="child";a.startsWith("//",e)?(d="desc",e+=2):a[e]==="/"&&(d="child",e+=1);let h=e;for(;e<a.length&&a[e]!=="/";)e++;let u=a.slice(h,e).trim();if(!u)continue;let p=u.match(/^(.*?)(\\[(\\d+)\\])?$/u),i=(p?.[1]??u).trim(),c=p?.[3]?Math.max(1,Number(p[3])):null,R=i===""?"*":i.toLowerCase();r.push({axis:d,raw:u,tag:R,index:c})}}n.debug&&console.info("[v3-piercer][resolve] start",{url:location.href,steps:r.map(e=>({axis:e.axis,raw:e.raw,tag:e.tag,index:e.index}))});let g=[document];for(let e of r){let d=e.index,h=null;for(let u of g){let p=e.axis==="child"?m(u):v(u),i=[];for(let c of p)(e.tag==="*"||c.localName===e.tag)&&i.push(c);if(n.debug&&console.info("[v3-piercer][resolve] step",{axis:e.axis,tag:e.tag,index:d,poolCount:p.length,matchesCount:i.length}),!!i.length){if(d!=null){let c=d-1;h=c>=0&&c<i.length?i[c]:null}else h=i[0];if(h)break}}if(!h)return n.debug&&console.info("[v3-piercer][resolve] no-match",{step:e.raw}),null;g=[h]}let E=g.length?g[0]:null;return n.debug&&console.info("[v3-piercer][resolve] done",{found:!!E,tag:E?.localName??""}),E};window.__stagehandV3__={getClosedRoot:t=>l.get(t),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:n.openCount,closed:n.closedCount}),resolveSimpleXPath:y}},f=Element.prototype.attachShadow;if(f.__v3Patched&&f.__v3State){f.__v3State.debug=!0,S(f.__v3State);return}let s={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},x=f,w=function(n){let l=n?.mode??"open",m=x.call(this,n);try{s.hostToRoot.set(this,m),l==="closed"?s.closedCount++:s.openCount++,s.debug&&console.info("[v3-piercer] attachShadow",{tag:this.tagName?.toLowerCase()??"",mode:l,url:location.href})}catch{}return m};if(w.__v3Patched=!0,w.__v3State=s,Object.defineProperty(Element.prototype,"attachShadow",{configurable:!0,writable:!0,value:w}),_.tagExisting)try{let n=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;n.nextNode();){let l=n.currentNode;l.shadowRoot&&(s.hostToRoot.set(l,l.shadowRoot),s.openCount++)}}catch{}window.__stagehandV3Injected=!0,S(s),s.debug&&console.info("[v3-piercer] installed",{url:location.href,isTop:window.top===window,readyState:document.readyState})}b({debug:!0,tagExisting:!1});})();\n';
|
|
39050
39256
|
|
|
39257
|
+
// lib/v3/dom/build/reRenderScriptContent.ts
|
|
39258
|
+
var reRenderScriptContent = '(()=>{function s(){try{let o=window.__stagehandV3__;if(!o||typeof o.getClosedRoot!="function")return;let t=[],r=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;r.nextNode();){let e=r.currentNode,n=e.tagName?.toLowerCase()??"";if(!n.includes("-")||typeof customElements?.get!="function"||!customElements.get(n))continue;let c=!!e.shadowRoot,i=!!o.getClosedRoot(e);c||i||t.push(e)}for(let e of t)try{let n=e.cloneNode(!0);e.replaceWith(n)}catch{}o.stats&&t.length&&console.info("[v3-piercer] rerender",{count:t.length})}catch(o){console.info("[v3-piercer] rerender error",{message:String(o??"")})}}s();})();\n';
|
|
39259
|
+
|
|
39051
39260
|
// lib/v3/understudy/piercer.ts
|
|
39052
39261
|
function installV3PiercerIntoSession(session) {
|
|
39053
39262
|
return __async(this, null, function* () {
|
|
39054
39263
|
var _a, _b;
|
|
39055
|
-
yield session.send("Page.enable").catch(() =>
|
|
39056
|
-
|
|
39264
|
+
const pageEnabled = yield session.send("Page.enable").then(() => true).catch(() => false);
|
|
39265
|
+
if (!pageEnabled) return false;
|
|
39057
39266
|
yield session.send("Runtime.enable").catch(() => {
|
|
39058
39267
|
});
|
|
39059
39268
|
try {
|
|
@@ -39063,7 +39272,7 @@ function installV3PiercerIntoSession(session) {
|
|
|
39063
39272
|
);
|
|
39064
39273
|
} catch (e) {
|
|
39065
39274
|
const msg = String((_b = (_a = e == null ? void 0 : e.message) != null ? _a : e) != null ? _b : "");
|
|
39066
|
-
if (msg.includes("Session with given id not found")) return;
|
|
39275
|
+
if (msg.includes("Session with given id not found")) return false;
|
|
39067
39276
|
}
|
|
39068
39277
|
yield session.send("Runtime.evaluate", {
|
|
39069
39278
|
expression: v3ScriptContent,
|
|
@@ -39071,6 +39280,13 @@ function installV3PiercerIntoSession(session) {
|
|
|
39071
39280
|
awaitPromise: true
|
|
39072
39281
|
}).catch(() => {
|
|
39073
39282
|
});
|
|
39283
|
+
yield session.send("Runtime.evaluate", {
|
|
39284
|
+
expression: reRenderScriptContent,
|
|
39285
|
+
returnByValue: true,
|
|
39286
|
+
awaitPromise: false
|
|
39287
|
+
}).catch(() => {
|
|
39288
|
+
});
|
|
39289
|
+
return true;
|
|
39074
39290
|
});
|
|
39075
39291
|
}
|
|
39076
39292
|
|
|
@@ -39177,9 +39393,12 @@ var V3Context = class _V3Context {
|
|
|
39177
39393
|
ensurePiercer(session) {
|
|
39178
39394
|
return __async(this, null, function* () {
|
|
39179
39395
|
const key = this.sessionKey(session);
|
|
39180
|
-
if (this._piercerInstalled.has(key)) return;
|
|
39181
|
-
yield installV3PiercerIntoSession(session);
|
|
39182
|
-
|
|
39396
|
+
if (this._piercerInstalled.has(key)) return true;
|
|
39397
|
+
const installed = yield installV3PiercerIntoSession(session);
|
|
39398
|
+
if (installed) {
|
|
39399
|
+
this._piercerInstalled.add(key);
|
|
39400
|
+
}
|
|
39401
|
+
return installed;
|
|
39183
39402
|
});
|
|
39184
39403
|
}
|
|
39185
39404
|
/** Mark a page target as the most-recent one (active). */
|
|
@@ -39317,11 +39536,7 @@ var V3Context = class _V3Context {
|
|
|
39317
39536
|
this.conn.on(
|
|
39318
39537
|
"Target.attachedToTarget",
|
|
39319
39538
|
(evt) => __async(this, null, function* () {
|
|
39320
|
-
yield this.onAttachedToTarget(
|
|
39321
|
-
evt.targetInfo,
|
|
39322
|
-
evt.sessionId,
|
|
39323
|
-
evt.waitingForDebugger === true
|
|
39324
|
-
);
|
|
39539
|
+
yield this.onAttachedToTarget(evt.targetInfo, evt.sessionId);
|
|
39325
39540
|
})
|
|
39326
39541
|
);
|
|
39327
39542
|
this.conn.on(
|
|
@@ -39374,36 +39589,28 @@ var V3Context = class _V3Context {
|
|
|
39374
39589
|
* if the parent is known; otherwise stage until parent `frameAttached`.
|
|
39375
39590
|
* - Resume the target only after listeners are wired.
|
|
39376
39591
|
*/
|
|
39377
|
-
onAttachedToTarget(info, sessionId
|
|
39592
|
+
onAttachedToTarget(info, sessionId) {
|
|
39378
39593
|
return __async(this, null, function* () {
|
|
39379
39594
|
var _a;
|
|
39380
39595
|
const session = this.conn.getSession(sessionId);
|
|
39381
39596
|
if (!session) return;
|
|
39382
39597
|
if (this._sessionInit.has(sessionId)) return;
|
|
39383
39598
|
this._sessionInit.add(sessionId);
|
|
39384
|
-
const pageEnabled = yield session.send("Page.enable").then(() => true).catch(() => false);
|
|
39385
|
-
if (!pageEnabled) {
|
|
39386
|
-
if (waitingForDebugger) {
|
|
39387
|
-
yield session.send("Runtime.runIfWaitingForDebugger").catch(() => {
|
|
39388
|
-
});
|
|
39389
|
-
}
|
|
39390
|
-
return;
|
|
39391
|
-
}
|
|
39392
|
-
yield session.send("Page.setLifecycleEventsEnabled", { enabled: true }).catch(() => {
|
|
39393
|
-
});
|
|
39394
39599
|
yield session.send("Runtime.runIfWaitingForDebugger").catch(() => {
|
|
39395
39600
|
});
|
|
39396
39601
|
executionContexts.attachSession(session);
|
|
39397
|
-
yield
|
|
39602
|
+
const piercerReady = yield this.ensurePiercer(session);
|
|
39603
|
+
if (!piercerReady) return;
|
|
39604
|
+
yield session.send("Page.setLifecycleEventsEnabled", { enabled: true }).catch(() => {
|
|
39398
39605
|
});
|
|
39399
|
-
yield this.ensurePiercer(session);
|
|
39400
39606
|
if (isTopLevelPage(info)) {
|
|
39401
39607
|
const page = yield Page.create(
|
|
39402
39608
|
this.conn,
|
|
39403
39609
|
session,
|
|
39404
39610
|
info.targetId,
|
|
39405
39611
|
this.apiClient,
|
|
39406
|
-
this.localBrowserLaunchOptions
|
|
39612
|
+
this.localBrowserLaunchOptions,
|
|
39613
|
+
this.env === "BROWSERBASE"
|
|
39407
39614
|
);
|
|
39408
39615
|
this.wireSessionToOwnerPage(sessionId, page);
|
|
39409
39616
|
this.pagesByTarget.set(info.targetId, page);
|
|
@@ -39419,10 +39626,6 @@ var V3Context = class _V3Context {
|
|
|
39419
39626
|
page.seedCurrentUrl((_a = pendingSeedUrl != null ? pendingSeedUrl : info.url) != null ? _a : "");
|
|
39420
39627
|
this._pushActive(info.targetId);
|
|
39421
39628
|
this.installFrameEventBridges(sessionId, page);
|
|
39422
|
-
if (waitingForDebugger) {
|
|
39423
|
-
yield session.send("Runtime.runIfWaitingForDebugger").catch(() => {
|
|
39424
|
-
});
|
|
39425
|
-
}
|
|
39426
39629
|
return;
|
|
39427
39630
|
}
|
|
39428
39631
|
try {
|
|
@@ -39450,51 +39653,13 @@ var V3Context = class _V3Context {
|
|
|
39450
39653
|
owner.adoptOopifSession(session, childMainId);
|
|
39451
39654
|
this.sessionOwnerPage.set(sessionId, owner);
|
|
39452
39655
|
this.installFrameEventBridges(sessionId, owner);
|
|
39656
|
+
void executionContexts.waitForMainWorld(session, childMainId).catch(() => {
|
|
39657
|
+
});
|
|
39453
39658
|
} else {
|
|
39454
39659
|
this.pendingOopifByMainFrame.set(childMainId, sessionId);
|
|
39455
39660
|
}
|
|
39456
39661
|
} catch (e) {
|
|
39457
39662
|
}
|
|
39458
|
-
if (info.type === "iframe" && !waitingForDebugger) {
|
|
39459
|
-
try {
|
|
39460
|
-
yield session.send("Page.setLifecycleEventsEnabled", { enabled: true }).catch(() => {
|
|
39461
|
-
});
|
|
39462
|
-
const loadWait = new Promise((resolve3) => {
|
|
39463
|
-
const handler = (evt) => {
|
|
39464
|
-
if (evt.name === "load") {
|
|
39465
|
-
session.off("Page.lifecycleEvent", handler);
|
|
39466
|
-
resolve3();
|
|
39467
|
-
}
|
|
39468
|
-
};
|
|
39469
|
-
session.on("Page.lifecycleEvent", handler);
|
|
39470
|
-
});
|
|
39471
|
-
yield session.send("Runtime.evaluate", {
|
|
39472
|
-
expression: "location.reload()",
|
|
39473
|
-
returnByValue: true,
|
|
39474
|
-
awaitPromise: false
|
|
39475
|
-
}).catch(() => {
|
|
39476
|
-
});
|
|
39477
|
-
yield Promise.race([
|
|
39478
|
-
loadWait,
|
|
39479
|
-
new Promise((r) => setTimeout(r, 3e3))
|
|
39480
|
-
]);
|
|
39481
|
-
yield this.ensurePiercer(session);
|
|
39482
|
-
} catch (e) {
|
|
39483
|
-
v3Logger({
|
|
39484
|
-
category: "ctx",
|
|
39485
|
-
message: "child reload attempt failed (continuing)",
|
|
39486
|
-
level: 2,
|
|
39487
|
-
auxiliary: {
|
|
39488
|
-
sessionId: { value: String(sessionId), type: "string" },
|
|
39489
|
-
err: { value: String(e), type: "string" }
|
|
39490
|
-
}
|
|
39491
|
-
});
|
|
39492
|
-
}
|
|
39493
|
-
}
|
|
39494
|
-
if (waitingForDebugger) {
|
|
39495
|
-
yield session.send("Runtime.runIfWaitingForDebugger").catch(() => {
|
|
39496
|
-
});
|
|
39497
|
-
}
|
|
39498
39663
|
});
|
|
39499
39664
|
}
|
|
39500
39665
|
/**
|
|
@@ -39877,18 +40042,28 @@ var StagehandAPIClient = class {
|
|
|
39877
40042
|
const metrics = {
|
|
39878
40043
|
actPromptTokens: 0,
|
|
39879
40044
|
actCompletionTokens: 0,
|
|
40045
|
+
actReasoningTokens: 0,
|
|
40046
|
+
actCachedInputTokens: 0,
|
|
39880
40047
|
actInferenceTimeMs: 0,
|
|
39881
40048
|
extractPromptTokens: 0,
|
|
39882
40049
|
extractCompletionTokens: 0,
|
|
40050
|
+
extractReasoningTokens: 0,
|
|
40051
|
+
extractCachedInputTokens: 0,
|
|
39883
40052
|
extractInferenceTimeMs: 0,
|
|
39884
40053
|
observePromptTokens: 0,
|
|
39885
40054
|
observeCompletionTokens: 0,
|
|
40055
|
+
observeReasoningTokens: 0,
|
|
40056
|
+
observeCachedInputTokens: 0,
|
|
39886
40057
|
observeInferenceTimeMs: 0,
|
|
39887
40058
|
agentPromptTokens: 0,
|
|
39888
40059
|
agentCompletionTokens: 0,
|
|
40060
|
+
agentReasoningTokens: 0,
|
|
40061
|
+
agentCachedInputTokens: 0,
|
|
39889
40062
|
agentInferenceTimeMs: 0,
|
|
39890
40063
|
totalPromptTokens: 0,
|
|
39891
40064
|
totalCompletionTokens: 0,
|
|
40065
|
+
totalReasoningTokens: 0,
|
|
40066
|
+
totalCachedInputTokens: 0,
|
|
39892
40067
|
totalInferenceTimeMs: 0
|
|
39893
40068
|
};
|
|
39894
40069
|
const pages = apiData.pages || [];
|
|
@@ -39900,26 +40075,38 @@ var StagehandAPIClient = class {
|
|
|
39900
40075
|
if (tokenUsage) {
|
|
39901
40076
|
const inputTokens = tokenUsage.inputTokens || 0;
|
|
39902
40077
|
const outputTokens = tokenUsage.outputTokens || 0;
|
|
40078
|
+
const reasoningTokens = tokenUsage.reasoningTokens || 0;
|
|
40079
|
+
const cachedInputTokens = tokenUsage.cachedInputTokens || 0;
|
|
39903
40080
|
const timeMs = tokenUsage.timeMs || 0;
|
|
39904
40081
|
if (method === "act") {
|
|
39905
40082
|
metrics.actPromptTokens += inputTokens;
|
|
39906
40083
|
metrics.actCompletionTokens += outputTokens;
|
|
40084
|
+
metrics.actReasoningTokens += reasoningTokens;
|
|
40085
|
+
metrics.actCachedInputTokens += cachedInputTokens;
|
|
39907
40086
|
metrics.actInferenceTimeMs += timeMs;
|
|
39908
40087
|
} else if (method === "extract") {
|
|
39909
40088
|
metrics.extractPromptTokens += inputTokens;
|
|
39910
40089
|
metrics.extractCompletionTokens += outputTokens;
|
|
40090
|
+
metrics.extractReasoningTokens += reasoningTokens;
|
|
40091
|
+
metrics.extractCachedInputTokens += cachedInputTokens;
|
|
39911
40092
|
metrics.extractInferenceTimeMs += timeMs;
|
|
39912
40093
|
} else if (method === "observe") {
|
|
39913
40094
|
metrics.observePromptTokens += inputTokens;
|
|
39914
40095
|
metrics.observeCompletionTokens += outputTokens;
|
|
40096
|
+
metrics.observeReasoningTokens += reasoningTokens;
|
|
40097
|
+
metrics.observeCachedInputTokens += cachedInputTokens;
|
|
39915
40098
|
metrics.observeInferenceTimeMs += timeMs;
|
|
39916
40099
|
} else if (method === "agent") {
|
|
39917
40100
|
metrics.agentPromptTokens += inputTokens;
|
|
39918
40101
|
metrics.agentCompletionTokens += outputTokens;
|
|
40102
|
+
metrics.agentReasoningTokens += reasoningTokens;
|
|
40103
|
+
metrics.agentCachedInputTokens += cachedInputTokens;
|
|
39919
40104
|
metrics.agentInferenceTimeMs += timeMs;
|
|
39920
40105
|
}
|
|
39921
40106
|
metrics.totalPromptTokens += inputTokens;
|
|
39922
40107
|
metrics.totalCompletionTokens += outputTokens;
|
|
40108
|
+
metrics.totalReasoningTokens += reasoningTokens;
|
|
40109
|
+
metrics.totalCachedInputTokens += cachedInputTokens;
|
|
39923
40110
|
metrics.totalInferenceTimeMs += timeMs;
|
|
39924
40111
|
}
|
|
39925
40112
|
}
|
|
@@ -40013,7 +40200,7 @@ var StagehandAPIClient = class {
|
|
|
40013
40200
|
}
|
|
40014
40201
|
});
|
|
40015
40202
|
}
|
|
40016
|
-
request(
|
|
40203
|
+
request(path7, options) {
|
|
40017
40204
|
return __async(this, null, function* () {
|
|
40018
40205
|
var _a;
|
|
40019
40206
|
const defaultHeaders = {
|
|
@@ -40031,7 +40218,7 @@ var StagehandAPIClient = class {
|
|
|
40031
40218
|
defaultHeaders["Content-Type"] = "application/json";
|
|
40032
40219
|
}
|
|
40033
40220
|
const response = yield this.fetchWithCookies(
|
|
40034
|
-
`${(_a = process.env.STAGEHAND_API_URL) != null ? _a : "https://api.stagehand.browserbase.com/v1"}${
|
|
40221
|
+
`${(_a = process.env.STAGEHAND_API_URL) != null ? _a : "https://api.stagehand.browserbase.com/v1"}${path7}`,
|
|
40035
40222
|
__spreadProps(__spreadValues({}, options), {
|
|
40036
40223
|
headers: __spreadValues(__spreadValues({}, defaultHeaders), options.headers)
|
|
40037
40224
|
})
|
|
@@ -40088,18 +40275,28 @@ var _V3 = class _V3 {
|
|
|
40088
40275
|
this.stagehandMetrics = {
|
|
40089
40276
|
actPromptTokens: 0,
|
|
40090
40277
|
actCompletionTokens: 0,
|
|
40278
|
+
actReasoningTokens: 0,
|
|
40279
|
+
actCachedInputTokens: 0,
|
|
40091
40280
|
actInferenceTimeMs: 0,
|
|
40092
40281
|
extractPromptTokens: 0,
|
|
40093
40282
|
extractCompletionTokens: 0,
|
|
40283
|
+
extractReasoningTokens: 0,
|
|
40284
|
+
extractCachedInputTokens: 0,
|
|
40094
40285
|
extractInferenceTimeMs: 0,
|
|
40095
40286
|
observePromptTokens: 0,
|
|
40096
40287
|
observeCompletionTokens: 0,
|
|
40288
|
+
observeReasoningTokens: 0,
|
|
40289
|
+
observeCachedInputTokens: 0,
|
|
40097
40290
|
observeInferenceTimeMs: 0,
|
|
40098
40291
|
agentPromptTokens: 0,
|
|
40099
40292
|
agentCompletionTokens: 0,
|
|
40293
|
+
agentReasoningTokens: 0,
|
|
40294
|
+
agentCachedInputTokens: 0,
|
|
40100
40295
|
agentInferenceTimeMs: 0,
|
|
40101
40296
|
totalPromptTokens: 0,
|
|
40102
40297
|
totalCompletionTokens: 0,
|
|
40298
|
+
totalReasoningTokens: 0,
|
|
40299
|
+
totalCachedInputTokens: 0,
|
|
40103
40300
|
totalInferenceTimeMs: 0
|
|
40104
40301
|
};
|
|
40105
40302
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -40134,9 +40331,6 @@ var _V3 = class _V3 {
|
|
|
40134
40331
|
this.llmProvider = new LLMProvider(this.logger);
|
|
40135
40332
|
this.domSettleTimeoutMs = opts.domSettleTimeout;
|
|
40136
40333
|
this.disableAPI = (_g = opts.disableAPI) != null ? _g : false;
|
|
40137
|
-
if (this.experimental && !this.disableAPI) {
|
|
40138
|
-
throw new ExperimentalApiConflictError();
|
|
40139
|
-
}
|
|
40140
40334
|
const baseClientOptions = clientOptions ? __spreadValues({}, clientOptions) : {};
|
|
40141
40335
|
if (opts.llmClient) {
|
|
40142
40336
|
this.llmClient = opts.llmClient;
|
|
@@ -40286,34 +40480,50 @@ var _V3 = class _V3 {
|
|
|
40286
40480
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
40287
40481
|
});
|
|
40288
40482
|
}
|
|
40289
|
-
updateMetrics(functionName, promptTokens, completionTokens, inferenceTimeMs) {
|
|
40483
|
+
updateMetrics(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) {
|
|
40290
40484
|
switch (functionName) {
|
|
40291
40485
|
case "ACT" /* ACT */:
|
|
40292
40486
|
this.stagehandMetrics.actPromptTokens += promptTokens;
|
|
40293
40487
|
this.stagehandMetrics.actCompletionTokens += completionTokens;
|
|
40488
|
+
this.stagehandMetrics.actReasoningTokens += reasoningTokens;
|
|
40489
|
+
this.stagehandMetrics.actCachedInputTokens += cachedInputTokens;
|
|
40294
40490
|
this.stagehandMetrics.actInferenceTimeMs += inferenceTimeMs;
|
|
40295
40491
|
break;
|
|
40296
40492
|
case "EXTRACT" /* EXTRACT */:
|
|
40297
40493
|
this.stagehandMetrics.extractPromptTokens += promptTokens;
|
|
40298
40494
|
this.stagehandMetrics.extractCompletionTokens += completionTokens;
|
|
40495
|
+
this.stagehandMetrics.extractReasoningTokens += reasoningTokens;
|
|
40496
|
+
this.stagehandMetrics.extractCachedInputTokens += cachedInputTokens;
|
|
40299
40497
|
this.stagehandMetrics.extractInferenceTimeMs += inferenceTimeMs;
|
|
40300
40498
|
break;
|
|
40301
40499
|
case "OBSERVE" /* OBSERVE */:
|
|
40302
40500
|
this.stagehandMetrics.observePromptTokens += promptTokens;
|
|
40303
40501
|
this.stagehandMetrics.observeCompletionTokens += completionTokens;
|
|
40502
|
+
this.stagehandMetrics.observeReasoningTokens += reasoningTokens;
|
|
40503
|
+
this.stagehandMetrics.observeCachedInputTokens += cachedInputTokens;
|
|
40304
40504
|
this.stagehandMetrics.observeInferenceTimeMs += inferenceTimeMs;
|
|
40305
40505
|
break;
|
|
40306
40506
|
case "AGENT" /* AGENT */:
|
|
40307
40507
|
this.stagehandMetrics.agentPromptTokens += promptTokens;
|
|
40308
40508
|
this.stagehandMetrics.agentCompletionTokens += completionTokens;
|
|
40509
|
+
this.stagehandMetrics.agentReasoningTokens += reasoningTokens;
|
|
40510
|
+
this.stagehandMetrics.agentCachedInputTokens += cachedInputTokens;
|
|
40309
40511
|
this.stagehandMetrics.agentInferenceTimeMs += inferenceTimeMs;
|
|
40310
40512
|
break;
|
|
40311
40513
|
}
|
|
40312
|
-
this.updateTotalMetrics(
|
|
40514
|
+
this.updateTotalMetrics(
|
|
40515
|
+
promptTokens,
|
|
40516
|
+
completionTokens,
|
|
40517
|
+
reasoningTokens,
|
|
40518
|
+
cachedInputTokens,
|
|
40519
|
+
inferenceTimeMs
|
|
40520
|
+
);
|
|
40313
40521
|
}
|
|
40314
|
-
updateTotalMetrics(promptTokens, completionTokens, inferenceTimeMs) {
|
|
40522
|
+
updateTotalMetrics(promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) {
|
|
40315
40523
|
this.stagehandMetrics.totalPromptTokens += promptTokens;
|
|
40316
40524
|
this.stagehandMetrics.totalCompletionTokens += completionTokens;
|
|
40525
|
+
this.stagehandMetrics.totalReasoningTokens += reasoningTokens;
|
|
40526
|
+
this.stagehandMetrics.totalCachedInputTokens += cachedInputTokens;
|
|
40317
40527
|
this.stagehandMetrics.totalInferenceTimeMs += inferenceTimeMs;
|
|
40318
40528
|
}
|
|
40319
40529
|
_immediateShutdown(reason) {
|
|
@@ -40406,10 +40616,12 @@ var _V3 = class _V3 {
|
|
|
40406
40616
|
(_a = this.opts.systemPrompt) != null ? _a : "",
|
|
40407
40617
|
this.logInferenceToFile,
|
|
40408
40618
|
(_b = this.opts.selfHeal) != null ? _b : true,
|
|
40409
|
-
(functionName, promptTokens, completionTokens, inferenceTimeMs) => this.updateMetrics(
|
|
40619
|
+
(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(
|
|
40410
40620
|
functionName,
|
|
40411
40621
|
promptTokens,
|
|
40412
40622
|
completionTokens,
|
|
40623
|
+
reasoningTokens,
|
|
40624
|
+
cachedInputTokens,
|
|
40413
40625
|
inferenceTimeMs
|
|
40414
40626
|
),
|
|
40415
40627
|
this.domSettleTimeoutMs
|
|
@@ -40422,10 +40634,12 @@ var _V3 = class _V3 {
|
|
|
40422
40634
|
(_c = this.opts.systemPrompt) != null ? _c : "",
|
|
40423
40635
|
this.logInferenceToFile,
|
|
40424
40636
|
this.experimental,
|
|
40425
|
-
(functionName, promptTokens, completionTokens, inferenceTimeMs) => this.updateMetrics(
|
|
40637
|
+
(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(
|
|
40426
40638
|
functionName,
|
|
40427
40639
|
promptTokens,
|
|
40428
40640
|
completionTokens,
|
|
40641
|
+
reasoningTokens,
|
|
40642
|
+
cachedInputTokens,
|
|
40429
40643
|
inferenceTimeMs
|
|
40430
40644
|
)
|
|
40431
40645
|
);
|
|
@@ -40437,10 +40651,12 @@ var _V3 = class _V3 {
|
|
|
40437
40651
|
(_d = this.opts.systemPrompt) != null ? _d : "",
|
|
40438
40652
|
this.logInferenceToFile,
|
|
40439
40653
|
this.experimental,
|
|
40440
|
-
(functionName, promptTokens, completionTokens, inferenceTimeMs) => this.updateMetrics(
|
|
40654
|
+
(functionName, promptTokens, completionTokens, reasoningTokens, cachedInputTokens, inferenceTimeMs) => this.updateMetrics(
|
|
40441
40655
|
functionName,
|
|
40442
40656
|
promptTokens,
|
|
40443
40657
|
completionTokens,
|
|
40658
|
+
reasoningTokens,
|
|
40659
|
+
cachedInputTokens,
|
|
40444
40660
|
inferenceTimeMs
|
|
40445
40661
|
)
|
|
40446
40662
|
);
|
|
@@ -40483,9 +40699,9 @@ var _V3 = class _V3 {
|
|
|
40483
40699
|
let userDataDir = lbo.userDataDir;
|
|
40484
40700
|
let createdTemp = false;
|
|
40485
40701
|
if (!userDataDir) {
|
|
40486
|
-
const base =
|
|
40487
|
-
|
|
40488
|
-
userDataDir =
|
|
40702
|
+
const base = import_path6.default.join(import_os2.default.tmpdir(), "stagehand-v3");
|
|
40703
|
+
import_fs7.default.mkdirSync(base, { recursive: true });
|
|
40704
|
+
userDataDir = import_fs7.default.mkdtempSync(import_path6.default.join(base, "profile-"));
|
|
40489
40705
|
createdTemp = true;
|
|
40490
40706
|
}
|
|
40491
40707
|
const defaults2 = [
|
|
@@ -40916,7 +41132,7 @@ var _V3 = class _V3 {
|
|
|
40916
41132
|
}
|
|
40917
41133
|
try {
|
|
40918
41134
|
if (this.state.createdTempProfile && !this.state.preserveUserDataDir && this.state.userDataDir) {
|
|
40919
|
-
|
|
41135
|
+
import_fs7.default.rmSync(this.state.userDataDir, { recursive: true, force: true });
|
|
40920
41136
|
}
|
|
40921
41137
|
} catch (e) {
|
|
40922
41138
|
}
|