@crawlee/stagehand 3.17.1-beta.53 → 3.17.1-beta.55

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/index.mjs CHANGED
@@ -50,6 +50,7 @@ export const RequestQueue = mod.RequestQueue;
50
50
  export const RequestQueueV1 = mod.RequestQueueV1;
51
51
  export const RequestQueueV2 = mod.RequestQueueV2;
52
52
  export const RequestState = mod.RequestState;
53
+ export const RequestValidationError = mod.RequestValidationError;
53
54
  export const RetryRequestError = mod.RetryRequestError;
54
55
  export const Router = mod.Router;
55
56
  export const STATE_PERSISTENCE_KEY = mod.STATE_PERSISTENCE_KEY;
@@ -81,6 +82,7 @@ export const createEventLoopLoadSignal = mod.createEventLoopLoadSignal;
81
82
  export const createRequestOptions = mod.createRequestOptions;
82
83
  export const createRequests = mod.createRequests;
83
84
  export const createStagehandRouter = mod.createStagehandRouter;
85
+ export const defaultRoute = mod.defaultRoute;
84
86
  export const deserializeArray = mod.deserializeArray;
85
87
  export const enqueueLinks = mod.enqueueLinks;
86
88
  export const evaluateLoadSignalSample = mod.evaluateLoadSignalSample;
@@ -103,5 +105,6 @@ export const tryAbsoluteURL = mod.tryAbsoluteURL;
103
105
  export const updateEnqueueLinksPatternCache = mod.updateEnqueueLinksPatternCache;
104
106
  export const useState = mod.useState;
105
107
  export const validateGlobPattern = mod.validateGlobPattern;
108
+ export const validateUserData = mod.validateUserData;
106
109
  export const validators = mod.validators;
107
110
  export const withCheckedStorageAccess = mod.withCheckedStorageAccess;
@@ -1,5 +1,5 @@
1
1
  import type { Action, ActOptions, ActResult, AgentConfig, ExtractOptions, LLMClient, ModelConfiguration, NonStreamingAgentInstance, ObserveOptions, Stagehand, StreamingAgentInstance } from '@browserbasehq/stagehand';
2
- import type { BrowserCrawlerOptions, BrowserCrawlingContext, BrowserHook, BrowserRequestHandler, GetUserDataFromRequest, LoadedContext, RouterHandler, RouterRoutes } from '@crawlee/browser';
2
+ import type { BrowserCrawlerOptions, BrowserCrawlingContext, BrowserHook, BrowserRequestHandler, GetUserDataFromRequest, LoadedContext, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/browser';
3
3
  import { BrowserCrawler, Configuration } from '@crawlee/browser';
4
4
  import type { Dictionary } from '@crawlee/types';
5
5
  // @ts-ignore optional peer dependency or compatibility with es2022
@@ -408,6 +408,9 @@ export declare class StagehandCrawler extends BrowserCrawler<{
408
408
  // @ts-ignore optional peer dependency or compatibility with es2022
409
409
  statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
410
410
  };
411
+ /** Set while `_runRequestHandler` has swapped `userProvidedRequestHandler` for its page-enhancing wrapper. */
412
+ private unwrappedRequestHandler?;
413
+ protected get userRequestHandler(): BrowserRequestHandler<StagehandCrawlingContext>;
411
414
  /**
412
415
  * Creates a new instance of StagehandCrawler.
413
416
  *
@@ -460,3 +463,4 @@ export declare class StagehandCrawler extends BrowserCrawler<{
460
463
  */
461
464
  export declare function createStagehandRouter<Context extends StagehandCrawlingContext = StagehandCrawlingContext, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>>(routes?: RouterRoutes<Context, Routes>): RouterHandler<Context, Routes>;
462
465
  export declare function createStagehandRouter<Context extends StagehandCrawlingContext = StagehandCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, Record<string, UserData>>): RouterHandler<Context, Record<string, UserData>>;
