@browserbasehq/stagehand 2.0.0 → 2.0.1-alpha-98d63e380ebdd9f49a0a36fb0873cab896819e80

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 CHANGED
@@ -603,7 +603,7 @@ declare class StagehandAPI {
603
603
  private logger;
604
604
  constructor({ apiKey, projectId, logger }: StagehandAPIConstructorParams);
605
605
  init({ modelName, modelApiKey, domSettleTimeoutMs, verbose, debugDom, systemPrompt, selfHeal, waitForCaptchaSolves, actionTimeoutMs, browserbaseSessionCreateParams, browserbaseSessionID, }: StartSessionParams): Promise<StartSessionResult>;
606
- act(options: ActOptions): Promise<ActResult>;
606
+ act(options: ActOptions | ObserveResult): Promise<ActResult>;
607
607
  extract<T extends z.AnyZodObject>(options: ExtractOptions<T>): Promise<ExtractResult<T>>;
608
608
  observe(options?: ObserveOptions): Promise<ObserveResult[]>;
609
609
  goto(url: string, options?: GotoOptions): Promise<void>;
@@ -707,6 +707,86 @@ declare const operatorSummarySchema: z.ZodObject<{
707
707
  }>;
708
708
  type OperatorSummary = z.infer<typeof operatorSummarySchema>;
709
709
 
710
+ declare class StagehandError extends Error {
711
+ constructor(message: string);
712
+ }
713
+ declare class StagehandDefaultError extends StagehandError {
714
+ constructor();
715
+ }
716
+ declare class StagehandEnvironmentError extends StagehandError {
717
+ constructor(currentEnvironment: string, requiredEnvironment: string, feature: string);
718
+ }
719
+ declare class MissingEnvironmentVariableError extends StagehandError {
720
+ constructor(missingEnvironmentVariable: string, feature: string);
721
+ }
722
+ declare class UnsupportedModelError extends StagehandError {
723
+ constructor(supportedModels: string[], feature?: string);
724
+ }
725
+ declare class UnsupportedModelProviderError extends StagehandError {
726
+ constructor(supportedProviders: string[], feature?: string);
727
+ }
728
+ declare class StagehandNotInitializedError extends StagehandError {
729
+ constructor(prop: string);
730
+ }
731
+ declare class BrowserbaseSessionNotFoundError extends StagehandError {
732
+ constructor();
733
+ }
734
+ declare class CaptchaTimeoutError extends StagehandError {
735
+ constructor();
736
+ }
737
+ declare class MissingLLMConfigurationError extends StagehandError {
738
+ constructor();
739
+ }
740
+ declare class HandlerNotInitializedError extends StagehandError {
741
+ constructor(handlerType: string);
742
+ }
743
+ declare class StagehandNotImplementedError extends StagehandError {
744
+ constructor(message: string);
745
+ }
746
+ declare class StagehandDeprecationError extends StagehandError {
747
+ constructor(message: string);
748
+ }
749
+ declare class StagehandInvalidArgumentError extends StagehandError {
750
+ constructor(message: string);
751
+ }
752
+ declare class StagehandElementNotFoundError extends StagehandError {
753
+ constructor(xpaths: string[]);
754
+ }
755
+ declare class AgentScreenshotProviderError extends StagehandError {
756
+ constructor(message: string);
757
+ }
758
+ declare class StagehandMissingArgumentError extends StagehandError {
759
+ constructor(message: string);
760
+ }
761
+ declare class CreateChatCompletionResponseError extends StagehandError {
762
+ constructor(message: string);
763
+ }
764
+ declare class StagehandEvalError extends StagehandError {
765
+ constructor(message: string);
766
+ }
767
+ declare class StagehandDomProcessError extends StagehandError {
768
+ constructor(message: string);
769
+ }
770
+
771
+ declare class StagehandAPIError extends Error {
772
+ constructor(message: string);
773
+ }
774
+ declare class StagehandAPIUnauthorizedError extends StagehandAPIError {
775
+ constructor(message?: string);
776
+ }
777
+ declare class StagehandHttpError extends StagehandAPIError {
778
+ constructor(message: string);
779
+ }
780
+ declare class StagehandServerError extends StagehandAPIError {
781
+ constructor(message: string);
782
+ }
783
+ declare class StagehandResponseBodyError extends StagehandAPIError {
784
+ constructor();
785
+ }
786
+ declare class StagehandResponseParseError extends StagehandAPIError {
787
+ constructor(message: string);
788
+ }
789
+
710
790
  declare class Stagehand {
711
791
  private stagehandPage;
712
792
  private stagehandContext;
@@ -773,4 +853,4 @@ declare class Stagehand {
773
853
  get history(): ReadonlyArray<HistoryEntry>;
774
854
  }
775
855
 
776
- export { type ActOptions, type ActResult, type ActionExecutionResult, type AgentAction, type AgentClientOptions, type AgentConfig, type AgentExecuteOptions, type AgentExecuteParams, type AgentExecutionOptions, type AgentHandlerOptions, type AgentOptions, type AgentProviderType, type AgentResult, type AgentType, AnnotatedScreenshotText, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AvailableModel, AvailableModelSchema, type Browser, type BrowserContext, type BrowserResult, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, type ConstructorParams, type CreateChatCompletionOptions, type ExtractOptions, type ExtractResult, type FunctionCallItem, type GotoOptions, type HistoryEntry, type InitResult, LLMClient, type LLMResponse, LOG_LEVEL_NAMES, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, type ModelProvider, type ObserveOptions, type ObserveResult, type OperatorResponse, type OperatorSummary, type Page, PlaywrightCommandException, PlaywrightCommandMethodNotSupportedException, type ResponseInputItem, type ResponseItem, Stagehand, StagehandFunctionName, type StagehandMetrics, type ToolUseItem, defaultExtractSchema, operatorResponseSchema, operatorSummarySchema, pageTextSchema };
856
+ export { type ActOptions, type ActResult, type ActionExecutionResult, type AgentAction, type AgentClientOptions, type AgentConfig, type AgentExecuteOptions, type AgentExecuteParams, type AgentExecutionOptions, type AgentHandlerOptions, type AgentOptions, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentType, AnnotatedScreenshotText, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AvailableModel, AvailableModelSchema, type Browser, type BrowserContext, type BrowserResult, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, type ConstructorParams, type CreateChatCompletionOptions, CreateChatCompletionResponseError, type ExtractOptions, type ExtractResult, type FunctionCallItem, type GotoOptions, HandlerNotInitializedError, type HistoryEntry, type InitResult, LLMClient, type LLMResponse, LOG_LEVEL_NAMES, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelProvider, type ObserveOptions, type ObserveResult, type OperatorResponse, type OperatorSummary, type Page, PlaywrightCommandException, PlaywrightCommandMethodNotSupportedException, type ResponseInputItem, type ResponseItem, Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandDefaultError, StagehandDeprecationError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandFunctionName, StagehandHttpError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotImplementedError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, type ToolUseItem, UnsupportedModelError, UnsupportedModelProviderError, defaultExtractSchema, operatorResponseSchema, operatorSummarySchema, pageTextSchema };
package/dist/index.js CHANGED
@@ -80,14 +80,40 @@ var __async = (__this, __arguments, generator) => {
80
80
  // lib/index.ts
81
81
  var index_exports = {};
82
82
  __export(index_exports, {
83
+ AgentScreenshotProviderError: () => AgentScreenshotProviderError,
83
84
  AnnotatedScreenshotText: () => AnnotatedScreenshotText,
84
85
  AvailableModelSchema: () => AvailableModelSchema,
86
+ BrowserbaseSessionNotFoundError: () => BrowserbaseSessionNotFoundError,
87
+ CaptchaTimeoutError: () => CaptchaTimeoutError,
88
+ CreateChatCompletionResponseError: () => CreateChatCompletionResponseError,
89
+ HandlerNotInitializedError: () => HandlerNotInitializedError,
85
90
  LLMClient: () => LLMClient,
86
91
  LOG_LEVEL_NAMES: () => LOG_LEVEL_NAMES,
92
+ MissingEnvironmentVariableError: () => MissingEnvironmentVariableError,
93
+ MissingLLMConfigurationError: () => MissingLLMConfigurationError,
87
94
  PlaywrightCommandException: () => PlaywrightCommandException,
88
95
  PlaywrightCommandMethodNotSupportedException: () => PlaywrightCommandMethodNotSupportedException,
89
96
  Stagehand: () => Stagehand3,
97
+ StagehandAPIError: () => StagehandAPIError,
98
+ StagehandAPIUnauthorizedError: () => StagehandAPIUnauthorizedError,
99
+ StagehandDefaultError: () => StagehandDefaultError,
100
+ StagehandDeprecationError: () => StagehandDeprecationError,
101
+ StagehandDomProcessError: () => StagehandDomProcessError,
102
+ StagehandElementNotFoundError: () => StagehandElementNotFoundError,
103
+ StagehandEnvironmentError: () => StagehandEnvironmentError,
104
+ StagehandError: () => StagehandError,
105
+ StagehandEvalError: () => StagehandEvalError,
90
106
  StagehandFunctionName: () => StagehandFunctionName,
107
+ StagehandHttpError: () => StagehandHttpError,
108
+ StagehandInvalidArgumentError: () => StagehandInvalidArgumentError,
109
+ StagehandMissingArgumentError: () => StagehandMissingArgumentError,
110
+ StagehandNotImplementedError: () => StagehandNotImplementedError,
111
+ StagehandNotInitializedError: () => StagehandNotInitializedError,
112
+ StagehandResponseBodyError: () => StagehandResponseBodyError,
113
+ StagehandResponseParseError: () => StagehandResponseParseError,
114
+ StagehandServerError: () => StagehandServerError,
115
+ UnsupportedModelError: () => UnsupportedModelError,
116
+ UnsupportedModelProviderError: () => UnsupportedModelProviderError,
91
117
  defaultExtractSchema: () => defaultExtractSchema,
92
118
  operatorResponseSchema: () => operatorResponseSchema,
93
119
  operatorSummarySchema: () => operatorSummarySchema,
@@ -391,11 +417,21 @@ var StagehandNotImplementedError = class extends StagehandError {
391
417
  super(`NotImplementedError: ${message}`);
392
418
  }
393
419
  };
420
+ var StagehandDeprecationError = class extends StagehandError {
421
+ constructor(message) {
422
+ super(`DeprecationError: ${message}`);
423
+ }
424
+ };
394
425
  var StagehandInvalidArgumentError = class extends StagehandError {
395
426
  constructor(message) {
396
427
  super(`InvalidArgumentError: ${message}`);
397
428
  }
398
429
  };
430
+ var StagehandElementNotFoundError = class extends StagehandError {
431
+ constructor(xpaths) {
432
+ super(`Could not find an element for the given xPath(s): ${xpaths}`);
433
+ }
434
+ };
399
435
  var AgentScreenshotProviderError = class extends StagehandError {
400
436
  constructor(message) {
401
437
  super(`ScreenshotProviderError: ${message}`);
@@ -411,6 +447,16 @@ var CreateChatCompletionResponseError = class extends StagehandError {
411
447
  super(`CreateChatCompletionResponseError: ${message}`);
412
448
  }
413
449
  };
450
+ var StagehandEvalError = class extends StagehandError {
451
+ constructor(message) {
452
+ super(`StagehandEvalError: ${message}`);
453
+ }
454
+ };
455
+ var StagehandDomProcessError = class extends StagehandError {
456
+ constructor(message) {
457
+ super(`Error Processing Dom: ${message}`);
458
+ }
459
+ };
414
460
 
415
461
  // lib/dom/utils.ts
416
462
  function getNodeFromXpath(xpath) {
@@ -3116,6 +3162,12 @@ var StagehandPage = class _StagehandPage {
3116
3162
  if (typeof actionOrOptions === "object" && actionOrOptions !== null) {
3117
3163
  if ("selector" in actionOrOptions && "method" in actionOrOptions) {
3118
3164
  const observeResult = actionOrOptions;
3165
+ if (this.api) {
3166
+ const result2 = yield this.api.act(observeResult);
3167
+ yield this._refreshPageFromAPI();
3168
+ this.addToHistory("act", observeResult, result2);
3169
+ return result2;
3170
+ }
3119
3171
  return this.actHandler.actFromObserveResult(observeResult);
3120
3172
  } else {
3121
3173
  if (!("action" in actionOrOptions)) {
@@ -8269,14 +8321,40 @@ var Stagehand3 = class {
8269
8321
  };
8270
8322
  // Annotate the CommonJS export names for ESM import in node:
8271
8323
  0 && (module.exports = {
8324
+ AgentScreenshotProviderError,
8272
8325
  AnnotatedScreenshotText,
8273
8326
  AvailableModelSchema,
8327
+ BrowserbaseSessionNotFoundError,
8328
+ CaptchaTimeoutError,
8329
+ CreateChatCompletionResponseError,
8330
+ HandlerNotInitializedError,
8274
8331
  LLMClient,
8275
8332
  LOG_LEVEL_NAMES,
8333
+ MissingEnvironmentVariableError,
8334
+ MissingLLMConfigurationError,
8276
8335
  PlaywrightCommandException,
8277
8336
  PlaywrightCommandMethodNotSupportedException,
8278
8337
  Stagehand,
8338
+ StagehandAPIError,
8339
+ StagehandAPIUnauthorizedError,
8340
+ StagehandDefaultError,
8341
+ StagehandDeprecationError,
8342
+ StagehandDomProcessError,
8343
+ StagehandElementNotFoundError,
8344
+ StagehandEnvironmentError,
8345
+ StagehandError,
8346
+ StagehandEvalError,
8279
8347
  StagehandFunctionName,
8348
+ StagehandHttpError,
8349
+ StagehandInvalidArgumentError,
8350
+ StagehandMissingArgumentError,
8351
+ StagehandNotImplementedError,
8352
+ StagehandNotInitializedError,
8353
+ StagehandResponseBodyError,
8354
+ StagehandResponseParseError,
8355
+ StagehandServerError,
8356
+ UnsupportedModelError,
8357
+ UnsupportedModelProviderError,
8280
8358
  defaultExtractSchema,
8281
8359
  operatorResponseSchema,
8282
8360
  operatorSummarySchema,
package/dist/lib/api.d.ts CHANGED
@@ -11,7 +11,7 @@ export declare class StagehandAPI {
11
11
  private logger;
12
12
  constructor({ apiKey, projectId, logger }: StagehandAPIConstructorParams);
13
13
  init({ modelName, modelApiKey, domSettleTimeoutMs, verbose, debugDom, systemPrompt, selfHeal, waitForCaptchaSolves, actionTimeoutMs, browserbaseSessionCreateParams, browserbaseSessionID, }: StartSessionParams): Promise<StartSessionResult>;
14
- act(options: ActOptions): Promise<ActResult>;
14
+ act(options: ActOptions | ObserveResult): Promise<ActResult>;
15
15
  extract<T extends z.AnyZodObject>(options: ExtractOptions<T>): Promise<ExtractResult<T>>;
16
16
  observe(options?: ObserveOptions): Promise<ObserveResult[]>;
17
17
  goto(url: string, options?: GotoOptions): Promise<void>;
@@ -82,3 +82,5 @@ export * from "../types/stagehand";
82
82
  export * from "../types/operator";
83
83
  export * from "../types/agent";
84
84
  export * from "./llm/LLMClient";
85
+ export * from "../types/stagehandErrors";
86
+ export * from "../types/stagehandApiErrors";
@@ -491,6 +491,14 @@ export class StagehandPage {
491
491
  // If it has selector AND method => treat as ObserveResult
492
492
  if ("selector" in actionOrOptions && "method" in actionOrOptions) {
493
493
  const observeResult = actionOrOptions as ObserveResult;
494
+
495
+ if (this.api) {
496
+ const result = await this.api.act(observeResult);
497
+ await this._refreshPageFromAPI();
498
+ this.addToHistory("act", observeResult, result);
499
+ return result;
500
+ }
501
+
494
502
  // validate observeResult.method, etc.
495
503
  return this.actHandler.actFromObserveResult(observeResult);
496
504
  } else {
package/lib/api.ts CHANGED
@@ -95,7 +95,7 @@ export class StagehandAPI {
95
95
  return sessionResponseBody.data;
96
96
  }
97
97
 
98
- async act(options: ActOptions): Promise<ActResult> {
98
+ async act(options: ActOptions | ObserveResult): Promise<ActResult> {
99
99
  return this.execute<ActResult>({
100
100
  method: "act",
101
101
  args: { ...options },
package/lib/index.ts CHANGED
@@ -918,3 +918,5 @@ export * from "../types/stagehand";
918
918
  export * from "../types/operator";
919
919
  export * from "../types/agent";
920
920
  export * from "./llm/LLMClient";
921
+ export * from "../types/stagehandErrors";
922
+ export * from "../types/stagehandApiErrors";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-alpha-98d63e380ebdd9f49a0a36fb0873cab896819e80",
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",