@browserbasehq/stagehand 3.0.6-alpha-7a8e7055724fe68d36940e483ce84546c597f06d → 3.0.6-alpha-1ebc7e1be4d3129dbba48b0a05b5ac006d3387eb
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/README.md +3 -3
- package/dist/index.d.ts +10 -1
- package/dist/index.js +340 -302
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<img alt="MIT License" src="../../media/light_license.svg" />
|
|
21
21
|
</picture>
|
|
22
22
|
</a>
|
|
23
|
-
<a href="https://join.slack.com/t/stagehand-dev/shared_invite/zt-
|
|
23
|
+
<a href="https://join.slack.com/t/stagehand-dev/shared_invite/zt-3kg9piw3m-rxqCIzeuYQMXG315yHigPQ">
|
|
24
24
|
<picture>
|
|
25
25
|
<source media="(prefers-color-scheme: dark)" srcset="../../media/dark_slack.svg" />
|
|
26
26
|
<img alt="Slack Community" src="../../media/light_slack.svg" />
|
|
@@ -137,9 +137,9 @@ In your project's `package.json` set:
|
|
|
137
137
|
## Contributing
|
|
138
138
|
|
|
139
139
|
> [!NOTE]
|
|
140
|
-
> We highly value contributions to Stagehand! For questions or support, please join our [Slack community](https://join.slack.com/t/stagehand-dev/shared_invite/zt-
|
|
140
|
+
> We highly value contributions to Stagehand! For questions or support, please join our [Slack community](https://join.slack.com/t/stagehand-dev/shared_invite/zt-3kg9piw3m-rxqCIzeuYQMXG315yHigPQ).
|
|
141
141
|
|
|
142
|
-
At a high level, we're focused on improving reliability, extensibility, speed, and cost in that order of priority. If you're interested in contributing, **bug fixes and small improvements are the best way to get started**. For more involved features, we strongly recommend reaching out to [Miguel Gonzalez](https://x.com/miguel_gonzf) or [Paul Klein](https://x.com/pk_iv) in our [Slack community](https://join.slack.com/t/stagehand-dev/shared_invite/zt-
|
|
142
|
+
At a high level, we're focused on improving reliability, extensibility, speed, and cost in that order of priority. If you're interested in contributing, **bug fixes and small improvements are the best way to get started**. For more involved features, we strongly recommend reaching out to [Miguel Gonzalez](https://x.com/miguel_gonzf) or [Paul Klein](https://x.com/pk_iv) in our [Slack community](https://join.slack.com/t/stagehand-dev/shared_invite/zt-3kg9piw3m-rxqCIzeuYQMXG315yHigPQ) before starting to ensure that your contribution aligns with our goals.
|
|
143
143
|
|
|
144
144
|
<!-- For more information, please see our [Contributing Guide](https://docs.stagehand.dev/examples/contributing). -->
|
|
145
145
|
|
package/dist/index.d.ts
CHANGED
|
@@ -778,6 +778,15 @@ declare class ResponseParseError extends StagehandError {
|
|
|
778
778
|
declare class TimeoutError extends StagehandError {
|
|
779
779
|
constructor(operation: string, timeoutMs: number);
|
|
780
780
|
}
|
|
781
|
+
declare class ActTimeoutError extends TimeoutError {
|
|
782
|
+
constructor(timeoutMs: number);
|
|
783
|
+
}
|
|
784
|
+
declare class ExtractTimeoutError extends TimeoutError {
|
|
785
|
+
constructor(timeoutMs: number);
|
|
786
|
+
}
|
|
787
|
+
declare class ObserveTimeoutError extends TimeoutError {
|
|
788
|
+
constructor(timeoutMs: number);
|
|
789
|
+
}
|
|
781
790
|
declare class PageNotFoundError extends StagehandError {
|
|
782
791
|
constructor(identifier: string);
|
|
783
792
|
}
|
|
@@ -2400,4 +2409,4 @@ declare class V3Evaluator {
|
|
|
2400
2409
|
private _evaluateWithMultipleScreenshots;
|
|
2401
2410
|
}
|
|
2402
2411
|
|
|
2403
|
-
export { type AISDKCustomProvider, type AISDKProvider, AISdkClient, AVAILABLE_CUA_MODELS, type ActOptions, type ActResult, type Action, type ActionExecutionResult, type AgentAction, type AgentCallbacks, type AgentConfig, type AgentContext, type AgentExecuteCallbacks, type AgentExecuteOptions, type AgentExecuteOptionsBase, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentModelConfig, AgentProvider, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentState, type AgentStreamCallbacks, type AgentStreamExecuteOptions, type AgentStreamResult, type AgentType, AnnotatedScreenshotText, type AnthropicClientOptions, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AnyPage, type AvailableCuaModel, type AvailableModel, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, ConnectionTimeoutError, type ConsoleListener, ConsoleMessage, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, CuaModelRequiredError, ElementNotVisibleError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, type FunctionCallItem, type GoogleServiceAccountCredentials, type GoogleVertexProviderSettings, HandlerNotInitializedError, type HistoryEntry, type InferStagehandSchema, InvalidAISDKModelFormatError, type JsonSchema, type JsonSchemaDocument, type JsonSchemaProperty, LLMClient, type LLMParsedResponse, type LLMResponse, LLMResponseError, type LLMTool, type LLMUsage, LOG_LEVEL_NAMES, type LoadState, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelConfiguration, type ModelProvider, type NonStreamingAgentInstance, type ObserveOptions, type OpenAIClientOptions, Page, PageNotFoundError, Response$1 as Response, ResponseBodyError, type ResponseInputItem, type ResponseItem, ResponseParseError, V3 as Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, type StagehandZodObject, type StagehandZodSchema, type StreamingAgentInstance, StreamingCallbacksInNonStreamingModeError, TimeoutError, type ToolUseItem, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, V3, type V3Env, V3Evaluator, V3FunctionName, type V3Options, XPathResolutionError, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getZodType, injectUrls, isRunningInBun, isZod3Schema, isZod4Schema, jsonSchemaToZod, loadApiKeyFromEnv, modelToAgentProviderMap, pageTextSchema, providerEnvVarMap, toGeminiSchema, toJsonSchema, transformSchema, trimTrailingTextNode, validateZodSchema };
|
|
2412
|
+
export { type AISDKCustomProvider, type AISDKProvider, AISdkClient, AVAILABLE_CUA_MODELS, type ActOptions, type ActResult, ActTimeoutError, type Action, type ActionExecutionResult, type AgentAction, type AgentCallbacks, type AgentConfig, type AgentContext, type AgentExecuteCallbacks, type AgentExecuteOptions, type AgentExecuteOptionsBase, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentModelConfig, AgentProvider, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentState, type AgentStreamCallbacks, type AgentStreamExecuteOptions, type AgentStreamResult, type AgentType, AnnotatedScreenshotText, type AnthropicClientOptions, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AnyPage, type AvailableCuaModel, type AvailableModel, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, ConnectionTimeoutError, type ConsoleListener, ConsoleMessage, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, CuaModelRequiredError, ElementNotVisibleError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, ExtractTimeoutError, type FunctionCallItem, type GoogleServiceAccountCredentials, type GoogleVertexProviderSettings, HandlerNotInitializedError, type HistoryEntry, type InferStagehandSchema, InvalidAISDKModelFormatError, type JsonSchema, type JsonSchemaDocument, type JsonSchemaProperty, LLMClient, type LLMParsedResponse, type LLMResponse, LLMResponseError, type LLMTool, type LLMUsage, LOG_LEVEL_NAMES, type LoadState, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelConfiguration, type ModelProvider, type NonStreamingAgentInstance, type ObserveOptions, ObserveTimeoutError, type OpenAIClientOptions, Page, PageNotFoundError, Response$1 as Response, ResponseBodyError, type ResponseInputItem, type ResponseItem, ResponseParseError, V3 as Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, type StagehandZodObject, type StagehandZodSchema, type StreamingAgentInstance, StreamingCallbacksInNonStreamingModeError, TimeoutError, type ToolUseItem, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, V3, type V3Env, V3Evaluator, V3FunctionName, type V3Options, XPathResolutionError, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getZodType, injectUrls, isRunningInBun, isZod3Schema, isZod4Schema, jsonSchemaToZod, loadApiKeyFromEnv, modelToAgentProviderMap, pageTextSchema, providerEnvVarMap, toGeminiSchema, toJsonSchema, transformSchema, trimTrailingTextNode, validateZodSchema };
|
package/dist/index.js
CHANGED
|
@@ -141,12 +141,12 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
141
141
|
var STAGEHAND_VERSION;
|
|
142
142
|
var init_version = __esm({
|
|
143
143
|
"lib/version.ts"() {
|
|
144
|
-
STAGEHAND_VERSION = "3.0.6-alpha-
|
|
144
|
+
STAGEHAND_VERSION = "3.0.6-alpha-1ebc7e1be4d3129dbba48b0a05b5ac006d3387eb";
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
// lib/v3/types/public/sdkErrors.ts
|
|
149
|
-
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, StreamingCallbacksInNonStreamingModeError;
|
|
149
|
+
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, ActTimeoutError, ExtractTimeoutError, ObserveTimeoutError, PageNotFoundError, ConnectionTimeoutError, StreamingCallbacksInNonStreamingModeError;
|
|
150
150
|
var init_sdkErrors = __esm({
|
|
151
151
|
"lib/v3/types/public/sdkErrors.ts"() {
|
|
152
152
|
init_version();
|
|
@@ -396,6 +396,24 @@ ${JSON.stringify(issues, null, 2)}`);
|
|
|
396
396
|
super(`${operation} timed out after ${timeoutMs}ms`);
|
|
397
397
|
}
|
|
398
398
|
};
|
|
399
|
+
ActTimeoutError = class extends TimeoutError {
|
|
400
|
+
constructor(timeoutMs) {
|
|
401
|
+
super("act()", timeoutMs);
|
|
402
|
+
this.name = "ActTimeoutError";
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
ExtractTimeoutError = class extends TimeoutError {
|
|
406
|
+
constructor(timeoutMs) {
|
|
407
|
+
super("extract()", timeoutMs);
|
|
408
|
+
this.name = "ExtractTimeoutError";
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
ObserveTimeoutError = class extends TimeoutError {
|
|
412
|
+
constructor(timeoutMs) {
|
|
413
|
+
super("observe()", timeoutMs);
|
|
414
|
+
this.name = "ObserveTimeoutError";
|
|
415
|
+
}
|
|
416
|
+
};
|
|
399
417
|
PageNotFoundError = class extends StagehandError {
|
|
400
418
|
constructor(identifier) {
|
|
401
419
|
super(`No Page found for ${identifier}`);
|
|
@@ -25989,6 +26007,7 @@ var v3_exports = {};
|
|
|
25989
26007
|
__export(v3_exports, {
|
|
25990
26008
|
AISdkClient: () => AISdkClient2,
|
|
25991
26009
|
AVAILABLE_CUA_MODELS: () => AVAILABLE_CUA_MODELS,
|
|
26010
|
+
ActTimeoutError: () => ActTimeoutError,
|
|
25992
26011
|
AgentProvider: () => AgentProvider,
|
|
25993
26012
|
AgentScreenshotProviderError: () => AgentScreenshotProviderError,
|
|
25994
26013
|
AnnotatedScreenshotText: () => AnnotatedScreenshotText,
|
|
@@ -26002,6 +26021,7 @@ __export(v3_exports, {
|
|
|
26002
26021
|
ElementNotVisibleError: () => ElementNotVisibleError,
|
|
26003
26022
|
ExperimentalApiConflictError: () => ExperimentalApiConflictError,
|
|
26004
26023
|
ExperimentalNotConfiguredError: () => ExperimentalNotConfiguredError,
|
|
26024
|
+
ExtractTimeoutError: () => ExtractTimeoutError,
|
|
26005
26025
|
HandlerNotInitializedError: () => HandlerNotInitializedError,
|
|
26006
26026
|
InvalidAISDKModelFormatError: () => InvalidAISDKModelFormatError,
|
|
26007
26027
|
LLMClient: () => LLMClient,
|
|
@@ -26010,6 +26030,7 @@ __export(v3_exports, {
|
|
|
26010
26030
|
MCPConnectionError: () => MCPConnectionError,
|
|
26011
26031
|
MissingEnvironmentVariableError: () => MissingEnvironmentVariableError,
|
|
26012
26032
|
MissingLLMConfigurationError: () => MissingLLMConfigurationError,
|
|
26033
|
+
ObserveTimeoutError: () => ObserveTimeoutError,
|
|
26013
26034
|
PageNotFoundError: () => PageNotFoundError,
|
|
26014
26035
|
Response: () => Response2,
|
|
26015
26036
|
ResponseBodyError: () => ResponseBodyError,
|
|
@@ -28490,6 +28511,7 @@ var V3FunctionName = /* @__PURE__ */ ((V3FunctionName2) => {
|
|
|
28490
28511
|
})(V3FunctionName || {});
|
|
28491
28512
|
|
|
28492
28513
|
// lib/v3/handlers/actHandler.ts
|
|
28514
|
+
init_sdkErrors();
|
|
28493
28515
|
init_snapshot();
|
|
28494
28516
|
|
|
28495
28517
|
// lib/v3/types/private/handlers.ts
|
|
@@ -29142,6 +29164,23 @@ function handlePossibleNavigation(actionDescription, xpath, initialUrl, frame) {
|
|
|
29142
29164
|
});
|
|
29143
29165
|
}
|
|
29144
29166
|
|
|
29167
|
+
// lib/v3/handlers/handlerUtils/timeoutGuard.ts
|
|
29168
|
+
init_sdkErrors();
|
|
29169
|
+
function createTimeoutGuard(timeoutMs, errorFactory) {
|
|
29170
|
+
if (!timeoutMs || timeoutMs <= 0) {
|
|
29171
|
+
return () => {
|
|
29172
|
+
};
|
|
29173
|
+
}
|
|
29174
|
+
const startTime = Date.now();
|
|
29175
|
+
return () => {
|
|
29176
|
+
var _a4;
|
|
29177
|
+
if (Date.now() - startTime >= timeoutMs) {
|
|
29178
|
+
const err = (_a4 = errorFactory == null ? void 0 : errorFactory(timeoutMs)) != null ? _a4 : new TimeoutError("operation", timeoutMs);
|
|
29179
|
+
throw err;
|
|
29180
|
+
}
|
|
29181
|
+
};
|
|
29182
|
+
}
|
|
29183
|
+
|
|
29145
29184
|
// lib/v3/handlers/actHandler.ts
|
|
29146
29185
|
var ActHandler = class {
|
|
29147
29186
|
constructor(llmClient, defaultModelName, defaultClientOptions, resolveLlmClient, systemPrompt, logInferenceToFile, selfHeal, onMetrics, defaultDomSettleTimeoutMs) {
|
|
@@ -29209,111 +29248,109 @@ var ActHandler = class {
|
|
|
29209
29248
|
return __async(this, null, function* () {
|
|
29210
29249
|
const { instruction, page, variables, timeout, model } = params;
|
|
29211
29250
|
const llmClient = this.resolveLlmClient(model);
|
|
29212
|
-
const
|
|
29213
|
-
|
|
29214
|
-
|
|
29215
|
-
|
|
29216
|
-
|
|
29217
|
-
|
|
29218
|
-
|
|
29219
|
-
|
|
29220
|
-
|
|
29221
|
-
|
|
29222
|
-
|
|
29223
|
-
|
|
29224
|
-
|
|
29225
|
-
|
|
29226
|
-
|
|
29227
|
-
|
|
29228
|
-
|
|
29229
|
-
|
|
29230
|
-
|
|
29231
|
-
|
|
29232
|
-
|
|
29233
|
-
|
|
29234
|
-
|
|
29235
|
-
|
|
29236
|
-
|
|
29237
|
-
|
|
29238
|
-
|
|
29239
|
-
|
|
29240
|
-
|
|
29241
|
-
|
|
29242
|
-
|
|
29243
|
-
|
|
29244
|
-
|
|
29245
|
-
}
|
|
29246
|
-
const firstResult = yield this.takeDeterministicAction(
|
|
29247
|
-
firstAction,
|
|
29248
|
-
page,
|
|
29249
|
-
this.defaultDomSettleTimeoutMs,
|
|
29250
|
-
llmClient
|
|
29251
|
-
);
|
|
29252
|
-
if ((actInferenceResponse == null ? void 0 : actInferenceResponse.twoStep) !== true) {
|
|
29253
|
-
return firstResult;
|
|
29254
|
-
}
|
|
29255
|
-
const {
|
|
29256
|
-
combinedTree: combinedTree2,
|
|
29257
|
-
combinedXpathMap: combinedXpathMap2
|
|
29258
|
-
} = yield captureHybridSnapshot(page, {
|
|
29259
|
-
experimental: true
|
|
29260
|
-
});
|
|
29261
|
-
let diffedTree = diffCombinedTrees(combinedTree, combinedTree2);
|
|
29262
|
-
if (!diffedTree.trim()) {
|
|
29263
|
-
diffedTree = combinedTree2;
|
|
29264
|
-
}
|
|
29265
|
-
const previousAction = `method: ${firstAction.method}, description: ${firstAction.description}, arguments: ${firstAction.arguments}`;
|
|
29266
|
-
const stepTwoInstructions = buildStepTwoPrompt(
|
|
29267
|
-
instruction,
|
|
29268
|
-
previousAction,
|
|
29269
|
-
Object.values(SupportedPlaywrightAction).filter(
|
|
29270
|
-
(action) => action !== "selectOptionFromDropdown" /* SELECT_OPTION_FROM_DROPDOWN */
|
|
29271
|
-
),
|
|
29272
|
-
variables
|
|
29273
|
-
);
|
|
29274
|
-
const { action: secondAction } = yield this.getActionFromLLM({
|
|
29275
|
-
instruction: stepTwoInstructions,
|
|
29276
|
-
domElements: diffedTree,
|
|
29277
|
-
xpathMap: combinedXpathMap2,
|
|
29278
|
-
llmClient,
|
|
29279
|
-
variables
|
|
29251
|
+
const effectiveTimeoutMs = typeof timeout === "number" && timeout > 0 ? timeout : void 0;
|
|
29252
|
+
const ensureTimeRemaining = createTimeoutGuard(
|
|
29253
|
+
effectiveTimeoutMs,
|
|
29254
|
+
(ms) => new ActTimeoutError(ms)
|
|
29255
|
+
);
|
|
29256
|
+
ensureTimeRemaining();
|
|
29257
|
+
yield waitForDomNetworkQuiet(
|
|
29258
|
+
page.mainFrame(),
|
|
29259
|
+
this.defaultDomSettleTimeoutMs
|
|
29260
|
+
);
|
|
29261
|
+
ensureTimeRemaining();
|
|
29262
|
+
const { combinedTree, combinedXpathMap } = yield captureHybridSnapshot(
|
|
29263
|
+
page,
|
|
29264
|
+
{ experimental: true }
|
|
29265
|
+
);
|
|
29266
|
+
const actInstruction = buildActPrompt(
|
|
29267
|
+
instruction,
|
|
29268
|
+
Object.values(SupportedPlaywrightAction),
|
|
29269
|
+
variables
|
|
29270
|
+
);
|
|
29271
|
+
ensureTimeRemaining();
|
|
29272
|
+
const { action: firstAction, response: actInferenceResponse } = yield this.getActionFromLLM({
|
|
29273
|
+
instruction: actInstruction,
|
|
29274
|
+
domElements: combinedTree,
|
|
29275
|
+
xpathMap: combinedXpathMap,
|
|
29276
|
+
llmClient,
|
|
29277
|
+
variables
|
|
29278
|
+
});
|
|
29279
|
+
if (!firstAction) {
|
|
29280
|
+
v3Logger({
|
|
29281
|
+
category: "action",
|
|
29282
|
+
message: "no actionable element returned by LLM",
|
|
29283
|
+
level: 1
|
|
29280
29284
|
});
|
|
29281
|
-
if (!secondAction) {
|
|
29282
|
-
return firstResult;
|
|
29283
|
-
}
|
|
29284
|
-
const secondResult = yield this.takeDeterministicAction(
|
|
29285
|
-
secondAction,
|
|
29286
|
-
page,
|
|
29287
|
-
this.defaultDomSettleTimeoutMs,
|
|
29288
|
-
llmClient
|
|
29289
|
-
);
|
|
29290
29285
|
return {
|
|
29291
|
-
success:
|
|
29292
|
-
message:
|
|
29293
|
-
actionDescription:
|
|
29294
|
-
actions: [
|
|
29295
|
-
...firstResult.actions || [],
|
|
29296
|
-
...secondResult.actions || []
|
|
29297
|
-
]
|
|
29286
|
+
success: false,
|
|
29287
|
+
message: "Failed to perform act: No action found",
|
|
29288
|
+
actionDescription: instruction,
|
|
29289
|
+
actions: []
|
|
29298
29290
|
};
|
|
29291
|
+
}
|
|
29292
|
+
ensureTimeRemaining();
|
|
29293
|
+
const firstResult = yield this.takeDeterministicAction(
|
|
29294
|
+
firstAction,
|
|
29295
|
+
page,
|
|
29296
|
+
this.defaultDomSettleTimeoutMs,
|
|
29297
|
+
llmClient,
|
|
29298
|
+
ensureTimeRemaining
|
|
29299
|
+
);
|
|
29300
|
+
if ((actInferenceResponse == null ? void 0 : actInferenceResponse.twoStep) !== true) {
|
|
29301
|
+
return firstResult;
|
|
29302
|
+
}
|
|
29303
|
+
ensureTimeRemaining();
|
|
29304
|
+
const { combinedTree: combinedTree2, combinedXpathMap: combinedXpathMap2 } = yield captureHybridSnapshot(page, {
|
|
29305
|
+
experimental: true
|
|
29299
29306
|
});
|
|
29300
|
-
|
|
29301
|
-
|
|
29302
|
-
|
|
29303
|
-
|
|
29304
|
-
|
|
29305
|
-
|
|
29306
|
-
|
|
29307
|
-
|
|
29308
|
-
|
|
29309
|
-
)
|
|
29310
|
-
|
|
29311
|
-
|
|
29307
|
+
let diffedTree = diffCombinedTrees(combinedTree, combinedTree2);
|
|
29308
|
+
if (!diffedTree.trim()) {
|
|
29309
|
+
diffedTree = combinedTree2;
|
|
29310
|
+
}
|
|
29311
|
+
const previousAction = `method: ${firstAction.method}, description: ${firstAction.description}, arguments: ${firstAction.arguments}`;
|
|
29312
|
+
const stepTwoInstructions = buildStepTwoPrompt(
|
|
29313
|
+
instruction,
|
|
29314
|
+
previousAction,
|
|
29315
|
+
Object.values(SupportedPlaywrightAction).filter(
|
|
29316
|
+
(action) => action !== "selectOptionFromDropdown" /* SELECT_OPTION_FROM_DROPDOWN */
|
|
29317
|
+
),
|
|
29318
|
+
variables
|
|
29319
|
+
);
|
|
29320
|
+
ensureTimeRemaining();
|
|
29321
|
+
const { action: secondAction } = yield this.getActionFromLLM({
|
|
29322
|
+
instruction: stepTwoInstructions,
|
|
29323
|
+
domElements: diffedTree,
|
|
29324
|
+
xpathMap: combinedXpathMap2,
|
|
29325
|
+
llmClient,
|
|
29326
|
+
variables
|
|
29327
|
+
});
|
|
29328
|
+
if (!secondAction) {
|
|
29329
|
+
return firstResult;
|
|
29330
|
+
}
|
|
29331
|
+
ensureTimeRemaining();
|
|
29332
|
+
const secondResult = yield this.takeDeterministicAction(
|
|
29333
|
+
secondAction,
|
|
29334
|
+
page,
|
|
29335
|
+
this.defaultDomSettleTimeoutMs,
|
|
29336
|
+
llmClient,
|
|
29337
|
+
ensureTimeRemaining
|
|
29338
|
+
);
|
|
29339
|
+
return {
|
|
29340
|
+
success: firstResult.success && secondResult.success,
|
|
29341
|
+
message: secondResult.success ? `${firstResult.message} \u2192 ${secondResult.message}` : `${firstResult.message} \u2192 ${secondResult.message}`,
|
|
29342
|
+
actionDescription: firstResult.actionDescription,
|
|
29343
|
+
actions: [
|
|
29344
|
+
...firstResult.actions || [],
|
|
29345
|
+
...secondResult.actions || []
|
|
29346
|
+
]
|
|
29347
|
+
};
|
|
29312
29348
|
});
|
|
29313
29349
|
}
|
|
29314
|
-
takeDeterministicAction(action, page, domSettleTimeoutMs, llmClientOverride) {
|
|
29350
|
+
takeDeterministicAction(action, page, domSettleTimeoutMs, llmClientOverride, ensureTimeRemaining) {
|
|
29315
29351
|
return __async(this, null, function* () {
|
|
29316
29352
|
var _a4;
|
|
29353
|
+
ensureTimeRemaining == null ? void 0 : ensureTimeRemaining();
|
|
29317
29354
|
const settleTimeout = domSettleTimeoutMs != null ? domSettleTimeoutMs : this.defaultDomSettleTimeoutMs;
|
|
29318
29355
|
const effectiveClient = llmClientOverride != null ? llmClientOverride : this.llmClient;
|
|
29319
29356
|
const method = (_a4 = action.method) == null ? void 0 : _a4.trim();
|
|
@@ -29335,6 +29372,7 @@ var ActHandler = class {
|
|
|
29335
29372
|
}
|
|
29336
29373
|
const args = Array.isArray(action.arguments) ? action.arguments : [];
|
|
29337
29374
|
try {
|
|
29375
|
+
ensureTimeRemaining == null ? void 0 : ensureTimeRemaining();
|
|
29338
29376
|
yield performUnderstudyMethod(
|
|
29339
29377
|
page,
|
|
29340
29378
|
page.mainFrame(),
|
|
@@ -29357,6 +29395,9 @@ var ActHandler = class {
|
|
|
29357
29395
|
]
|
|
29358
29396
|
};
|
|
29359
29397
|
} catch (err) {
|
|
29398
|
+
if (err instanceof ActTimeoutError) {
|
|
29399
|
+
throw err;
|
|
29400
|
+
}
|
|
29360
29401
|
const msg = err instanceof Error ? err.message : String(err);
|
|
29361
29402
|
if (this.selfHeal) {
|
|
29362
29403
|
v3Logger({
|
|
@@ -29373,6 +29414,7 @@ var ActHandler = class {
|
|
|
29373
29414
|
});
|
|
29374
29415
|
try {
|
|
29375
29416
|
const actCommand = action.description ? action.description.toLowerCase().startsWith(method.toLowerCase()) ? action.description : `${method} ${action.description}` : method;
|
|
29417
|
+
ensureTimeRemaining == null ? void 0 : ensureTimeRemaining();
|
|
29376
29418
|
const { combinedTree, combinedXpathMap } = yield captureHybridSnapshot(page, {
|
|
29377
29419
|
experimental: true
|
|
29378
29420
|
});
|
|
@@ -29381,6 +29423,7 @@ var ActHandler = class {
|
|
|
29381
29423
|
Object.values(SupportedPlaywrightAction),
|
|
29382
29424
|
{}
|
|
29383
29425
|
);
|
|
29426
|
+
ensureTimeRemaining == null ? void 0 : ensureTimeRemaining();
|
|
29384
29427
|
const { action: fallbackAction, response: fallbackResponse } = yield this.getActionFromLLM({
|
|
29385
29428
|
instruction,
|
|
29386
29429
|
domElements: combinedTree,
|
|
@@ -29401,6 +29444,7 @@ var ActHandler = class {
|
|
|
29401
29444
|
if (fallbackAction == null ? void 0 : fallbackAction.selector) {
|
|
29402
29445
|
newSelector = fallbackAction.selector;
|
|
29403
29446
|
}
|
|
29447
|
+
ensureTimeRemaining == null ? void 0 : ensureTimeRemaining();
|
|
29404
29448
|
yield performUnderstudyMethod(
|
|
29405
29449
|
page,
|
|
29406
29450
|
page.mainFrame(),
|
|
@@ -29423,6 +29467,9 @@ var ActHandler = class {
|
|
|
29423
29467
|
]
|
|
29424
29468
|
};
|
|
29425
29469
|
} catch (retryErr) {
|
|
29470
|
+
if (retryErr instanceof ActTimeoutError) {
|
|
29471
|
+
throw retryErr;
|
|
29472
|
+
}
|
|
29426
29473
|
const retryMsg = retryErr instanceof Error ? retryErr.message : String(retryErr);
|
|
29427
29474
|
return {
|
|
29428
29475
|
success: false,
|
|
@@ -29501,122 +29548,110 @@ var ExtractHandler = class {
|
|
|
29501
29548
|
}
|
|
29502
29549
|
extract(params) {
|
|
29503
29550
|
return __async(this, null, function* () {
|
|
29551
|
+
var _a4, _b, _d2;
|
|
29504
29552
|
const { instruction, schema, page, selector, timeout, model } = params;
|
|
29505
29553
|
const llmClient = this.resolveLlmClient(model);
|
|
29506
|
-
const
|
|
29507
|
-
|
|
29508
|
-
|
|
29509
|
-
|
|
29510
|
-
|
|
29511
|
-
|
|
29512
|
-
|
|
29513
|
-
|
|
29514
|
-
|
|
29515
|
-
|
|
29516
|
-
|
|
29517
|
-
|
|
29518
|
-
if (!instruction && schema) {
|
|
29519
|
-
throw new StagehandInvalidArgumentError(
|
|
29520
|
-
"extract() requires an instruction when a schema is provided."
|
|
29521
|
-
);
|
|
29522
|
-
}
|
|
29523
|
-
const focusSelector = (_b = selector == null ? void 0 : selector.replace(/^xpath=/, "")) != null ? _b : "";
|
|
29524
|
-
const { combinedTree, combinedUrlMap } = yield captureHybridSnapshot(
|
|
29525
|
-
page,
|
|
29526
|
-
{
|
|
29527
|
-
experimental: this.experimental,
|
|
29528
|
-
focusSelector
|
|
29529
|
-
}
|
|
29530
|
-
);
|
|
29531
|
-
v3Logger({
|
|
29532
|
-
category: "extraction",
|
|
29533
|
-
message: "Starting extraction using a11y snapshot",
|
|
29534
|
-
level: 1,
|
|
29535
|
-
auxiliary: instruction ? { instruction: { value: instruction, type: "string" } } : void 0
|
|
29536
|
-
});
|
|
29537
|
-
const baseSchema = schema != null ? schema : defaultExtractSchema;
|
|
29538
|
-
const isObjectSchema = getZodType(baseSchema) === "object";
|
|
29539
|
-
const WRAP_KEY = "value";
|
|
29540
|
-
const factory6 = getZFactory(baseSchema);
|
|
29541
|
-
const objectSchema = isObjectSchema ? baseSchema : factory6.object({
|
|
29542
|
-
[WRAP_KEY]: baseSchema
|
|
29543
|
-
});
|
|
29544
|
-
const [transformedSchema, urlFieldPaths] = transformUrlStringsToNumericIds(objectSchema);
|
|
29545
|
-
const extractionResponse = yield extract({
|
|
29546
|
-
instruction,
|
|
29547
|
-
domElements: combinedTree,
|
|
29548
|
-
schema: transformedSchema,
|
|
29549
|
-
llmClient,
|
|
29550
|
-
userProvidedInstructions: this.systemPrompt,
|
|
29551
|
-
logger: v3Logger,
|
|
29552
|
-
logInferenceToFile: this.logInferenceToFile
|
|
29553
|
-
});
|
|
29554
|
-
const _c = extractionResponse, {
|
|
29555
|
-
metadata: { completed },
|
|
29556
|
-
prompt_tokens,
|
|
29557
|
-
completion_tokens,
|
|
29558
|
-
reasoning_tokens = 0,
|
|
29559
|
-
cached_input_tokens = 0,
|
|
29560
|
-
inference_time_ms
|
|
29561
|
-
} = _c, rest = __objRest(_c, [
|
|
29562
|
-
"metadata",
|
|
29563
|
-
"prompt_tokens",
|
|
29564
|
-
"completion_tokens",
|
|
29565
|
-
"reasoning_tokens",
|
|
29566
|
-
"cached_input_tokens",
|
|
29567
|
-
"inference_time_ms"
|
|
29568
|
-
]);
|
|
29569
|
-
let output = rest;
|
|
29570
|
-
v3Logger({
|
|
29571
|
-
category: "extraction",
|
|
29572
|
-
message: completed ? "Extraction completed successfully" : "Extraction incomplete after processing all data",
|
|
29573
|
-
level: 1,
|
|
29574
|
-
auxiliary: {
|
|
29575
|
-
prompt_tokens: { value: String(prompt_tokens), type: "string" },
|
|
29576
|
-
completion_tokens: {
|
|
29577
|
-
value: String(completion_tokens),
|
|
29578
|
-
type: "string"
|
|
29579
|
-
},
|
|
29580
|
-
inference_time_ms: {
|
|
29581
|
-
value: String(inference_time_ms),
|
|
29582
|
-
type: "string"
|
|
29583
|
-
}
|
|
29584
|
-
}
|
|
29554
|
+
const effectiveTimeoutMs = typeof timeout === "number" && timeout > 0 ? timeout : void 0;
|
|
29555
|
+
const ensureTimeRemaining = createTimeoutGuard(
|
|
29556
|
+
effectiveTimeoutMs,
|
|
29557
|
+
(ms) => new ExtractTimeoutError(ms)
|
|
29558
|
+
);
|
|
29559
|
+
const noArgs = !instruction && !schema;
|
|
29560
|
+
if (noArgs) {
|
|
29561
|
+
const focusSelector2 = (_a4 = selector == null ? void 0 : selector.replace(/^xpath=/i, "")) != null ? _a4 : "";
|
|
29562
|
+
ensureTimeRemaining();
|
|
29563
|
+
const snap = yield captureHybridSnapshot(page, {
|
|
29564
|
+
experimental: this.experimental,
|
|
29565
|
+
focusSelector: focusSelector2 || void 0
|
|
29585
29566
|
});
|
|
29586
|
-
|
|
29587
|
-
|
|
29588
|
-
|
|
29589
|
-
|
|
29590
|
-
|
|
29591
|
-
|
|
29592
|
-
cached_input_tokens,
|
|
29593
|
-
inference_time_ms
|
|
29567
|
+
const result = { pageText: snap.combinedTree };
|
|
29568
|
+
return pageTextSchema.parse(result);
|
|
29569
|
+
}
|
|
29570
|
+
if (!instruction && schema) {
|
|
29571
|
+
throw new StagehandInvalidArgumentError(
|
|
29572
|
+
"extract() requires an instruction when a schema is provided."
|
|
29594
29573
|
);
|
|
29595
|
-
|
|
29596
|
-
|
|
29597
|
-
|
|
29598
|
-
|
|
29599
|
-
|
|
29600
|
-
|
|
29601
|
-
);
|
|
29602
|
-
}
|
|
29603
|
-
if (!isObjectSchema && output && typeof output === "object") {
|
|
29604
|
-
output = output[WRAP_KEY];
|
|
29605
|
-
}
|
|
29606
|
-
return output;
|
|
29574
|
+
}
|
|
29575
|
+
const focusSelector = (_b = selector == null ? void 0 : selector.replace(/^xpath=/, "")) != null ? _b : "";
|
|
29576
|
+
ensureTimeRemaining();
|
|
29577
|
+
const { combinedTree, combinedUrlMap } = yield captureHybridSnapshot(page, {
|
|
29578
|
+
experimental: this.experimental,
|
|
29579
|
+
focusSelector
|
|
29607
29580
|
});
|
|
29608
|
-
|
|
29609
|
-
|
|
29610
|
-
|
|
29611
|
-
|
|
29612
|
-
|
|
29613
|
-
|
|
29614
|
-
|
|
29615
|
-
|
|
29616
|
-
|
|
29617
|
-
|
|
29618
|
-
|
|
29581
|
+
v3Logger({
|
|
29582
|
+
category: "extraction",
|
|
29583
|
+
message: "Starting extraction using a11y snapshot",
|
|
29584
|
+
level: 1,
|
|
29585
|
+
auxiliary: instruction ? { instruction: { value: instruction, type: "string" } } : void 0
|
|
29586
|
+
});
|
|
29587
|
+
const baseSchema = schema != null ? schema : defaultExtractSchema;
|
|
29588
|
+
const isObjectSchema = getZodType(baseSchema) === "object";
|
|
29589
|
+
const WRAP_KEY = "value";
|
|
29590
|
+
const factory6 = getZFactory(baseSchema);
|
|
29591
|
+
const objectSchema = isObjectSchema ? baseSchema : factory6.object({
|
|
29592
|
+
[WRAP_KEY]: baseSchema
|
|
29593
|
+
});
|
|
29594
|
+
const [transformedSchema, urlFieldPaths] = transformUrlStringsToNumericIds(objectSchema);
|
|
29595
|
+
ensureTimeRemaining();
|
|
29596
|
+
const extractionResponse = yield extract({
|
|
29597
|
+
instruction,
|
|
29598
|
+
domElements: combinedTree,
|
|
29599
|
+
schema: transformedSchema,
|
|
29600
|
+
llmClient,
|
|
29601
|
+
userProvidedInstructions: this.systemPrompt,
|
|
29602
|
+
logger: v3Logger,
|
|
29603
|
+
logInferenceToFile: this.logInferenceToFile
|
|
29604
|
+
});
|
|
29605
|
+
const _c = extractionResponse, {
|
|
29606
|
+
metadata: { completed },
|
|
29607
|
+
prompt_tokens,
|
|
29608
|
+
completion_tokens,
|
|
29609
|
+
reasoning_tokens = 0,
|
|
29610
|
+
cached_input_tokens = 0,
|
|
29611
|
+
inference_time_ms
|
|
29612
|
+
} = _c, rest = __objRest(_c, [
|
|
29613
|
+
"metadata",
|
|
29614
|
+
"prompt_tokens",
|
|
29615
|
+
"completion_tokens",
|
|
29616
|
+
"reasoning_tokens",
|
|
29617
|
+
"cached_input_tokens",
|
|
29618
|
+
"inference_time_ms"
|
|
29619
29619
|
]);
|
|
29620
|
+
let output = rest;
|
|
29621
|
+
v3Logger({
|
|
29622
|
+
category: "extraction",
|
|
29623
|
+
message: completed ? "Extraction completed successfully" : "Extraction incomplete after processing all data",
|
|
29624
|
+
level: 1,
|
|
29625
|
+
auxiliary: {
|
|
29626
|
+
prompt_tokens: { value: String(prompt_tokens), type: "string" },
|
|
29627
|
+
completion_tokens: { value: String(completion_tokens), type: "string" },
|
|
29628
|
+
inference_time_ms: {
|
|
29629
|
+
value: String(inference_time_ms),
|
|
29630
|
+
type: "string"
|
|
29631
|
+
}
|
|
29632
|
+
}
|
|
29633
|
+
});
|
|
29634
|
+
(_d2 = this.onMetrics) == null ? void 0 : _d2.call(
|
|
29635
|
+
this,
|
|
29636
|
+
"EXTRACT" /* EXTRACT */,
|
|
29637
|
+
prompt_tokens,
|
|
29638
|
+
completion_tokens,
|
|
29639
|
+
reasoning_tokens,
|
|
29640
|
+
cached_input_tokens,
|
|
29641
|
+
inference_time_ms
|
|
29642
|
+
);
|
|
29643
|
+
const idToUrl = combinedUrlMap != null ? combinedUrlMap : {};
|
|
29644
|
+
for (const { segments } of urlFieldPaths) {
|
|
29645
|
+
injectUrls(
|
|
29646
|
+
output,
|
|
29647
|
+
segments,
|
|
29648
|
+
idToUrl
|
|
29649
|
+
);
|
|
29650
|
+
}
|
|
29651
|
+
if (!isObjectSchema && output && typeof output === "object") {
|
|
29652
|
+
output = output[WRAP_KEY];
|
|
29653
|
+
}
|
|
29654
|
+
return output;
|
|
29620
29655
|
});
|
|
29621
29656
|
}
|
|
29622
29657
|
};
|
|
@@ -29624,6 +29659,7 @@ var ExtractHandler = class {
|
|
|
29624
29659
|
// lib/v3/handlers/observeHandler.ts
|
|
29625
29660
|
init_logger();
|
|
29626
29661
|
init_snapshot();
|
|
29662
|
+
init_sdkErrors();
|
|
29627
29663
|
var ObserveHandler = class {
|
|
29628
29664
|
constructor(llmClient, defaultModelName, defaultClientOptions, resolveLlmClient, systemPrompt, logInferenceToFile, experimental, onMetrics) {
|
|
29629
29665
|
this.llmClient = llmClient;
|
|
@@ -29637,102 +29673,96 @@ var ObserveHandler = class {
|
|
|
29637
29673
|
}
|
|
29638
29674
|
observe(params) {
|
|
29639
29675
|
return __async(this, null, function* () {
|
|
29676
|
+
var _a4, _b, _c;
|
|
29640
29677
|
const { instruction, page, timeout, selector, model } = params;
|
|
29641
29678
|
const llmClient = this.resolveLlmClient(model);
|
|
29679
|
+
const effectiveTimeoutMs = typeof timeout === "number" && timeout > 0 ? timeout : void 0;
|
|
29680
|
+
const ensureTimeRemaining = createTimeoutGuard(
|
|
29681
|
+
effectiveTimeoutMs,
|
|
29682
|
+
(ms) => new ObserveTimeoutError(ms)
|
|
29683
|
+
);
|
|
29642
29684
|
const effectiveInstruction = instruction != null ? instruction : "Find elements that can be used for any future actions in the page. These may be navigation links, related pages, section/subsection links, buttons, or other interactive elements. Be comprehensive: if there are multiple elements that may be relevant for future actions, return all of them.";
|
|
29643
|
-
|
|
29644
|
-
|
|
29645
|
-
|
|
29646
|
-
|
|
29647
|
-
|
|
29648
|
-
|
|
29649
|
-
|
|
29650
|
-
|
|
29651
|
-
value: effectiveInstruction,
|
|
29652
|
-
type: "string"
|
|
29653
|
-
}
|
|
29685
|
+
v3Logger({
|
|
29686
|
+
category: "observation",
|
|
29687
|
+
message: "starting observation",
|
|
29688
|
+
level: 1,
|
|
29689
|
+
auxiliary: {
|
|
29690
|
+
instruction: {
|
|
29691
|
+
value: effectiveInstruction,
|
|
29692
|
+
type: "string"
|
|
29654
29693
|
}
|
|
29655
|
-
}
|
|
29656
|
-
|
|
29657
|
-
|
|
29658
|
-
|
|
29659
|
-
|
|
29660
|
-
|
|
29661
|
-
|
|
29662
|
-
|
|
29663
|
-
|
|
29664
|
-
|
|
29665
|
-
|
|
29666
|
-
|
|
29667
|
-
|
|
29668
|
-
|
|
29669
|
-
|
|
29670
|
-
|
|
29671
|
-
|
|
29672
|
-
|
|
29673
|
-
|
|
29674
|
-
|
|
29675
|
-
|
|
29676
|
-
|
|
29677
|
-
|
|
29678
|
-
|
|
29679
|
-
|
|
29680
|
-
|
|
29681
|
-
|
|
29682
|
-
|
|
29683
|
-
|
|
29684
|
-
|
|
29685
|
-
|
|
29686
|
-
|
|
29687
|
-
|
|
29688
|
-
|
|
29689
|
-
|
|
29690
|
-
|
|
29691
|
-
|
|
29692
|
-
|
|
29693
|
-
|
|
29694
|
-
|
|
29695
|
-
|
|
29696
|
-
|
|
29697
|
-
|
|
29698
|
-
|
|
29699
|
-
|
|
29700
|
-
|
|
29701
|
-
|
|
29702
|
-
|
|
29703
|
-
|
|
29704
|
-
|
|
29705
|
-
|
|
29706
|
-
description: "an element inside a shadow DOM",
|
|
29707
|
-
method: "not-supported",
|
|
29708
|
-
arguments: [],
|
|
29709
|
-
selector: "not-supported"
|
|
29710
|
-
};
|
|
29711
|
-
}))
|
|
29712
|
-
)).filter((e2) => e2 !== void 0);
|
|
29713
|
-
v3Logger({
|
|
29714
|
-
category: "observation",
|
|
29715
|
-
message: "found elements",
|
|
29716
|
-
level: 1,
|
|
29717
|
-
auxiliary: {
|
|
29718
|
-
elements: {
|
|
29719
|
-
value: JSON.stringify(elementsWithSelectors),
|
|
29720
|
-
type: "object"
|
|
29721
|
-
}
|
|
29694
|
+
}
|
|
29695
|
+
});
|
|
29696
|
+
const focusSelector = (_a4 = selector == null ? void 0 : selector.replace(/^xpath=/i, "")) != null ? _a4 : "";
|
|
29697
|
+
ensureTimeRemaining();
|
|
29698
|
+
const snapshot = yield captureHybridSnapshot(page, {
|
|
29699
|
+
experimental: this.experimental,
|
|
29700
|
+
focusSelector: focusSelector || void 0
|
|
29701
|
+
});
|
|
29702
|
+
const combinedTree = snapshot.combinedTree;
|
|
29703
|
+
const combinedXpathMap = (_b = snapshot.combinedXpathMap) != null ? _b : {};
|
|
29704
|
+
v3Logger({
|
|
29705
|
+
category: "observation",
|
|
29706
|
+
message: "Got accessibility tree data",
|
|
29707
|
+
level: 1
|
|
29708
|
+
});
|
|
29709
|
+
ensureTimeRemaining();
|
|
29710
|
+
const observationResponse = yield observe({
|
|
29711
|
+
instruction: effectiveInstruction,
|
|
29712
|
+
domElements: combinedTree,
|
|
29713
|
+
llmClient,
|
|
29714
|
+
userProvidedInstructions: this.systemPrompt,
|
|
29715
|
+
logger: v3Logger,
|
|
29716
|
+
logInferenceToFile: this.logInferenceToFile
|
|
29717
|
+
});
|
|
29718
|
+
const {
|
|
29719
|
+
prompt_tokens = 0,
|
|
29720
|
+
completion_tokens = 0,
|
|
29721
|
+
reasoning_tokens = 0,
|
|
29722
|
+
cached_input_tokens = 0,
|
|
29723
|
+
inference_time_ms = 0
|
|
29724
|
+
} = observationResponse;
|
|
29725
|
+
(_c = this.onMetrics) == null ? void 0 : _c.call(
|
|
29726
|
+
this,
|
|
29727
|
+
"OBSERVE" /* OBSERVE */,
|
|
29728
|
+
prompt_tokens,
|
|
29729
|
+
completion_tokens,
|
|
29730
|
+
reasoning_tokens,
|
|
29731
|
+
cached_input_tokens,
|
|
29732
|
+
inference_time_ms
|
|
29733
|
+
);
|
|
29734
|
+
const elementsWithSelectors = (yield Promise.all(
|
|
29735
|
+
observationResponse.elements.map((element) => __async(this, null, function* () {
|
|
29736
|
+
const _a5 = element, { elementId } = _a5, rest = __objRest(_a5, ["elementId"]);
|
|
29737
|
+
if (typeof elementId === "string" && elementId.includes("-")) {
|
|
29738
|
+
const lookUpIndex = elementId;
|
|
29739
|
+
const xpath = combinedXpathMap[lookUpIndex];
|
|
29740
|
+
const trimmedXpath = trimTrailingTextNode(xpath);
|
|
29741
|
+
if (!trimmedXpath) return void 0;
|
|
29742
|
+
return __spreadProps(__spreadValues({}, rest), {
|
|
29743
|
+
selector: `xpath=${trimmedXpath}`
|
|
29744
|
+
});
|
|
29722
29745
|
}
|
|
29723
|
-
|
|
29724
|
-
|
|
29746
|
+
return {
|
|
29747
|
+
description: "an element inside a shadow DOM",
|
|
29748
|
+
method: "not-supported",
|
|
29749
|
+
arguments: [],
|
|
29750
|
+
selector: "not-supported"
|
|
29751
|
+
};
|
|
29752
|
+
}))
|
|
29753
|
+
)).filter((e2) => e2 !== void 0);
|
|
29754
|
+
v3Logger({
|
|
29755
|
+
category: "observation",
|
|
29756
|
+
message: "found elements",
|
|
29757
|
+
level: 1,
|
|
29758
|
+
auxiliary: {
|
|
29759
|
+
elements: {
|
|
29760
|
+
value: JSON.stringify(elementsWithSelectors),
|
|
29761
|
+
type: "object"
|
|
29762
|
+
}
|
|
29763
|
+
}
|
|
29725
29764
|
});
|
|
29726
|
-
|
|
29727
|
-
return yield Promise.race([
|
|
29728
|
-
doObserve(),
|
|
29729
|
-
new Promise((_, reject) => {
|
|
29730
|
-
setTimeout(
|
|
29731
|
-
() => reject(new Error(`observe() timed out after ${timeout}ms`)),
|
|
29732
|
-
timeout
|
|
29733
|
-
);
|
|
29734
|
-
})
|
|
29735
|
-
]);
|
|
29765
|
+
return elementsWithSelectors;
|
|
29736
29766
|
});
|
|
29737
29767
|
}
|
|
29738
29768
|
};
|
|
@@ -63087,6 +63117,7 @@ var StagehandAPIClient = class {
|
|
|
63087
63117
|
};
|
|
63088
63118
|
|
|
63089
63119
|
// lib/v3/v3.ts
|
|
63120
|
+
init_sdkErrors();
|
|
63090
63121
|
var DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
|
|
63091
63122
|
var DEFAULT_VIEWPORT = { width: 1288, height: 711 };
|
|
63092
63123
|
function resolveModelConfiguration(model) {
|
|
@@ -63792,13 +63823,17 @@ var _V3 = class _V3 {
|
|
|
63792
63823
|
frameId: v3Page.mainFrameId()
|
|
63793
63824
|
});
|
|
63794
63825
|
} else {
|
|
63826
|
+
const effectiveTimeoutMs = typeof (options == null ? void 0 : options.timeout) === "number" && options.timeout > 0 ? options.timeout : void 0;
|
|
63827
|
+
const ensureTimeRemaining = createTimeoutGuard(
|
|
63828
|
+
effectiveTimeoutMs,
|
|
63829
|
+
(ms) => new ActTimeoutError(ms)
|
|
63830
|
+
);
|
|
63795
63831
|
actResult = yield this.actHandler.takeDeterministicAction(
|
|
63796
63832
|
__spreadProps(__spreadValues({}, input), { selector }),
|
|
63797
|
-
// ObserveResult
|
|
63798
63833
|
v3Page,
|
|
63799
|
-
// V3 Page
|
|
63800
63834
|
this.domSettleTimeoutMs,
|
|
63801
|
-
this.resolveLlmClient(options == null ? void 0 : options.model)
|
|
63835
|
+
this.resolveLlmClient(options == null ? void 0 : options.model),
|
|
63836
|
+
ensureTimeRemaining
|
|
63802
63837
|
);
|
|
63803
63838
|
}
|
|
63804
63839
|
this.addToHistory(
|
|
@@ -64659,6 +64694,7 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
64659
64694
|
0 && (module.exports = {
|
|
64660
64695
|
AISdkClient,
|
|
64661
64696
|
AVAILABLE_CUA_MODELS,
|
|
64697
|
+
ActTimeoutError,
|
|
64662
64698
|
AgentProvider,
|
|
64663
64699
|
AgentScreenshotProviderError,
|
|
64664
64700
|
AnnotatedScreenshotText,
|
|
@@ -64672,6 +64708,7 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
64672
64708
|
ElementNotVisibleError,
|
|
64673
64709
|
ExperimentalApiConflictError,
|
|
64674
64710
|
ExperimentalNotConfiguredError,
|
|
64711
|
+
ExtractTimeoutError,
|
|
64675
64712
|
HandlerNotInitializedError,
|
|
64676
64713
|
InvalidAISDKModelFormatError,
|
|
64677
64714
|
LLMClient,
|
|
@@ -64680,6 +64717,7 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
64680
64717
|
MCPConnectionError,
|
|
64681
64718
|
MissingEnvironmentVariableError,
|
|
64682
64719
|
MissingLLMConfigurationError,
|
|
64720
|
+
ObserveTimeoutError,
|
|
64683
64721
|
PageNotFoundError,
|
|
64684
64722
|
Response,
|
|
64685
64723
|
ResponseBodyError,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserbasehq/stagehand",
|
|
3
|
-
"version": "3.0.6-alpha-
|
|
3
|
+
"version": "3.0.6-alpha-1ebc7e1be4d3129dbba48b0a05b5ac006d3387eb",
|
|
4
4
|
"description": "An AI web browsing framework focused on simplicity and extensibility.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -96,6 +96,6 @@
|
|
|
96
96
|
"e2e:bb": "playwright test --config=lib/v3/tests/v3.bb.playwright.config.ts",
|
|
97
97
|
"lint": "cd ../.. && prettier --check packages/core && cd packages/core && eslint .",
|
|
98
98
|
"format": "prettier --write .",
|
|
99
|
-
"test:vitest": "
|
|
99
|
+
"test:vitest": "turbo run build && vitest run --config vitest.config.ts"
|
|
100
100
|
}
|
|
101
101
|
}
|