466
+ export declare function createStagehandRouter<Context extends StagehandCrawlingContext = StagehandCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
@@ -57,6 +57,9 @@ const stagehand_utils_1 = require("./utils/stagehand-utils");
57
57
  * ```
58
58
  */
59
59
  class StagehandCrawler extends browser_1.BrowserCrawler {
60
+ get userRequestHandler() {
61
+ return this.unwrappedRequestHandler ?? super.userRequestHandler;
62
+ }
60
63
  /**
61
64
  * Creates a new instance of StagehandCrawler.
62
65
  *
@@ -88,6 +91,13 @@ class StagehandCrawler extends browser_1.BrowserCrawler {
88
91
  writable: true,
89
92
  value: config
90
93
  });
94
+ /** Set while `_runRequestHandler` has swapped `userProvidedRequestHandler` for its page-enhancing wrapper. */
95
+ Object.defineProperty(this, "unwrappedRequestHandler", {
96
+ enumerable: true,
97
+ configurable: true,
98
+ writable: true,
99
+ value: void 0
100
+ });
91
101
  }
92
102
  /**
93
103
  * Overrides the request handler to enhance the page with Stagehand AI methods.
@@ -105,6 +115,9 @@ class StagehandCrawler extends browser_1.BrowserCrawler {
105
115
  async _runRequestHandler(crawlingContext) {
106
116
  // Store the original handler (could be this.requestHandler or this.router)
107
117
  const originalHandler = this.userProvidedRequestHandler;
118
+ // Keep `userRequestHandler` pointing at the unwrapped handler: the swap below is live while the user's
119
+ // handler runs, which is exactly when `context.addRequests`/`enqueueLinks` resolve router metadata.
120
+ this.unwrappedRequestHandler = originalHandler;
108
121
  // Replace with a wrapper that enhances the page before calling the user's handler
109
122
  this.userProvidedRequestHandler = async (ctx) => {
110
123
  // Get Stagehand instance from controller
@@ -122,6 +135,7 @@ class StagehandCrawler extends browser_1.BrowserCrawler {
122
135
  finally {
123
136
  // Restore original handler
124
137
  this.userProvidedRequestHandler = originalHandler;
138
+ this.unwrappedRequestHandler = undefined;
125
139
  }
126
140
  }
127
141
  /**
@@ -144,6 +158,6 @@ Object.defineProperty(StagehandCrawler, "optionsShape", {
144
158
  browserPoolOptions: ow_1.default.optional.object,
145
159
  }
146
160
  });
147
- function createStagehandRouter(routes) {
148
- return browser_1.Router.create(routes);
161
+ function createStagehandRouter(routesOrSchemas) {
162
+ return browser_1.Router.create(routesOrSchemas);
149
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/stagehand",
3
- "version": "3.17.1-beta.53",
3
+ "version": "3.17.1-beta.55",
4
4
  "description": "AI-powered web crawling with Stagehand integration for Crawlee - enables natural language browser automation with act(), extract(), and observe() methods.",
5
5
  "engines": {
6
6
  "node": ">=16.0.0"
@@ -58,11 +58,11 @@
58
58
  "dependencies": {
59
59
  "@apify/log": "^2.4.0",
60
60
  "@apify/timeout": "^0.3.1",
61
- "@crawlee/browser": "3.17.1-beta.53",
62
- "@crawlee/browser-pool": "3.17.1-beta.53",
63
- "@crawlee/core": "3.17.1-beta.53",
64
- "@crawlee/types": "3.17.1-beta.53",
65
- "@crawlee/utils": "3.17.1-beta.53",
61
+ "@crawlee/browser": "3.17.1-beta.55",
62
+ "@crawlee/browser-pool": "3.17.1-beta.55",
63
+ "@crawlee/core": "3.17.1-beta.55",
64
+ "@crawlee/types": "3.17.1-beta.55",
65
+ "@crawlee/utils": "3.17.1-beta.55",
66
66
  "ow": "^0.28.1",
67
67
  "tslib": "^2.4.0"
68
68
  },
@@ -94,5 +94,5 @@
94
94
  }
95
95
  }
96
96
  },
97
- "gitHead": "59a0d19d96e7402cd8d0edd8b90ad4f5abc8f7db"
97
+ "gitHead": "93d29e305f01ca6ca9bb79264a5ca553b19766ef"
98
98
  }