@browserbasehq/stagehand 3.0.2-alpha-2d1b5732dc441a3331f5743cdfed3e1037d8b3b5 → 3.1.0-alpha-7e72adfd7e4af5ec49ac2f552e7f1f57c1acc554
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 +22 -1
- package/dist/index.js +459 -313
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -81,6 +81,278 @@ var __async = (__this, __arguments, generator) => {
|
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
// lib/version.ts
|
|
85
|
+
var STAGEHAND_VERSION;
|
|
86
|
+
var init_version = __esm({
|
|
87
|
+
"lib/version.ts"() {
|
|
88
|
+
STAGEHAND_VERSION = "3.1.0-alpha-7e72adfd7e4af5ec49ac2f552e7f1f57c1acc554";
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// lib/v3/types/public/sdkErrors.ts
|
|
93
|
+
var StagehandError, StagehandDefaultError, StagehandEnvironmentError, MissingEnvironmentVariableError, UnsupportedModelError, UnsupportedModelProviderError, UnsupportedAISDKModelProviderError, InvalidAISDKModelFormatError, StagehandNotInitializedError, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, MissingLLMConfigurationError, HandlerNotInitializedError, StagehandInvalidArgumentError, StagehandElementNotFoundError, AgentScreenshotProviderError, StagehandMissingArgumentError, CreateChatCompletionResponseError, StagehandEvalError, StagehandDomProcessError, StagehandClickError, LLMResponseError, StagehandIframeError, ContentFrameNotFoundError, XPathResolutionError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, CuaModelRequiredError, ZodSchemaValidationError, StagehandInitError, MCPConnectionError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, ElementNotVisibleError, ResponseBodyError, ResponseParseError, TimeoutError, PageNotFoundError, ConnectionTimeoutError;
|
|
94
|
+
var init_sdkErrors = __esm({
|
|
95
|
+
"lib/v3/types/public/sdkErrors.ts"() {
|
|
96
|
+
init_version();
|
|
97
|
+
StagehandError = class extends Error {
|
|
98
|
+
constructor(message) {
|
|
99
|
+
super(message);
|
|
100
|
+
this.name = this.constructor.name;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
StagehandDefaultError = class extends StagehandError {
|
|
104
|
+
constructor(error) {
|
|
105
|
+
if (error instanceof Error || error instanceof StagehandError) {
|
|
106
|
+
super(
|
|
107
|
+
`
|
|
108
|
+
Hey! We're sorry you ran into an error.
|
|
109
|
+
Stagehand version: ${STAGEHAND_VERSION}
|
|
110
|
+
If you need help, please open a Github issue or reach out to us on Slack: https://stagehand.dev/slack
|
|
111
|
+
|
|
112
|
+
Full error:
|
|
113
|
+
${error.message}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
StagehandEnvironmentError = class extends StagehandError {
|
|
119
|
+
constructor(currentEnvironment, requiredEnvironment, feature) {
|
|
120
|
+
super(
|
|
121
|
+
`You seem to be setting the current environment to ${currentEnvironment}.Ensure the environment is set to ${requiredEnvironment} if you want to use ${feature}.`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
MissingEnvironmentVariableError = class extends StagehandError {
|
|
126
|
+
constructor(missingEnvironmentVariable, feature) {
|
|
127
|
+
super(
|
|
128
|
+
`${missingEnvironmentVariable} is required to use ${feature}.Please set ${missingEnvironmentVariable} in your environment.`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
UnsupportedModelError = class extends StagehandError {
|
|
133
|
+
constructor(supportedModels, feature) {
|
|
134
|
+
super(
|
|
135
|
+
feature ? `${feature} requires one of the following models: ${supportedModels}` : `please use one of the supported models: ${supportedModels}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
UnsupportedModelProviderError = class extends StagehandError {
|
|
140
|
+
constructor(supportedProviders, feature) {
|
|
141
|
+
super(
|
|
142
|
+
feature ? `${feature} requires one of the following model providers: ${supportedProviders}` : `please use one of the supported model providers: ${supportedProviders}`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
UnsupportedAISDKModelProviderError = class extends StagehandError {
|
|
147
|
+
constructor(provider, supportedProviders) {
|
|
148
|
+
super(
|
|
149
|
+
`${provider} is not currently supported for aiSDK. please use one of the supported model providers: ${supportedProviders}`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
InvalidAISDKModelFormatError = class extends StagehandError {
|
|
154
|
+
constructor(modelName) {
|
|
155
|
+
super(
|
|
156
|
+
`${modelName} does not follow correct format for specifying aiSDK models. Please define your model as 'provider/model-name'. For example: \`model: 'openai/gpt-4o-mini'\``
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
StagehandNotInitializedError = class extends StagehandError {
|
|
161
|
+
constructor(prop) {
|
|
162
|
+
super(
|
|
163
|
+
`You seem to be calling \`${prop}\` on a page in an uninitialized \`Stagehand\` object. Ensure you are running \`await stagehand.init()\` on the Stagehand object before referencing the \`page\` object.`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
BrowserbaseSessionNotFoundError = class extends StagehandError {
|
|
168
|
+
constructor() {
|
|
169
|
+
super("No Browserbase session ID found");
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
CaptchaTimeoutError = class extends StagehandError {
|
|
173
|
+
constructor() {
|
|
174
|
+
super("Captcha timeout");
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
MissingLLMConfigurationError = class extends StagehandError {
|
|
178
|
+
constructor() {
|
|
179
|
+
super(
|
|
180
|
+
"No LLM API key or LLM Client configured. An LLM API key or a custom LLM Client is required to use act, extract, or observe."
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
HandlerNotInitializedError = class extends StagehandError {
|
|
185
|
+
constructor(handlerType) {
|
|
186
|
+
super(`${handlerType} handler not initialized`);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
StagehandInvalidArgumentError = class extends StagehandError {
|
|
190
|
+
constructor(message) {
|
|
191
|
+
super(`InvalidArgumentError: ${message}`);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
StagehandElementNotFoundError = class extends StagehandError {
|
|
195
|
+
constructor(xpaths) {
|
|
196
|
+
super(`Could not find an element for the given xPath(s): ${xpaths}`);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
AgentScreenshotProviderError = class extends StagehandError {
|
|
200
|
+
constructor(message) {
|
|
201
|
+
super(`ScreenshotProviderError: ${message}`);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
StagehandMissingArgumentError = class extends StagehandError {
|
|
205
|
+
constructor(message) {
|
|
206
|
+
super(`MissingArgumentError: ${message}`);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
CreateChatCompletionResponseError = class extends StagehandError {
|
|
210
|
+
constructor(message) {
|
|
211
|
+
super(`CreateChatCompletionResponseError: ${message}`);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
StagehandEvalError = class extends StagehandError {
|
|
215
|
+
constructor(message) {
|
|
216
|
+
super(`StagehandEvalError: ${message}`);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
StagehandDomProcessError = class extends StagehandError {
|
|
220
|
+
constructor(message) {
|
|
221
|
+
super(`Error Processing Dom: ${message}`);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
StagehandClickError = class extends StagehandError {
|
|
225
|
+
constructor(message, selector) {
|
|
226
|
+
super(
|
|
227
|
+
`Error Clicking Element with selector: ${selector} Reason: ${message}`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
LLMResponseError = class extends StagehandError {
|
|
232
|
+
constructor(primitive, message) {
|
|
233
|
+
super(`${primitive} LLM response error: ${message}`);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
StagehandIframeError = class extends StagehandError {
|
|
237
|
+
constructor(frameUrl, message) {
|
|
238
|
+
super(
|
|
239
|
+
`Unable to resolve frameId for iframe with URL: ${frameUrl} Full error: ${message}`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
ContentFrameNotFoundError = class extends StagehandError {
|
|
244
|
+
constructor(selector) {
|
|
245
|
+
super(`Unable to obtain a content frame for selector: ${selector}`);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
XPathResolutionError = class extends StagehandError {
|
|
249
|
+
constructor(xpath) {
|
|
250
|
+
super(`XPath "${xpath}" does not resolve in the current page or frames`);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
ExperimentalApiConflictError = class extends StagehandError {
|
|
254
|
+
constructor() {
|
|
255
|
+
super(
|
|
256
|
+
"`experimental` mode cannot be used together with the Stagehand API. To use experimental features, set experimental: true, and useApi: false in the stagehand constructor. To use the Stagehand API, set experimental: false and useApi: true in the stagehand constructor. "
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
ExperimentalNotConfiguredError = class extends StagehandError {
|
|
261
|
+
constructor(featureName) {
|
|
262
|
+
super(`Feature "${featureName}" is an experimental feature, and cannot be configured when useAPI: true.
|
|
263
|
+
Please set experimental: true and useAPI: false in the stagehand constructor to use this feature.
|
|
264
|
+
If you wish to use the Stagehand API, please ensure ${featureName} is not defined in your function call,
|
|
265
|
+
and set experimental: false, useAPI: true in the Stagehand constructor. `);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
CuaModelRequiredError = class extends StagehandError {
|
|
269
|
+
constructor(availableModels) {
|
|
270
|
+
super(
|
|
271
|
+
`To use the computer use agent (CUA), please provide a CUA model in the agent constructor or stagehand config. Try one of our supported CUA models: ${availableModels.join(", ")}`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
ZodSchemaValidationError = class extends Error {
|
|
276
|
+
constructor(received, issues) {
|
|
277
|
+
super(`Zod schema validation failed
|
|
278
|
+
|
|
279
|
+
\u2014 Received \u2014
|
|
280
|
+
${JSON.stringify(received, null, 2)}
|
|
281
|
+
|
|
282
|
+
\u2014 Issues \u2014
|
|
283
|
+
${JSON.stringify(issues, null, 2)}`);
|
|
284
|
+
this.received = received;
|
|
285
|
+
this.issues = issues;
|
|
286
|
+
this.name = "ZodSchemaValidationError";
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
StagehandInitError = class extends StagehandError {
|
|
290
|
+
constructor(message) {
|
|
291
|
+
super(message);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
MCPConnectionError = class extends StagehandError {
|
|
295
|
+
constructor(serverUrl, originalError) {
|
|
296
|
+
const errorMessage = originalError instanceof Error ? originalError.message : String(originalError);
|
|
297
|
+
super(
|
|
298
|
+
`Failed to connect to MCP server at "${serverUrl}". ${errorMessage}. Please verify the server URL is correct and the server is running.`
|
|
299
|
+
);
|
|
300
|
+
this.serverUrl = serverUrl;
|
|
301
|
+
this.originalError = originalError;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
StagehandShadowRootMissingError = class extends StagehandError {
|
|
305
|
+
constructor(detail) {
|
|
306
|
+
super(
|
|
307
|
+
`No shadow root present on the resolved host` + (detail ? `: ${detail}` : "")
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
StagehandShadowSegmentEmptyError = class extends StagehandError {
|
|
312
|
+
constructor() {
|
|
313
|
+
super(`Empty selector segment after shadow-DOM hop ("//")`);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
StagehandShadowSegmentNotFoundError = class extends StagehandError {
|
|
317
|
+
constructor(segment, hint) {
|
|
318
|
+
super(
|
|
319
|
+
`Shadow segment '${segment}' matched no element inside shadow root` + (hint ? ` ${hint}` : "")
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
ElementNotVisibleError = class extends StagehandError {
|
|
324
|
+
constructor(selector) {
|
|
325
|
+
super(`Element not visible (no box model): ${selector}`);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
ResponseBodyError = class extends StagehandError {
|
|
329
|
+
constructor(message) {
|
|
330
|
+
super(`Failed to retrieve response body: ${message}`);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
ResponseParseError = class extends StagehandError {
|
|
334
|
+
constructor(message) {
|
|
335
|
+
super(`Failed to parse response: ${message}`);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
TimeoutError = class extends StagehandError {
|
|
339
|
+
constructor(operation, timeoutMs) {
|
|
340
|
+
super(`${operation} timed out after ${timeoutMs}ms`);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
PageNotFoundError = class extends StagehandError {
|
|
344
|
+
constructor(identifier) {
|
|
345
|
+
super(`No Page found for ${identifier}`);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
ConnectionTimeoutError = class extends StagehandError {
|
|
349
|
+
constructor(message) {
|
|
350
|
+
super(`Connection timeout: ${message}`);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
|
|
84
356
|
// lib/v3/logger.ts
|
|
85
357
|
function bindInstanceLogger(instanceId, logger) {
|
|
86
358
|
instanceLoggers.set(instanceId, logger);
|
|
@@ -951,7 +1223,11 @@ function resolveFocusFrameAndTail(page, absoluteXPath, parentByFrame, rootId) {
|
|
|
951
1223
|
selectorForIframe,
|
|
952
1224
|
ctxFrameId
|
|
953
1225
|
);
|
|
954
|
-
if (!objectId)
|
|
1226
|
+
if (!objectId)
|
|
1227
|
+
throw new StagehandIframeError(
|
|
1228
|
+
selectorForIframe,
|
|
1229
|
+
"Failed to resolve iframe element by XPath"
|
|
1230
|
+
);
|
|
955
1231
|
try {
|
|
956
1232
|
yield parentSess.send("DOM.enable").catch(() => {
|
|
957
1233
|
});
|
|
@@ -972,7 +1248,10 @@ function resolveFocusFrameAndTail(page, absoluteXPath, parentByFrame, rootId) {
|
|
|
972
1248
|
}
|
|
973
1249
|
}
|
|
974
1250
|
if (!childFrameId)
|
|
975
|
-
throw new
|
|
1251
|
+
throw new StagehandIframeError(
|
|
1252
|
+
selectorForIframe,
|
|
1253
|
+
"Could not map iframe to child frameId"
|
|
1254
|
+
);
|
|
976
1255
|
absPrefix = prefixXPath(absPrefix || "/", selectorForIframe);
|
|
977
1256
|
ctxFrameId = childFrameId;
|
|
978
1257
|
} finally {
|
|
@@ -1004,7 +1283,11 @@ function resolveCssFocusFrameAndTail(page, rawSelector, parentByFrame, rootId) {
|
|
|
1004
1283
|
parts[i],
|
|
1005
1284
|
ctxFrameId
|
|
1006
1285
|
);
|
|
1007
|
-
if (!objectId)
|
|
1286
|
+
if (!objectId)
|
|
1287
|
+
throw new StagehandIframeError(
|
|
1288
|
+
parts[i],
|
|
1289
|
+
"Failed to resolve iframe via CSS hop"
|
|
1290
|
+
);
|
|
1008
1291
|
try {
|
|
1009
1292
|
yield parentSess.send("DOM.enable").catch(() => {
|
|
1010
1293
|
});
|
|
@@ -1025,7 +1308,10 @@ function resolveCssFocusFrameAndTail(page, rawSelector, parentByFrame, rootId) {
|
|
|
1025
1308
|
}
|
|
1026
1309
|
}
|
|
1027
1310
|
if (!childFrameId)
|
|
1028
|
-
throw new
|
|
1311
|
+
throw new StagehandIframeError(
|
|
1312
|
+
parts[i],
|
|
1313
|
+
"Could not map CSS iframe hop to child frameId"
|
|
1314
|
+
);
|
|
1029
1315
|
ctxFrameId = childFrameId;
|
|
1030
1316
|
} finally {
|
|
1031
1317
|
yield parentSess.send("Runtime.releaseObject", { objectId }).catch(() => {
|
|
@@ -1553,6 +1839,7 @@ var init_snapshot = __esm({
|
|
|
1553
1839
|
"lib/v3/understudy/a11y/snapshot.ts"() {
|
|
1554
1840
|
init_executionContextRegistry();
|
|
1555
1841
|
init_logger();
|
|
1842
|
+
init_sdkErrors();
|
|
1556
1843
|
IFRAME_STEP_RE = /^iframe(?:\[\d+])?$/i;
|
|
1557
1844
|
}
|
|
1558
1845
|
});
|
|
@@ -1981,6 +2268,7 @@ var init_locator = __esm({
|
|
|
1981
2268
|
import_buffer = require("buffer");
|
|
1982
2269
|
init_locatorScripts_generated();
|
|
1983
2270
|
init_selectorResolver();
|
|
2271
|
+
init_sdkErrors();
|
|
1984
2272
|
Locator = class _Locator {
|
|
1985
2273
|
constructor(frame, selector, options, nthIndex = 0) {
|
|
1986
2274
|
this.frame = frame;
|
|
@@ -2018,7 +2306,9 @@ var init_locator = __esm({
|
|
|
2018
2306
|
if (data instanceof Uint8Array) return import_buffer.Buffer.from(data);
|
|
2019
2307
|
if (typeof data === "string") return import_buffer.Buffer.from(data);
|
|
2020
2308
|
if (data instanceof ArrayBuffer) return import_buffer.Buffer.from(new Uint8Array(data));
|
|
2021
|
-
throw new
|
|
2309
|
+
throw new StagehandInvalidArgumentError(
|
|
2310
|
+
"Unsupported file payload buffer type"
|
|
2311
|
+
);
|
|
2022
2312
|
};
|
|
2023
2313
|
try {
|
|
2024
2314
|
try {
|
|
@@ -2032,9 +2322,11 @@ var init_locator = __esm({
|
|
|
2032
2322
|
);
|
|
2033
2323
|
const ok = Boolean(res.result.value);
|
|
2034
2324
|
if (!ok)
|
|
2035
|
-
throw new
|
|
2325
|
+
throw new StagehandInvalidArgumentError(
|
|
2326
|
+
'Target is not an <input type="file"> element'
|
|
2327
|
+
);
|
|
2036
2328
|
} catch (e) {
|
|
2037
|
-
throw new
|
|
2329
|
+
throw new StagehandInvalidArgumentError(
|
|
2038
2330
|
e instanceof Error ? e.message : "Unable to verify file input element"
|
|
2039
2331
|
);
|
|
2040
2332
|
}
|
|
@@ -2057,7 +2349,7 @@ var init_locator = __esm({
|
|
|
2057
2349
|
filePaths.push(tmp);
|
|
2058
2350
|
continue;
|
|
2059
2351
|
}
|
|
2060
|
-
throw new
|
|
2352
|
+
throw new StagehandInvalidArgumentError(
|
|
2061
2353
|
"Unsupported setInputFiles item \u2013 expected path or payload"
|
|
2062
2354
|
);
|
|
2063
2355
|
}
|
|
@@ -2123,7 +2415,7 @@ var init_locator = __esm({
|
|
|
2123
2415
|
"DOM.getBoxModel",
|
|
2124
2416
|
{ objectId }
|
|
2125
2417
|
);
|
|
2126
|
-
if (!box.model) throw new
|
|
2418
|
+
if (!box.model) throw new ElementNotVisibleError(this.selector);
|
|
2127
2419
|
const { cx, cy } = this.centerFromBoxContent(box.model.content);
|
|
2128
2420
|
return { x: Math.round(cx), y: Math.round(cy) };
|
|
2129
2421
|
} finally {
|
|
@@ -2210,7 +2502,7 @@ var init_locator = __esm({
|
|
|
2210
2502
|
"DOM.getBoxModel",
|
|
2211
2503
|
{ objectId }
|
|
2212
2504
|
);
|
|
2213
|
-
if (!box.model) throw new
|
|
2505
|
+
if (!box.model) throw new ElementNotVisibleError(this.selector);
|
|
2214
2506
|
const { cx, cy } = this.centerFromBoxContent(box.model.content);
|
|
2215
2507
|
yield session.send("Input.dispatchMouseEvent", {
|
|
2216
2508
|
type: "mouseMoved",
|
|
@@ -2245,7 +2537,7 @@ var init_locator = __esm({
|
|
|
2245
2537
|
"DOM.getBoxModel",
|
|
2246
2538
|
{ objectId }
|
|
2247
2539
|
);
|
|
2248
|
-
if (!box.model) throw new
|
|
2540
|
+
if (!box.model) throw new ElementNotVisibleError(this.selector);
|
|
2249
2541
|
const { cx, cy } = this.centerFromBoxContent(box.model.content);
|
|
2250
2542
|
yield session.send("Input.dispatchMouseEvent", {
|
|
2251
2543
|
type: "mouseMoved",
|
|
@@ -2412,7 +2704,9 @@ var init_locator = __esm({
|
|
|
2412
2704
|
}
|
|
2413
2705
|
if (status === "error") {
|
|
2414
2706
|
const reason = typeof (result == null ? void 0 : result.reason) === "string" && result.reason.length > 0 ? result.reason : "Failed to fill element";
|
|
2415
|
-
throw new
|
|
2707
|
+
throw new StagehandInvalidArgumentError(
|
|
2708
|
+
`Failed to fill element (${reason})`
|
|
2709
|
+
);
|
|
2416
2710
|
}
|
|
2417
2711
|
if (!status) {
|
|
2418
2712
|
yield this.type(value);
|
|
@@ -2639,7 +2933,9 @@ var init_locator = __esm({
|
|
|
2639
2933
|
nth(index) {
|
|
2640
2934
|
const value = Number(index);
|
|
2641
2935
|
if (!Number.isFinite(value) || value < 0) {
|
|
2642
|
-
throw new
|
|
2936
|
+
throw new StagehandInvalidArgumentError(
|
|
2937
|
+
"locator().nth() expects a non-negative index"
|
|
2938
|
+
);
|
|
2643
2939
|
}
|
|
2644
2940
|
const nextIndex = Math.floor(value);
|
|
2645
2941
|
if (nextIndex === this.nthIndex) {
|
|
@@ -2662,7 +2958,7 @@ var init_locator = __esm({
|
|
|
2662
2958
|
this.nthIndex
|
|
2663
2959
|
);
|
|
2664
2960
|
if (!resolved) {
|
|
2665
|
-
throw new
|
|
2961
|
+
throw new StagehandElementNotFoundError([this.selector]);
|
|
2666
2962
|
}
|
|
2667
2963
|
return resolved;
|
|
2668
2964
|
});
|
|
@@ -2670,7 +2966,7 @@ var init_locator = __esm({
|
|
|
2670
2966
|
/** Compute a center point from a BoxModel content quad */
|
|
2671
2967
|
centerFromBoxContent(content) {
|
|
2672
2968
|
if (!content || content.length < 8) {
|
|
2673
|
-
throw new
|
|
2969
|
+
throw new StagehandInvalidArgumentError("Invalid box model content quad");
|
|
2674
2970
|
}
|
|
2675
2971
|
const xs = [content[0], content[2], content[4], content[6]];
|
|
2676
2972
|
const ys = [content[1], content[3], content[5], content[7]];
|
|
@@ -2781,6 +3077,7 @@ var FrameLocator, LocatorDelegate;
|
|
|
2781
3077
|
var init_frameLocator = __esm({
|
|
2782
3078
|
"lib/v3/understudy/frameLocator.ts"() {
|
|
2783
3079
|
init_executionContextRegistry();
|
|
3080
|
+
init_sdkErrors();
|
|
2784
3081
|
FrameLocator = class _FrameLocator {
|
|
2785
3082
|
constructor(page, selector, parent, root) {
|
|
2786
3083
|
this.page = page;
|
|
@@ -2823,9 +3120,7 @@ var init_frameLocator = __esm({
|
|
|
2823
3120
|
} catch (e) {
|
|
2824
3121
|
}
|
|
2825
3122
|
}
|
|
2826
|
-
throw new
|
|
2827
|
-
`frameLocator: could not resolve child frame for selector: ${this.selector}`
|
|
2828
|
-
);
|
|
3123
|
+
throw new ContentFrameNotFoundError(this.selector);
|
|
2829
3124
|
} finally {
|
|
2830
3125
|
yield parentSession2.send("Runtime.releaseObject", { objectId }).catch(() => {
|
|
2831
3126
|
});
|
|
@@ -3019,6 +3314,7 @@ var init_deepLocator = __esm({
|
|
|
3019
3314
|
init_locator();
|
|
3020
3315
|
init_logger();
|
|
3021
3316
|
init_frameLocator();
|
|
3317
|
+
init_sdkErrors();
|
|
3022
3318
|
IFRAME_STEP_RE2 = /^iframe(?:\[\d+])?$/i;
|
|
3023
3319
|
DeepLocatorDelegate = class _DeepLocatorDelegate {
|
|
3024
3320
|
constructor(page, root, selector, nthIndex = 0) {
|
|
@@ -3134,7 +3430,9 @@ var init_deepLocator = __esm({
|
|
|
3134
3430
|
nth(index) {
|
|
3135
3431
|
const value = Number(index);
|
|
3136
3432
|
if (!Number.isFinite(value) || value < 0) {
|
|
3137
|
-
throw new
|
|
3433
|
+
throw new StagehandInvalidArgumentError(
|
|
3434
|
+
"deepLocator().nth() expects a non-negative index"
|
|
3435
|
+
);
|
|
3138
3436
|
}
|
|
3139
3437
|
const nextIndex = Math.floor(value);
|
|
3140
3438
|
if (nextIndex === this.nthIndex) return this;
|
|
@@ -4090,6 +4388,7 @@ function parseHeadersText(headersText) {
|
|
|
4090
4388
|
var Response;
|
|
4091
4389
|
var init_response = __esm({
|
|
4092
4390
|
"lib/v3/understudy/response.ts"() {
|
|
4391
|
+
init_sdkErrors();
|
|
4093
4392
|
Response = class _Response {
|
|
4094
4393
|
/**
|
|
4095
4394
|
* Build a response wrapper from the CDP notification associated with a
|
|
@@ -4260,7 +4559,7 @@ var init_response = __esm({
|
|
|
4260
4559
|
"Network.getResponseBody",
|
|
4261
4560
|
{ requestId: this.requestId }
|
|
4262
4561
|
).catch((error) => {
|
|
4263
|
-
throw new
|
|
4562
|
+
throw new ResponseBodyError(String(error));
|
|
4264
4563
|
});
|
|
4265
4564
|
if (result.base64Encoded) {
|
|
4266
4565
|
return Buffer.from(result.body, "base64");
|
|
@@ -4282,7 +4581,7 @@ var init_response = __esm({
|
|
|
4282
4581
|
try {
|
|
4283
4582
|
return JSON.parse(text);
|
|
4284
4583
|
} catch (error) {
|
|
4285
|
-
throw new
|
|
4584
|
+
throw new ResponseParseError(String(error));
|
|
4286
4585
|
}
|
|
4287
4586
|
});
|
|
4288
4587
|
}
|
|
@@ -4363,6 +4662,7 @@ var Frame;
|
|
|
4363
4662
|
var init_frame = __esm({
|
|
4364
4663
|
"lib/v3/understudy/frame.ts"() {
|
|
4365
4664
|
init_locator();
|
|
4665
|
+
init_sdkErrors();
|
|
4366
4666
|
Frame = class _Frame {
|
|
4367
4667
|
constructor(session, frameId, pageId) {
|
|
4368
4668
|
this.session = session;
|
|
@@ -4469,7 +4769,9 @@ var init_frame = __esm({
|
|
|
4469
4769
|
}
|
|
4470
4770
|
);
|
|
4471
4771
|
if (res.exceptionDetails) {
|
|
4472
|
-
throw new
|
|
4772
|
+
throw new StagehandEvalError(
|
|
4773
|
+
(_a = res.exceptionDetails.text) != null ? _a : "Evaluation failed"
|
|
4774
|
+
);
|
|
4473
4775
|
}
|
|
4474
4776
|
return res.result.value;
|
|
4475
4777
|
});
|
|
@@ -5122,6 +5424,7 @@ var init_networkManager = __esm({
|
|
|
5122
5424
|
var LifecycleWatcher;
|
|
5123
5425
|
var init_lifecycleWatcher = __esm({
|
|
5124
5426
|
"lib/v3/understudy/lifecycleWatcher.ts"() {
|
|
5427
|
+
init_sdkErrors();
|
|
5125
5428
|
init_network();
|
|
5126
5429
|
LifecycleWatcher = class {
|
|
5127
5430
|
/**
|
|
@@ -5259,7 +5562,7 @@ var init_lifecycleWatcher = __esm({
|
|
|
5259
5562
|
timeRemaining(deadline) {
|
|
5260
5563
|
const remaining = deadline - Date.now();
|
|
5261
5564
|
if (remaining <= 0) {
|
|
5262
|
-
throw new
|
|
5565
|
+
throw new TimeoutError("Lifecycle wait", this.timeoutMs);
|
|
5263
5566
|
}
|
|
5264
5567
|
return remaining;
|
|
5265
5568
|
}
|
|
@@ -5556,11 +5859,15 @@ function normalizeScreenshotClip(clip) {
|
|
|
5556
5859
|
const height = Number(clip.height);
|
|
5557
5860
|
for (const [key, value] of Object.entries({ x, y, width, height })) {
|
|
5558
5861
|
if (!Number.isFinite(value)) {
|
|
5559
|
-
throw new
|
|
5862
|
+
throw new StagehandInvalidArgumentError(
|
|
5863
|
+
`screenshot: clip.${key} must be a finite number`
|
|
5864
|
+
);
|
|
5560
5865
|
}
|
|
5561
5866
|
}
|
|
5562
5867
|
if (width <= 0 || height <= 0) {
|
|
5563
|
-
throw new
|
|
5868
|
+
throw new StagehandInvalidArgumentError(
|
|
5869
|
+
"screenshot: clip width/height must be positive"
|
|
5870
|
+
);
|
|
5564
5871
|
}
|
|
5565
5872
|
return { x, y, width, height };
|
|
5566
5873
|
}
|
|
@@ -5849,6 +6156,7 @@ function withScreenshotTimeout(timeoutMs, task) {
|
|
|
5849
6156
|
}
|
|
5850
6157
|
var init_screenshotUtils = __esm({
|
|
5851
6158
|
"lib/v3/understudy/screenshotUtils.ts"() {
|
|
6159
|
+
init_sdkErrors();
|
|
5852
6160
|
}
|
|
5853
6161
|
});
|
|
5854
6162
|
|
|
@@ -5872,6 +6180,7 @@ var init_page = __esm({
|
|
|
5872
6180
|
init_navigationResponseTracker();
|
|
5873
6181
|
init_response();
|
|
5874
6182
|
init_consoleMessage();
|
|
6183
|
+
init_sdkErrors();
|
|
5875
6184
|
init_screenshotUtils();
|
|
5876
6185
|
LIFECYCLE_NAME = {
|
|
5877
6186
|
load: "load",
|
|
@@ -6188,7 +6497,7 @@ var init_page = __esm({
|
|
|
6188
6497
|
}
|
|
6189
6498
|
on(event, listener) {
|
|
6190
6499
|
if (event !== "console") {
|
|
6191
|
-
throw new
|
|
6500
|
+
throw new StagehandInvalidArgumentError(`Unsupported event: ${event}`);
|
|
6192
6501
|
}
|
|
6193
6502
|
const firstListener = this.consoleListeners.size === 0;
|
|
6194
6503
|
this.consoleListeners.add(listener);
|
|
@@ -6199,7 +6508,7 @@ var init_page = __esm({
|
|
|
6199
6508
|
}
|
|
6200
6509
|
once(event, listener) {
|
|
6201
6510
|
if (event !== "console") {
|
|
6202
|
-
throw new
|
|
6511
|
+
throw new StagehandInvalidArgumentError(`Unsupported event: ${event}`);
|
|
6203
6512
|
}
|
|
6204
6513
|
const wrapper = (message) => {
|
|
6205
6514
|
this.off("console", wrapper);
|
|
@@ -6209,7 +6518,7 @@ var init_page = __esm({
|
|
|
6209
6518
|
}
|
|
6210
6519
|
off(event, listener) {
|
|
6211
6520
|
if (event !== "console") {
|
|
6212
|
-
throw new
|
|
6521
|
+
throw new StagehandInvalidArgumentError(`Unsupported event: ${event}`);
|
|
6213
6522
|
}
|
|
6214
6523
|
this.consoleListeners.delete(listener);
|
|
6215
6524
|
if (this.consoleListeners.size === 0) {
|
|
@@ -6635,13 +6944,17 @@ var init_page = __esm({
|
|
|
6635
6944
|
const opts = options != null ? options : {};
|
|
6636
6945
|
const type = (_a = opts.type) != null ? _a : "png";
|
|
6637
6946
|
if (type !== "png" && type !== "jpeg") {
|
|
6638
|
-
throw new
|
|
6947
|
+
throw new StagehandInvalidArgumentError(
|
|
6948
|
+
`screenshot: unsupported image type "${type}"`
|
|
6949
|
+
);
|
|
6639
6950
|
}
|
|
6640
6951
|
if (opts.fullPage && opts.clip) {
|
|
6641
|
-
throw new
|
|
6952
|
+
throw new StagehandInvalidArgumentError(
|
|
6953
|
+
"screenshot: clip and fullPage cannot be used together"
|
|
6954
|
+
);
|
|
6642
6955
|
}
|
|
6643
6956
|
if (type === "png" && typeof opts.quality === "number") {
|
|
6644
|
-
throw new
|
|
6957
|
+
throw new StagehandInvalidArgumentError(
|
|
6645
6958
|
'screenshot: quality option is only valid for type="jpeg"'
|
|
6646
6959
|
);
|
|
6647
6960
|
}
|
|
@@ -6778,7 +7091,7 @@ var init_page = __esm({
|
|
|
6778
7091
|
);
|
|
6779
7092
|
if (exceptionDetails) {
|
|
6780
7093
|
const msg = exceptionDetails.text || ((_a = exceptionDetails.exception) == null ? void 0 : _a.description) || "Evaluation failed";
|
|
6781
|
-
throw new
|
|
7094
|
+
throw new StagehandEvalError(msg);
|
|
6782
7095
|
}
|
|
6783
7096
|
return result == null ? void 0 : result.value;
|
|
6784
7097
|
});
|
|
@@ -7417,9 +7730,12 @@ __export(v3_exports, {
|
|
|
7417
7730
|
AnnotatedScreenshotText: () => AnnotatedScreenshotText,
|
|
7418
7731
|
BrowserbaseSessionNotFoundError: () => BrowserbaseSessionNotFoundError,
|
|
7419
7732
|
CaptchaTimeoutError: () => CaptchaTimeoutError,
|
|
7733
|
+
ConnectionTimeoutError: () => ConnectionTimeoutError,
|
|
7420
7734
|
ConsoleMessage: () => ConsoleMessage,
|
|
7421
7735
|
ContentFrameNotFoundError: () => ContentFrameNotFoundError,
|
|
7422
7736
|
CreateChatCompletionResponseError: () => CreateChatCompletionResponseError,
|
|
7737
|
+
CuaModelRequiredError: () => CuaModelRequiredError,
|
|
7738
|
+
ElementNotVisibleError: () => ElementNotVisibleError,
|
|
7423
7739
|
ExperimentalApiConflictError: () => ExperimentalApiConflictError,
|
|
7424
7740
|
ExperimentalNotConfiguredError: () => ExperimentalNotConfiguredError,
|
|
7425
7741
|
HandlerNotInitializedError: () => HandlerNotInitializedError,
|
|
@@ -7430,7 +7746,10 @@ __export(v3_exports, {
|
|
|
7430
7746
|
MCPConnectionError: () => MCPConnectionError,
|
|
7431
7747
|
MissingEnvironmentVariableError: () => MissingEnvironmentVariableError,
|
|
7432
7748
|
MissingLLMConfigurationError: () => MissingLLMConfigurationError,
|
|
7749
|
+
PageNotFoundError: () => PageNotFoundError,
|
|
7433
7750
|
Response: () => Response,
|
|
7751
|
+
ResponseBodyError: () => ResponseBodyError,
|
|
7752
|
+
ResponseParseError: () => ResponseParseError,
|
|
7434
7753
|
Stagehand: () => V3,
|
|
7435
7754
|
StagehandAPIError: () => StagehandAPIError,
|
|
7436
7755
|
StagehandAPIUnauthorizedError: () => StagehandAPIUnauthorizedError,
|
|
@@ -7453,6 +7772,7 @@ __export(v3_exports, {
|
|
|
7453
7772
|
StagehandShadowRootMissingError: () => StagehandShadowRootMissingError,
|
|
7454
7773
|
StagehandShadowSegmentEmptyError: () => StagehandShadowSegmentEmptyError,
|
|
7455
7774
|
StagehandShadowSegmentNotFoundError: () => StagehandShadowSegmentNotFoundError,
|
|
7775
|
+
TimeoutError: () => TimeoutError,
|
|
7456
7776
|
UnsupportedAISDKModelProviderError: () => UnsupportedAISDKModelProviderError,
|
|
7457
7777
|
UnsupportedModelError: () => UnsupportedModelError,
|
|
7458
7778
|
UnsupportedModelProviderError: () => UnsupportedModelProviderError,
|
|
@@ -7485,231 +7805,8 @@ var import_os2 = __toESM(require("os"));
|
|
|
7485
7805
|
var import_path5 = __toESM(require("path"));
|
|
7486
7806
|
var import_process2 = __toESM(require("process"));
|
|
7487
7807
|
|
|
7488
|
-
// lib/version.ts
|
|
7489
|
-
var STAGEHAND_VERSION = "3.0.2-alpha-2d1b5732dc441a3331f5743cdfed3e1037d8b3b5";
|
|
7490
|
-
|
|
7491
|
-
// lib/v3/types/public/sdkErrors.ts
|
|
7492
|
-
var StagehandError = class extends Error {
|
|
7493
|
-
constructor(message) {
|
|
7494
|
-
super(message);
|
|
7495
|
-
this.name = this.constructor.name;
|
|
7496
|
-
}
|
|
7497
|
-
};
|
|
7498
|
-
var StagehandDefaultError = class extends StagehandError {
|
|
7499
|
-
constructor(error) {
|
|
7500
|
-
if (error instanceof Error || error instanceof StagehandError) {
|
|
7501
|
-
super(
|
|
7502
|
-
`
|
|
7503
|
-
Hey! We're sorry you ran into an error.
|
|
7504
|
-
Stagehand version: ${STAGEHAND_VERSION}
|
|
7505
|
-
If you need help, please open a Github issue or reach out to us on Slack: https://stagehand.dev/slack
|
|
7506
|
-
|
|
7507
|
-
Full error:
|
|
7508
|
-
${error.message}`
|
|
7509
|
-
);
|
|
7510
|
-
}
|
|
7511
|
-
}
|
|
7512
|
-
};
|
|
7513
|
-
var StagehandEnvironmentError = class extends StagehandError {
|
|
7514
|
-
constructor(currentEnvironment, requiredEnvironment, feature) {
|
|
7515
|
-
super(
|
|
7516
|
-
`You seem to be setting the current environment to ${currentEnvironment}.Ensure the environment is set to ${requiredEnvironment} if you want to use ${feature}.`
|
|
7517
|
-
);
|
|
7518
|
-
}
|
|
7519
|
-
};
|
|
7520
|
-
var MissingEnvironmentVariableError = class extends StagehandError {
|
|
7521
|
-
constructor(missingEnvironmentVariable, feature) {
|
|
7522
|
-
super(
|
|
7523
|
-
`${missingEnvironmentVariable} is required to use ${feature}.Please set ${missingEnvironmentVariable} in your environment.`
|
|
7524
|
-
);
|
|
7525
|
-
}
|
|
7526
|
-
};
|
|
7527
|
-
var UnsupportedModelError = class extends StagehandError {
|
|
7528
|
-
constructor(supportedModels, feature) {
|
|
7529
|
-
super(
|
|
7530
|
-
feature ? `${feature} requires one of the following models: ${supportedModels}` : `please use one of the supported models: ${supportedModels}`
|
|
7531
|
-
);
|
|
7532
|
-
}
|
|
7533
|
-
};
|
|
7534
|
-
var UnsupportedModelProviderError = class extends StagehandError {
|
|
7535
|
-
constructor(supportedProviders, feature) {
|
|
7536
|
-
super(
|
|
7537
|
-
feature ? `${feature} requires one of the following model providers: ${supportedProviders}` : `please use one of the supported model providers: ${supportedProviders}`
|
|
7538
|
-
);
|
|
7539
|
-
}
|
|
7540
|
-
};
|
|
7541
|
-
var UnsupportedAISDKModelProviderError = class extends StagehandError {
|
|
7542
|
-
constructor(provider, supportedProviders) {
|
|
7543
|
-
super(
|
|
7544
|
-
`${provider} is not currently supported for aiSDK. please use one of the supported model providers: ${supportedProviders}`
|
|
7545
|
-
);
|
|
7546
|
-
}
|
|
7547
|
-
};
|
|
7548
|
-
var InvalidAISDKModelFormatError = class extends StagehandError {
|
|
7549
|
-
constructor(modelName) {
|
|
7550
|
-
super(
|
|
7551
|
-
`${modelName} does not follow correct format for specifying aiSDK models. Please define your model as 'provider/model-name'. For example: \`model: 'openai/gpt-4o-mini'\``
|
|
7552
|
-
);
|
|
7553
|
-
}
|
|
7554
|
-
};
|
|
7555
|
-
var StagehandNotInitializedError = class extends StagehandError {
|
|
7556
|
-
constructor(prop) {
|
|
7557
|
-
super(
|
|
7558
|
-
`You seem to be calling \`${prop}\` on a page in an uninitialized \`Stagehand\` object. Ensure you are running \`await stagehand.init()\` on the Stagehand object before referencing the \`page\` object.`
|
|
7559
|
-
);
|
|
7560
|
-
}
|
|
7561
|
-
};
|
|
7562
|
-
var BrowserbaseSessionNotFoundError = class extends StagehandError {
|
|
7563
|
-
constructor() {
|
|
7564
|
-
super("No Browserbase session ID found");
|
|
7565
|
-
}
|
|
7566
|
-
};
|
|
7567
|
-
var CaptchaTimeoutError = class extends StagehandError {
|
|
7568
|
-
constructor() {
|
|
7569
|
-
super("Captcha timeout");
|
|
7570
|
-
}
|
|
7571
|
-
};
|
|
7572
|
-
var MissingLLMConfigurationError = class extends StagehandError {
|
|
7573
|
-
constructor() {
|
|
7574
|
-
super(
|
|
7575
|
-
"No LLM API key or LLM Client configured. An LLM API key or a custom LLM Client is required to use act, extract, or observe."
|
|
7576
|
-
);
|
|
7577
|
-
}
|
|
7578
|
-
};
|
|
7579
|
-
var HandlerNotInitializedError = class extends StagehandError {
|
|
7580
|
-
constructor(handlerType) {
|
|
7581
|
-
super(`${handlerType} handler not initialized`);
|
|
7582
|
-
}
|
|
7583
|
-
};
|
|
7584
|
-
var StagehandInvalidArgumentError = class extends StagehandError {
|
|
7585
|
-
constructor(message) {
|
|
7586
|
-
super(`InvalidArgumentError: ${message}`);
|
|
7587
|
-
}
|
|
7588
|
-
};
|
|
7589
|
-
var StagehandElementNotFoundError = class extends StagehandError {
|
|
7590
|
-
constructor(xpaths) {
|
|
7591
|
-
super(`Could not find an element for the given xPath(s): ${xpaths}`);
|
|
7592
|
-
}
|
|
7593
|
-
};
|
|
7594
|
-
var AgentScreenshotProviderError = class extends StagehandError {
|
|
7595
|
-
constructor(message) {
|
|
7596
|
-
super(`ScreenshotProviderError: ${message}`);
|
|
7597
|
-
}
|
|
7598
|
-
};
|
|
7599
|
-
var StagehandMissingArgumentError = class extends StagehandError {
|
|
7600
|
-
constructor(message) {
|
|
7601
|
-
super(`MissingArgumentError: ${message}`);
|
|
7602
|
-
}
|
|
7603
|
-
};
|
|
7604
|
-
var CreateChatCompletionResponseError = class extends StagehandError {
|
|
7605
|
-
constructor(message) {
|
|
7606
|
-
super(`CreateChatCompletionResponseError: ${message}`);
|
|
7607
|
-
}
|
|
7608
|
-
};
|
|
7609
|
-
var StagehandEvalError = class extends StagehandError {
|
|
7610
|
-
constructor(message) {
|
|
7611
|
-
super(`StagehandEvalError: ${message}`);
|
|
7612
|
-
}
|
|
7613
|
-
};
|
|
7614
|
-
var StagehandDomProcessError = class extends StagehandError {
|
|
7615
|
-
constructor(message) {
|
|
7616
|
-
super(`Error Processing Dom: ${message}`);
|
|
7617
|
-
}
|
|
7618
|
-
};
|
|
7619
|
-
var StagehandClickError = class extends StagehandError {
|
|
7620
|
-
constructor(message, selector) {
|
|
7621
|
-
super(
|
|
7622
|
-
`Error Clicking Element with selector: ${selector} Reason: ${message}`
|
|
7623
|
-
);
|
|
7624
|
-
}
|
|
7625
|
-
};
|
|
7626
|
-
var LLMResponseError = class extends StagehandError {
|
|
7627
|
-
constructor(primitive, message) {
|
|
7628
|
-
super(`${primitive} LLM response error: ${message}`);
|
|
7629
|
-
}
|
|
7630
|
-
};
|
|
7631
|
-
var StagehandIframeError = class extends StagehandError {
|
|
7632
|
-
constructor(frameUrl, message) {
|
|
7633
|
-
super(
|
|
7634
|
-
`Unable to resolve frameId for iframe with URL: ${frameUrl} Full error: ${message}`
|
|
7635
|
-
);
|
|
7636
|
-
}
|
|
7637
|
-
};
|
|
7638
|
-
var ContentFrameNotFoundError = class extends StagehandError {
|
|
7639
|
-
constructor(selector) {
|
|
7640
|
-
super(`Unable to obtain a content frame for selector: ${selector}`);
|
|
7641
|
-
}
|
|
7642
|
-
};
|
|
7643
|
-
var XPathResolutionError = class extends StagehandError {
|
|
7644
|
-
constructor(xpath) {
|
|
7645
|
-
super(`XPath "${xpath}" does not resolve in the current page or frames`);
|
|
7646
|
-
}
|
|
7647
|
-
};
|
|
7648
|
-
var ExperimentalApiConflictError = class extends StagehandError {
|
|
7649
|
-
constructor() {
|
|
7650
|
-
super(
|
|
7651
|
-
"`experimental` mode cannot be used together with the Stagehand API. To use experimental features, set experimental: true, and useApi: false in the stagehand constructor. To use the Stagehand API, set experimental: false and useApi: true in the stagehand constructor. "
|
|
7652
|
-
);
|
|
7653
|
-
}
|
|
7654
|
-
};
|
|
7655
|
-
var ExperimentalNotConfiguredError = class extends StagehandError {
|
|
7656
|
-
constructor(featureName) {
|
|
7657
|
-
super(`Feature "${featureName}" is an experimental feature, and cannot be configured when useAPI: true.
|
|
7658
|
-
Please set experimental: true and useAPI: false in the stagehand constructor to use this feature.
|
|
7659
|
-
If you wish to use the Stagehand API, please ensure ${featureName} is not defined in your function call,
|
|
7660
|
-
and set experimental: false, useAPI: true in the Stagehand constructor. `);
|
|
7661
|
-
}
|
|
7662
|
-
};
|
|
7663
|
-
var ZodSchemaValidationError = class extends Error {
|
|
7664
|
-
constructor(received, issues) {
|
|
7665
|
-
super(`Zod schema validation failed
|
|
7666
|
-
|
|
7667
|
-
\u2014 Received \u2014
|
|
7668
|
-
${JSON.stringify(received, null, 2)}
|
|
7669
|
-
|
|
7670
|
-
\u2014 Issues \u2014
|
|
7671
|
-
${JSON.stringify(issues, null, 2)}`);
|
|
7672
|
-
this.received = received;
|
|
7673
|
-
this.issues = issues;
|
|
7674
|
-
this.name = "ZodSchemaValidationError";
|
|
7675
|
-
}
|
|
7676
|
-
};
|
|
7677
|
-
var StagehandInitError = class extends StagehandError {
|
|
7678
|
-
constructor(message) {
|
|
7679
|
-
super(message);
|
|
7680
|
-
}
|
|
7681
|
-
};
|
|
7682
|
-
var MCPConnectionError = class extends StagehandError {
|
|
7683
|
-
constructor(serverUrl, originalError) {
|
|
7684
|
-
const errorMessage = originalError instanceof Error ? originalError.message : String(originalError);
|
|
7685
|
-
super(
|
|
7686
|
-
`Failed to connect to MCP server at "${serverUrl}". ${errorMessage}. Please verify the server URL is correct and the server is running.`
|
|
7687
|
-
);
|
|
7688
|
-
this.serverUrl = serverUrl;
|
|
7689
|
-
this.originalError = originalError;
|
|
7690
|
-
}
|
|
7691
|
-
};
|
|
7692
|
-
var StagehandShadowRootMissingError = class extends StagehandError {
|
|
7693
|
-
constructor(detail) {
|
|
7694
|
-
super(
|
|
7695
|
-
`No shadow root present on the resolved host` + (detail ? `: ${detail}` : "")
|
|
7696
|
-
);
|
|
7697
|
-
}
|
|
7698
|
-
};
|
|
7699
|
-
var StagehandShadowSegmentEmptyError = class extends StagehandError {
|
|
7700
|
-
constructor() {
|
|
7701
|
-
super(`Empty selector segment after shadow-DOM hop ("//")`);
|
|
7702
|
-
}
|
|
7703
|
-
};
|
|
7704
|
-
var StagehandShadowSegmentNotFoundError = class extends StagehandError {
|
|
7705
|
-
constructor(segment, hint) {
|
|
7706
|
-
super(
|
|
7707
|
-
`Shadow segment '${segment}' matched no element inside shadow root` + (hint ? ` ${hint}` : "")
|
|
7708
|
-
);
|
|
7709
|
-
}
|
|
7710
|
-
};
|
|
7711
|
-
|
|
7712
7808
|
// lib/utils.ts
|
|
7809
|
+
init_sdkErrors();
|
|
7713
7810
|
var import_genai = require("@google/genai");
|
|
7714
7811
|
var import_v3 = require("zod/v3");
|
|
7715
7812
|
var ID_PATTERN = /^\d+-\d+$/;
|
|
@@ -8369,6 +8466,7 @@ function safeGetPageUrl(page) {
|
|
|
8369
8466
|
}
|
|
8370
8467
|
|
|
8371
8468
|
// lib/v3/cache/ActCache.ts
|
|
8469
|
+
init_sdkErrors();
|
|
8372
8470
|
var ActCache = class {
|
|
8373
8471
|
constructor({
|
|
8374
8472
|
storage,
|
|
@@ -8496,7 +8594,7 @@ var ActCache = class {
|
|
|
8496
8594
|
return __async(this, null, function* () {
|
|
8497
8595
|
const handler = this.getActHandler();
|
|
8498
8596
|
if (!handler) {
|
|
8499
|
-
throw new
|
|
8597
|
+
throw new StagehandNotInitializedError("act()");
|
|
8500
8598
|
}
|
|
8501
8599
|
const execute = () => __async(this, null, function* () {
|
|
8502
8600
|
var _a, _b, _c;
|
|
@@ -9750,6 +9848,7 @@ var SupportedPlaywrightAction = /* @__PURE__ */ ((SupportedPlaywrightAction2) =>
|
|
|
9750
9848
|
// lib/v3/handlers/handlerUtils/actHandlerUtils.ts
|
|
9751
9849
|
init_deepLocator();
|
|
9752
9850
|
init_logger();
|
|
9851
|
+
init_sdkErrors();
|
|
9753
9852
|
var UnderstudyCommandException = class extends Error {
|
|
9754
9853
|
constructor(message) {
|
|
9755
9854
|
super(message);
|
|
@@ -10726,6 +10825,7 @@ var ActHandler = class {
|
|
|
10726
10825
|
init_logger();
|
|
10727
10826
|
init_snapshot();
|
|
10728
10827
|
var import_v34 = require("zod/v3");
|
|
10828
|
+
init_sdkErrors();
|
|
10729
10829
|
function transformUrlStringsToNumericIds(schema) {
|
|
10730
10830
|
const [finalSchema, urlPaths] = transformSchema(schema, []);
|
|
10731
10831
|
return [finalSchema, urlPaths];
|
|
@@ -10758,7 +10858,7 @@ var ExtractHandler = class {
|
|
|
10758
10858
|
return pageTextSchema.parse(result);
|
|
10759
10859
|
}
|
|
10760
10860
|
if (!instruction && schema) {
|
|
10761
|
-
throw new
|
|
10861
|
+
throw new StagehandInvalidArgumentError(
|
|
10762
10862
|
"extract() requires an instruction when a schema is provided."
|
|
10763
10863
|
);
|
|
10764
10864
|
}
|
|
@@ -11517,6 +11617,7 @@ function createStandardAction(toolCallName, toolResult, args, reasoning) {
|
|
|
11517
11617
|
}
|
|
11518
11618
|
|
|
11519
11619
|
// lib/v3/handlers/v3AgentHandler.ts
|
|
11620
|
+
init_sdkErrors();
|
|
11520
11621
|
var V3AgentHandler = class {
|
|
11521
11622
|
constructor(v3, logger, llmClient, executionModel, systemInstructions, mcpTools) {
|
|
11522
11623
|
this.v3 = v3;
|
|
@@ -11548,9 +11649,7 @@ var V3AgentHandler = class {
|
|
|
11548
11649
|
{ role: "user", content: options.instruction }
|
|
11549
11650
|
];
|
|
11550
11651
|
if (!((_a = this.llmClient) == null ? void 0 : _a.getLanguageModel)) {
|
|
11551
|
-
throw new
|
|
11552
|
-
"V3AgentHandler requires an AISDK-backed LLM client. Ensure your model is configured like 'openai/gpt-4.1-mini'."
|
|
11553
|
-
);
|
|
11652
|
+
throw new MissingLLMConfigurationError();
|
|
11554
11653
|
}
|
|
11555
11654
|
const baseModel = this.llmClient.getLanguageModel();
|
|
11556
11655
|
const wrappedModel = (0, import_ai11.wrapLanguageModel)({
|
|
@@ -11697,7 +11796,11 @@ STRATEGY:
|
|
|
11697
11796
|
// lib/v3/handlers/v3CuaAgentHandler.ts
|
|
11698
11797
|
init_snapshot();
|
|
11699
11798
|
|
|
11799
|
+
// lib/v3/agent/AgentProvider.ts
|
|
11800
|
+
init_sdkErrors();
|
|
11801
|
+
|
|
11700
11802
|
// lib/v3/agent/AnthropicCUAClient.ts
|
|
11803
|
+
init_sdkErrors();
|
|
11701
11804
|
var import_sdk = __toESM(require("@anthropic-ai/sdk"));
|
|
11702
11805
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
11703
11806
|
|
|
@@ -12590,6 +12693,7 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
12590
12693
|
|
|
12591
12694
|
// lib/v3/agent/OpenAICUAClient.ts
|
|
12592
12695
|
var import_openai = __toESM(require("openai"));
|
|
12696
|
+
init_sdkErrors();
|
|
12593
12697
|
var OpenAICUAClient = class extends AgentClient {
|
|
12594
12698
|
constructor(type, modelName, userProvidedInstructions, clientOptions, tools) {
|
|
12595
12699
|
super(type, modelName, userProvidedInstructions);
|
|
@@ -13063,6 +13167,7 @@ var OpenAICUAClient = class extends AgentClient {
|
|
|
13063
13167
|
|
|
13064
13168
|
// lib/v3/agent/GoogleCUAClient.ts
|
|
13065
13169
|
var import_genai3 = require("@google/genai");
|
|
13170
|
+
init_sdkErrors();
|
|
13066
13171
|
|
|
13067
13172
|
// lib/v3/agent/utils/googleCustomToolHandler.ts
|
|
13068
13173
|
var import_genai2 = require("@google/genai");
|
|
@@ -13379,7 +13484,7 @@ var GoogleCUAClient = class extends AgentClient {
|
|
|
13379
13484
|
config: this.generateContentConfig
|
|
13380
13485
|
});
|
|
13381
13486
|
if (!response.candidates || response.candidates.length === 0) {
|
|
13382
|
-
throw new
|
|
13487
|
+
throw new LLMResponseError("agent", "Response has no candidates!");
|
|
13383
13488
|
}
|
|
13384
13489
|
break;
|
|
13385
13490
|
} catch (error) {
|
|
@@ -14379,6 +14484,7 @@ var V3CuaAgentHandler = class {
|
|
|
14379
14484
|
|
|
14380
14485
|
// lib/v3/launch/browserbase.ts
|
|
14381
14486
|
var import_sdk2 = __toESM(require("@browserbasehq/sdk"));
|
|
14487
|
+
init_sdkErrors();
|
|
14382
14488
|
function createBrowserbaseSession(apiKey, projectId, params, resumeSessionId) {
|
|
14383
14489
|
return __async(this, null, function* () {
|
|
14384
14490
|
var _b;
|
|
@@ -14388,11 +14494,11 @@ function createBrowserbaseSession(apiKey, projectId, params, resumeSessionId) {
|
|
|
14388
14494
|
resumeSessionId
|
|
14389
14495
|
);
|
|
14390
14496
|
if (!(existing == null ? void 0 : existing.id)) {
|
|
14391
|
-
throw new
|
|
14497
|
+
throw new BrowserbaseSessionNotFoundError();
|
|
14392
14498
|
}
|
|
14393
14499
|
const ws = existing.connectUrl;
|
|
14394
14500
|
if (!ws) {
|
|
14395
|
-
throw new
|
|
14501
|
+
throw new StagehandInitError(
|
|
14396
14502
|
`Browserbase session resume missing connectUrl for ${resumeSessionId}`
|
|
14397
14503
|
);
|
|
14398
14504
|
}
|
|
@@ -14419,7 +14525,7 @@ function createBrowserbaseSession(apiKey, projectId, params, resumeSessionId) {
|
|
|
14419
14525
|
});
|
|
14420
14526
|
const created = yield bb.sessions.create(createPayload);
|
|
14421
14527
|
if (!(created == null ? void 0 : created.connectUrl) || !(created == null ? void 0 : created.id)) {
|
|
14422
|
-
throw new
|
|
14528
|
+
throw new StagehandInitError(
|
|
14423
14529
|
"Browserbase session creation returned an unexpected shape."
|
|
14424
14530
|
);
|
|
14425
14531
|
}
|
|
@@ -15470,6 +15576,7 @@ var Launcher = class _Launcher {
|
|
|
15470
15576
|
};
|
|
15471
15577
|
|
|
15472
15578
|
// lib/v3/launch/local.ts
|
|
15579
|
+
init_sdkErrors();
|
|
15473
15580
|
function launchLocalChrome(opts) {
|
|
15474
15581
|
return __async(this, null, function* () {
|
|
15475
15582
|
var _a, _b, _c;
|
|
@@ -15514,12 +15621,15 @@ function waitForWebSocketDebuggerUrl(port, timeoutMs) {
|
|
|
15514
15621
|
}
|
|
15515
15622
|
yield new Promise((r) => setTimeout(r, 250));
|
|
15516
15623
|
}
|
|
15517
|
-
throw new
|
|
15624
|
+
throw new ConnectionTimeoutError(
|
|
15518
15625
|
`Timed out waiting for /json/version on port ${port}${lastErrMsg ? ` (last error: ${lastErrMsg})` : ""}`
|
|
15519
15626
|
);
|
|
15520
15627
|
});
|
|
15521
15628
|
}
|
|
15522
15629
|
|
|
15630
|
+
// lib/v3/llm/LLMProvider.ts
|
|
15631
|
+
init_sdkErrors();
|
|
15632
|
+
|
|
15523
15633
|
// lib/v3/llm/aisdk.ts
|
|
15524
15634
|
var import_ai13 = require("ai");
|
|
15525
15635
|
|
|
@@ -15792,6 +15902,7 @@ var AISdkClient = class extends LLMClient {
|
|
|
15792
15902
|
// lib/v3/llm/AnthropicClient.ts
|
|
15793
15903
|
var import_sdk3 = __toESM(require("@anthropic-ai/sdk"));
|
|
15794
15904
|
var import_zod_to_json_schema3 = require("zod-to-json-schema");
|
|
15905
|
+
init_sdkErrors();
|
|
15795
15906
|
var AnthropicClient = class extends LLMClient {
|
|
15796
15907
|
constructor({
|
|
15797
15908
|
modelName,
|
|
@@ -16034,6 +16145,7 @@ var extractSchemaProperties = (jsonSchema2) => {
|
|
|
16034
16145
|
// lib/v3/llm/CerebrasClient.ts
|
|
16035
16146
|
var import_openai2 = __toESM(require("openai"));
|
|
16036
16147
|
var import_zod_to_json_schema4 = require("zod-to-json-schema");
|
|
16148
|
+
init_sdkErrors();
|
|
16037
16149
|
var CerebrasClient = class extends LLMClient {
|
|
16038
16150
|
constructor({
|
|
16039
16151
|
modelName,
|
|
@@ -16253,6 +16365,7 @@ var CerebrasClient = class extends LLMClient {
|
|
|
16253
16365
|
|
|
16254
16366
|
// lib/v3/llm/GoogleClient.ts
|
|
16255
16367
|
var import_genai4 = require("@google/genai");
|
|
16368
|
+
init_sdkErrors();
|
|
16256
16369
|
var roleMap = {
|
|
16257
16370
|
user: "user",
|
|
16258
16371
|
assistant: "model",
|
|
@@ -16621,6 +16734,7 @@ ${firstPartText.text}`;
|
|
|
16621
16734
|
// lib/v3/llm/GroqClient.ts
|
|
16622
16735
|
var import_openai3 = __toESM(require("openai"));
|
|
16623
16736
|
var import_zod_to_json_schema5 = require("zod-to-json-schema");
|
|
16737
|
+
init_sdkErrors();
|
|
16624
16738
|
var GroqClient = class extends LLMClient {
|
|
16625
16739
|
constructor({
|
|
16626
16740
|
modelName,
|
|
@@ -16842,6 +16956,7 @@ var GroqClient = class extends LLMClient {
|
|
|
16842
16956
|
var import_openai4 = __toESM(require("openai"));
|
|
16843
16957
|
var import_zod = require("openai/helpers/zod");
|
|
16844
16958
|
var import_zod_to_json_schema6 = __toESM(require("zod-to-json-schema"));
|
|
16959
|
+
init_sdkErrors();
|
|
16845
16960
|
var OpenAIClient = class extends LLMClient {
|
|
16846
16961
|
constructor({
|
|
16847
16962
|
modelName,
|
|
@@ -38465,6 +38580,7 @@ init_logger();
|
|
|
38465
38580
|
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
38466
38581
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
38467
38582
|
var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
38583
|
+
init_sdkErrors();
|
|
38468
38584
|
var connectToMCPServer = (serverConfig) => __async(null, null, function* () {
|
|
38469
38585
|
try {
|
|
38470
38586
|
let transport;
|
|
@@ -38590,6 +38706,9 @@ var LOG_LEVEL_NAMES = {
|
|
|
38590
38706
|
init_consoleMessage();
|
|
38591
38707
|
init_response();
|
|
38592
38708
|
|
|
38709
|
+
// lib/v3/types/public/index.ts
|
|
38710
|
+
init_sdkErrors();
|
|
38711
|
+
|
|
38593
38712
|
// examples/external_clients/aisdk.ts
|
|
38594
38713
|
var import_ai14 = require("ai");
|
|
38595
38714
|
var AISdkClient2 = class extends LLMClient {
|
|
@@ -38957,6 +39076,7 @@ function installV3PiercerIntoSession(session) {
|
|
|
38957
39076
|
|
|
38958
39077
|
// lib/v3/understudy/context.ts
|
|
38959
39078
|
init_executionContextRegistry();
|
|
39079
|
+
init_sdkErrors();
|
|
38960
39080
|
function isTopLevelPage(info) {
|
|
38961
39081
|
const ti = info;
|
|
38962
39082
|
return info.type === "page" && ti.subtype !== "iframe";
|
|
@@ -39020,8 +39140,9 @@ var V3Context = class _V3Context {
|
|
|
39020
39140
|
}
|
|
39021
39141
|
yield new Promise((r) => setTimeout(r, 25));
|
|
39022
39142
|
}
|
|
39023
|
-
throw new
|
|
39024
|
-
|
|
39143
|
+
throw new TimeoutError(
|
|
39144
|
+
"waitForFirstTopLevelPage (no top-level Page)",
|
|
39145
|
+
timeoutMs
|
|
39025
39146
|
);
|
|
39026
39147
|
});
|
|
39027
39148
|
}
|
|
@@ -39114,8 +39235,7 @@ var V3Context = class _V3Context {
|
|
|
39114
39235
|
getFullFrameTreeByMainFrameId(rootMainFrameId) {
|
|
39115
39236
|
return __async(this, null, function* () {
|
|
39116
39237
|
const owner = this.resolvePageByMainFrameId(rootMainFrameId);
|
|
39117
|
-
if (!owner)
|
|
39118
|
-
throw new Error(`No Page found for mainFrameId=${rootMainFrameId}`);
|
|
39238
|
+
if (!owner) throw new PageNotFoundError(`mainFrameId=${rootMainFrameId}`);
|
|
39119
39239
|
return owner.asProtocolFrameTree(rootMainFrameId);
|
|
39120
39240
|
});
|
|
39121
39241
|
}
|
|
@@ -39138,7 +39258,7 @@ var V3Context = class _V3Context {
|
|
|
39138
39258
|
if (page) return page;
|
|
39139
39259
|
yield new Promise((r) => setTimeout(r, 25));
|
|
39140
39260
|
}
|
|
39141
|
-
throw new
|
|
39261
|
+
throw new TimeoutError(`newPage: target not attached (${targetId})`, 5e3);
|
|
39142
39262
|
});
|
|
39143
39263
|
}
|
|
39144
39264
|
/**
|
|
@@ -39498,7 +39618,7 @@ var V3Context = class _V3Context {
|
|
|
39498
39618
|
yield new Promise((r) => setTimeout(r, 25));
|
|
39499
39619
|
}
|
|
39500
39620
|
if (immediate) return immediate;
|
|
39501
|
-
throw new
|
|
39621
|
+
throw new PageNotFoundError("awaitActivePage: no page available");
|
|
39502
39622
|
});
|
|
39503
39623
|
}
|
|
39504
39624
|
};
|
|
@@ -39529,6 +39649,7 @@ function resolveModel(model) {
|
|
|
39529
39649
|
// lib/v3/api.ts
|
|
39530
39650
|
var import_fetch_cookie = __toESM(require("fetch-cookie"));
|
|
39531
39651
|
var import_zod_to_json_schema7 = __toESM(require("zod-to-json-schema"));
|
|
39652
|
+
init_version();
|
|
39532
39653
|
var StagehandAPIClient = class {
|
|
39533
39654
|
constructor({ apiKey, projectId, logger }) {
|
|
39534
39655
|
this.apiKey = apiKey;
|
|
@@ -39673,9 +39794,7 @@ var StagehandAPIClient = class {
|
|
|
39673
39794
|
agentExecute(agentConfig, executeOptions, frameId) {
|
|
39674
39795
|
return __async(this, null, function* () {
|
|
39675
39796
|
if (agentConfig.integrations && agentConfig.integrations.length > 0) {
|
|
39676
|
-
throw new
|
|
39677
|
-
"MCP integrations are not supported in API mode. Set experimental: true to use MCP integrations."
|
|
39678
|
-
);
|
|
39797
|
+
throw new ExperimentalNotConfiguredError("MCP integrations");
|
|
39679
39798
|
}
|
|
39680
39799
|
if (typeof executeOptions === "object") {
|
|
39681
39800
|
if (executeOptions.page) {
|
|
@@ -39904,7 +40023,7 @@ function resolveModelConfiguration(model) {
|
|
|
39904
40023
|
if (model && typeof model === "object") {
|
|
39905
40024
|
const _a = model, { modelName } = _a, clientOptions = __objRest(_a, ["modelName"]);
|
|
39906
40025
|
if (!modelName) {
|
|
39907
|
-
throw new
|
|
40026
|
+
throw new StagehandInvalidArgumentError(
|
|
39908
40027
|
"model.modelName is required when providing client options."
|
|
39909
40028
|
);
|
|
39910
40029
|
}
|
|
@@ -39984,6 +40103,9 @@ var _V3 = class _V3 {
|
|
|
39984
40103
|
this.llmProvider = new LLMProvider(this.logger);
|
|
39985
40104
|
this.domSettleTimeoutMs = opts.domSettleTimeout;
|
|
39986
40105
|
this.disableAPI = (_g = opts.disableAPI) != null ? _g : false;
|
|
40106
|
+
if (this.experimental && !this.disableAPI) {
|
|
40107
|
+
throw new ExperimentalApiConflictError();
|
|
40108
|
+
}
|
|
39987
40109
|
const baseClientOptions = clientOptions ? __spreadValues({}, clientOptions) : {};
|
|
39988
40110
|
if (opts.llmClient) {
|
|
39989
40111
|
this.llmClient = opts.llmClient;
|
|
@@ -40404,8 +40526,9 @@ var _V3 = class _V3 {
|
|
|
40404
40526
|
if (this.opts.env === "BROWSERBASE") {
|
|
40405
40527
|
const { apiKey, projectId } = this.requireBrowserbaseCreds();
|
|
40406
40528
|
if (!apiKey || !projectId) {
|
|
40407
|
-
throw new
|
|
40408
|
-
"
|
|
40529
|
+
throw new MissingEnvironmentVariableError(
|
|
40530
|
+
"BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID",
|
|
40531
|
+
"Browserbase environment"
|
|
40409
40532
|
);
|
|
40410
40533
|
}
|
|
40411
40534
|
this.logger({
|
|
@@ -40484,7 +40607,7 @@ var _V3 = class _V3 {
|
|
|
40484
40607
|
return;
|
|
40485
40608
|
}
|
|
40486
40609
|
const neverEnv = this.opts.env;
|
|
40487
|
-
throw new
|
|
40610
|
+
throw new StagehandInitError(`Unsupported env: ${neverEnv}`);
|
|
40488
40611
|
}));
|
|
40489
40612
|
} catch (error) {
|
|
40490
40613
|
if (this.externalLogger) {
|
|
@@ -40533,8 +40656,7 @@ var _V3 = class _V3 {
|
|
|
40533
40656
|
act(input, options) {
|
|
40534
40657
|
return __async(this, null, function* () {
|
|
40535
40658
|
return yield withInstanceLogContext(this.instanceId, () => __async(this, null, function* () {
|
|
40536
|
-
if (!this.actHandler)
|
|
40537
|
-
throw new Error("V3 not initialized. Call init() before act().");
|
|
40659
|
+
if (!this.actHandler) throw new StagehandNotInitializedError("act()");
|
|
40538
40660
|
let actResult;
|
|
40539
40661
|
if (isObserveResult(input)) {
|
|
40540
40662
|
const v3Page = yield this.resolvePage(options == null ? void 0 : options.page);
|
|
@@ -40565,7 +40687,7 @@ var _V3 = class _V3 {
|
|
|
40565
40687
|
return actResult;
|
|
40566
40688
|
}
|
|
40567
40689
|
if (typeof input !== "string" || !input.trim()) {
|
|
40568
|
-
throw new
|
|
40690
|
+
throw new StagehandInvalidArgumentError(
|
|
40569
40691
|
"act(): instruction string is required unless passing an Action"
|
|
40570
40692
|
);
|
|
40571
40693
|
}
|
|
@@ -40632,7 +40754,7 @@ var _V3 = class _V3 {
|
|
|
40632
40754
|
return __async(this, null, function* () {
|
|
40633
40755
|
return yield withInstanceLogContext(this.instanceId, () => __async(this, null, function* () {
|
|
40634
40756
|
if (!this.extractHandler) {
|
|
40635
|
-
throw new
|
|
40757
|
+
throw new StagehandNotInitializedError("extract()");
|
|
40636
40758
|
}
|
|
40637
40759
|
let instruction;
|
|
40638
40760
|
let schema;
|
|
@@ -40650,7 +40772,9 @@ var _V3 = class _V3 {
|
|
|
40650
40772
|
options = a || void 0;
|
|
40651
40773
|
}
|
|
40652
40774
|
if (!instruction && schema) {
|
|
40653
|
-
throw new
|
|
40775
|
+
throw new StagehandInvalidArgumentError(
|
|
40776
|
+
"extract(): schema provided without instruction"
|
|
40777
|
+
);
|
|
40654
40778
|
}
|
|
40655
40779
|
const effectiveSchema = instruction && !schema ? defaultExtractSchema : schema;
|
|
40656
40780
|
const page = yield this.resolvePage(options == null ? void 0 : options.page);
|
|
@@ -40682,7 +40806,7 @@ var _V3 = class _V3 {
|
|
|
40682
40806
|
return __async(this, null, function* () {
|
|
40683
40807
|
return yield withInstanceLogContext(this.instanceId, () => __async(this, null, function* () {
|
|
40684
40808
|
if (!this.observeHandler) {
|
|
40685
|
-
throw new
|
|
40809
|
+
throw new StagehandNotInitializedError("observe()");
|
|
40686
40810
|
}
|
|
40687
40811
|
let instruction;
|
|
40688
40812
|
let options;
|
|
@@ -40726,7 +40850,7 @@ var _V3 = class _V3 {
|
|
|
40726
40850
|
/** Return the browser-level CDP WebSocket endpoint. */
|
|
40727
40851
|
connectURL() {
|
|
40728
40852
|
if (this.state.kind === "UNINITIALIZED") {
|
|
40729
|
-
throw new
|
|
40853
|
+
throw new StagehandNotInitializedError("connectURL()");
|
|
40730
40854
|
}
|
|
40731
40855
|
return this.state.ws;
|
|
40732
40856
|
}
|
|
@@ -40791,10 +40915,9 @@ var _V3 = class _V3 {
|
|
|
40791
40915
|
const missing = [];
|
|
40792
40916
|
if (!apiKey) missing.push("BROWSERBASE_API_KEY");
|
|
40793
40917
|
if (!projectId) missing.push("BROWSERBASE_PROJECT_ID");
|
|
40794
|
-
throw new
|
|
40795
|
-
|
|
40796
|
-
|
|
40797
|
-
)} in your .env`
|
|
40918
|
+
throw new MissingEnvironmentVariableError(
|
|
40919
|
+
missing.join(", "),
|
|
40920
|
+
"Browserbase"
|
|
40798
40921
|
);
|
|
40799
40922
|
}
|
|
40800
40923
|
this.opts.apiKey = apiKey;
|
|
@@ -40840,7 +40963,9 @@ var _V3 = class _V3 {
|
|
|
40840
40963
|
});
|
|
40841
40964
|
return frameTree.frame.id;
|
|
40842
40965
|
}
|
|
40843
|
-
throw new
|
|
40966
|
+
throw new StagehandInvalidArgumentError(
|
|
40967
|
+
"Unsupported page object passed to V3.act()"
|
|
40968
|
+
);
|
|
40844
40969
|
});
|
|
40845
40970
|
}
|
|
40846
40971
|
isPlaywrightPage(p) {
|
|
@@ -40860,9 +40985,7 @@ var _V3 = class _V3 {
|
|
|
40860
40985
|
}
|
|
40861
40986
|
const ctx = this.ctx;
|
|
40862
40987
|
if (!ctx) {
|
|
40863
|
-
throw new
|
|
40864
|
-
"V3 context not initialized. Call init() before resolving pages."
|
|
40865
|
-
);
|
|
40988
|
+
throw new StagehandNotInitializedError("resolvePage()");
|
|
40866
40989
|
}
|
|
40867
40990
|
return yield ctx.awaitActivePage();
|
|
40868
40991
|
});
|
|
@@ -40876,24 +40999,30 @@ var _V3 = class _V3 {
|
|
|
40876
40999
|
const frameId = yield this.resolveTopFrameId(input);
|
|
40877
41000
|
const page = this.ctx.resolvePageByMainFrameId(frameId);
|
|
40878
41001
|
if (!page)
|
|
40879
|
-
throw new
|
|
41002
|
+
throw new StagehandInitError(
|
|
41003
|
+
"Failed to resolve V3 Page from Playwright page."
|
|
41004
|
+
);
|
|
40880
41005
|
return page;
|
|
40881
41006
|
}
|
|
40882
41007
|
if (this.isPatchrightPage(input)) {
|
|
40883
41008
|
const frameId = yield this.resolveTopFrameId(input);
|
|
40884
41009
|
const page = this.ctx.resolvePageByMainFrameId(frameId);
|
|
40885
41010
|
if (!page)
|
|
40886
|
-
throw new
|
|
41011
|
+
throw new StagehandInitError(
|
|
41012
|
+
"Failed to resolve V3 Page from Patchright page."
|
|
41013
|
+
);
|
|
40887
41014
|
return page;
|
|
40888
41015
|
}
|
|
40889
41016
|
if (this.isPuppeteerPage(input)) {
|
|
40890
41017
|
const frameId = yield this.resolveTopFrameId(input);
|
|
40891
41018
|
const page = this.ctx.resolvePageByMainFrameId(frameId);
|
|
40892
41019
|
if (!page)
|
|
40893
|
-
throw new
|
|
41020
|
+
throw new StagehandInitError(
|
|
41021
|
+
"Failed to resolve V3 Page from Puppeteer page."
|
|
41022
|
+
);
|
|
40894
41023
|
return page;
|
|
40895
41024
|
}
|
|
40896
|
-
throw new
|
|
41025
|
+
throw new StagehandInvalidArgumentError("Unsupported page object.");
|
|
40897
41026
|
});
|
|
40898
41027
|
}
|
|
40899
41028
|
/**
|
|
@@ -40920,8 +41049,8 @@ var _V3 = class _V3 {
|
|
|
40920
41049
|
});
|
|
40921
41050
|
if (options == null ? void 0 : options.cua) {
|
|
40922
41051
|
if (((options == null ? void 0 : options.integrations) || (options == null ? void 0 : options.tools)) && !this.experimental) {
|
|
40923
|
-
throw new
|
|
40924
|
-
"MCP integrations and custom tools
|
|
41052
|
+
throw new ExperimentalNotConfiguredError(
|
|
41053
|
+
"MCP integrations and custom tools"
|
|
40925
41054
|
);
|
|
40926
41055
|
}
|
|
40927
41056
|
const modelToUse = (options == null ? void 0 : options.model) || __spreadValues({
|
|
@@ -40929,9 +41058,7 @@ var _V3 = class _V3 {
|
|
|
40929
41058
|
}, this.modelClientOptions);
|
|
40930
41059
|
const { modelName, isCua, clientOptions } = resolveModel(modelToUse);
|
|
40931
41060
|
if (!isCua) {
|
|
40932
|
-
throw new
|
|
40933
|
-
"To use the computer use agent, please provide a CUA model in the agent constructor or stagehand config. Try one of our supported CUA models: " + AVAILABLE_CUA_MODELS.join(", ")
|
|
40934
|
-
);
|
|
41061
|
+
throw new CuaModelRequiredError(AVAILABLE_CUA_MODELS);
|
|
40935
41062
|
}
|
|
40936
41063
|
const agentConfigSignature2 = this.agentCache.buildConfigSignature(options);
|
|
40937
41064
|
return {
|
|
@@ -40939,9 +41066,7 @@ var _V3 = class _V3 {
|
|
|
40939
41066
|
return withInstanceLogContext(this.instanceId, () => __async(this, null, function* () {
|
|
40940
41067
|
var _a2, _b2;
|
|
40941
41068
|
if ((options == null ? void 0 : options.integrations) && !this.experimental) {
|
|
40942
|
-
throw new
|
|
40943
|
-
"MCP integrations are experimental. Enable experimental: true in V3 options."
|
|
40944
|
-
);
|
|
41069
|
+
throw new ExperimentalNotConfiguredError("MCP integrations");
|
|
40945
41070
|
}
|
|
40946
41071
|
const tools = (options == null ? void 0 : options.integrations) ? yield resolveTools(options.integrations, options.tools) : (_a2 = options == null ? void 0 : options.tools) != null ? _a2 : {};
|
|
40947
41072
|
const handler = new V3CuaAgentHandler(
|
|
@@ -41022,8 +41147,8 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
41022
41147
|
return withInstanceLogContext(this.instanceId, () => __async(this, null, function* () {
|
|
41023
41148
|
var _a2, _b2;
|
|
41024
41149
|
if (((options == null ? void 0 : options.integrations) || (options == null ? void 0 : options.tools)) && !this.experimental) {
|
|
41025
|
-
throw new
|
|
41026
|
-
"MCP integrations and custom tools
|
|
41150
|
+
throw new ExperimentalNotConfiguredError(
|
|
41151
|
+
"MCP integrations and custom tools"
|
|
41027
41152
|
);
|
|
41028
41153
|
}
|
|
41029
41154
|
const tools = (options == null ? void 0 : options.integrations) ? yield resolveTools(options.integrations, options.tools) : (_a2 = options == null ? void 0 : options.tools) != null ? _a2 : {};
|
|
@@ -41108,6 +41233,7 @@ function isObserveResult(v) {
|
|
|
41108
41233
|
// lib/v3Evaluator.ts
|
|
41109
41234
|
var import_dotenv2 = __toESM(require("dotenv"));
|
|
41110
41235
|
var import_v318 = require("zod/v3");
|
|
41236
|
+
init_sdkErrors();
|
|
41111
41237
|
import_dotenv2.default.config();
|
|
41112
41238
|
var EvaluationSchema = import_v318.z.object({
|
|
41113
41239
|
evaluation: import_v318.z.enum(["YES", "NO"]),
|
|
@@ -41138,9 +41264,14 @@ var V3Evaluator = class {
|
|
|
41138
41264
|
screenshotDelayMs = 250,
|
|
41139
41265
|
agentReasoning
|
|
41140
41266
|
} = options;
|
|
41141
|
-
if (!question)
|
|
41267
|
+
if (!question)
|
|
41268
|
+
throw new StagehandInvalidArgumentError(
|
|
41269
|
+
"Question cannot be an empty string"
|
|
41270
|
+
);
|
|
41142
41271
|
if (!answer && !screenshot)
|
|
41143
|
-
throw new
|
|
41272
|
+
throw new StagehandInvalidArgumentError(
|
|
41273
|
+
"Either answer (text) or screenshot must be provided"
|
|
41274
|
+
);
|
|
41144
41275
|
if (Array.isArray(screenshot)) {
|
|
41145
41276
|
return this._evaluateWithMultipleScreenshots({
|
|
41146
41277
|
question,
|
|
@@ -41208,7 +41339,10 @@ ${agentReasoning}` : question
|
|
|
41208
41339
|
systemPrompt = "You are an expert evaluator that returns YES or NO with a concise reasoning.",
|
|
41209
41340
|
screenshotDelayMs = 250
|
|
41210
41341
|
} = options;
|
|
41211
|
-
if (!(questions == null ? void 0 : questions.length))
|
|
41342
|
+
if (!(questions == null ? void 0 : questions.length))
|
|
41343
|
+
throw new StagehandInvalidArgumentError(
|
|
41344
|
+
"Questions array cannot be empty"
|
|
41345
|
+
);
|
|
41212
41346
|
yield new Promise((r) => setTimeout(r, screenshotDelayMs));
|
|
41213
41347
|
let imageBuffer;
|
|
41214
41348
|
if (screenshot) {
|
|
@@ -41279,9 +41413,14 @@ You will be given multiple questions${screenshot ? " with a screenshot" : ""}. $
|
|
|
41279
41413
|
${agentReasoning ? "The agent's reasoning provides crucial context about what actions were attempted, what was observed, and the decision-making process. Use this alongside the visual evidence to make a comprehensive evaluation." : ""}
|
|
41280
41414
|
Today's date is ${(/* @__PURE__ */ new Date()).toLocaleDateString()}`
|
|
41281
41415
|
} = options;
|
|
41282
|
-
if (!question)
|
|
41416
|
+
if (!question)
|
|
41417
|
+
throw new StagehandInvalidArgumentError(
|
|
41418
|
+
"Question cannot be an empty string"
|
|
41419
|
+
);
|
|
41283
41420
|
if (!screenshots || screenshots.length === 0)
|
|
41284
|
-
throw new
|
|
41421
|
+
throw new StagehandInvalidArgumentError(
|
|
41422
|
+
"At least one screenshot must be provided"
|
|
41423
|
+
);
|
|
41285
41424
|
const llmClient = this.getClient();
|
|
41286
41425
|
const imageContents = screenshots.map((s) => ({
|
|
41287
41426
|
type: "image_url",
|
|
@@ -41335,9 +41474,12 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
41335
41474
|
AnnotatedScreenshotText,
|
|
41336
41475
|
BrowserbaseSessionNotFoundError,
|
|
41337
41476
|
CaptchaTimeoutError,
|
|
41477
|
+
ConnectionTimeoutError,
|
|
41338
41478
|
ConsoleMessage,
|
|
41339
41479
|
ContentFrameNotFoundError,
|
|
41340
41480
|
CreateChatCompletionResponseError,
|
|
41481
|
+
CuaModelRequiredError,
|
|
41482
|
+
ElementNotVisibleError,
|
|
41341
41483
|
ExperimentalApiConflictError,
|
|
41342
41484
|
ExperimentalNotConfiguredError,
|
|
41343
41485
|
HandlerNotInitializedError,
|
|
@@ -41348,7 +41490,10 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
41348
41490
|
MCPConnectionError,
|
|
41349
41491
|
MissingEnvironmentVariableError,
|
|
41350
41492
|
MissingLLMConfigurationError,
|
|
41493
|
+
PageNotFoundError,
|
|
41351
41494
|
Response,
|
|
41495
|
+
ResponseBodyError,
|
|
41496
|
+
ResponseParseError,
|
|
41352
41497
|
Stagehand,
|
|
41353
41498
|
StagehandAPIError,
|
|
41354
41499
|
StagehandAPIUnauthorizedError,
|
|
@@ -41371,6 +41516,7 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
41371
41516
|
StagehandShadowRootMissingError,
|
|
41372
41517
|
StagehandShadowSegmentEmptyError,
|
|
41373
41518
|
StagehandShadowSegmentNotFoundError,
|
|
41519
|
+
TimeoutError,
|
|
41374
41520
|
UnsupportedAISDKModelProviderError,
|
|
41375
41521
|
UnsupportedModelError,
|
|
41376
41522
|
UnsupportedModelProviderError,
|