@browserbasehq/stagehand 1.8.0 → 1.8.1-alpha-5c6f14bade201e08cb86d2e14e246cb65707f7ee
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 +6 -8
- package/dist/index.js +10 -9
- package/dist/lib/index.d.ts +2 -5
- package/dist/types/page.d.ts +2 -0
- package/dist/types/stagehand.d.ts +1 -1
- package/lib/index.ts +16 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Page as Page$1, BrowserContext, Browser } from '@playwright/test';
|
|
2
1
|
import { z, ZodType } from 'zod';
|
|
2
|
+
import { Page as Page$1, BrowserContext as BrowserContext$1, Browser } from '@playwright/test';
|
|
3
3
|
import Browserbase from '@browserbasehq/sdk';
|
|
4
4
|
import { ClientOptions as ClientOptions$2 } from '@anthropic-ai/sdk';
|
|
5
5
|
import { ClientOptions as ClientOptions$1 } from 'openai';
|
|
@@ -138,7 +138,7 @@ interface ConstructorParams {
|
|
|
138
138
|
debugDom?: boolean;
|
|
139
139
|
llmProvider?: LLMProvider;
|
|
140
140
|
headless?: boolean;
|
|
141
|
-
logger?: (message: LogLine) => void
|
|
141
|
+
logger?: (message: LogLine) => void | Promise<void>;
|
|
142
142
|
domSettleTimeoutMs?: number;
|
|
143
143
|
browserbaseSessionCreateParams?: Browserbase.Sessions.SessionCreateParams;
|
|
144
144
|
enableCaching?: boolean;
|
|
@@ -167,7 +167,7 @@ interface InitFromPageOptions {
|
|
|
167
167
|
modelClientOptions?: ClientOptions;
|
|
168
168
|
}
|
|
169
169
|
interface InitFromPageResult {
|
|
170
|
-
context: BrowserContext;
|
|
170
|
+
context: BrowserContext$1;
|
|
171
171
|
}
|
|
172
172
|
interface ActOptions {
|
|
173
173
|
action: string;
|
|
@@ -208,11 +208,12 @@ interface Page extends Page$1 {
|
|
|
208
208
|
extract: <T extends z.AnyZodObject>(options: ExtractOptions<T>) => Promise<ExtractResult<T>>;
|
|
209
209
|
observe: (options?: ObserveOptions) => Promise<ObserveResult[]>;
|
|
210
210
|
}
|
|
211
|
+
type BrowserContext = BrowserContext$1;
|
|
211
212
|
|
|
212
213
|
interface BrowserResult {
|
|
213
214
|
env: "LOCAL" | "BROWSERBASE";
|
|
214
215
|
browser?: Browser;
|
|
215
|
-
context: BrowserContext;
|
|
216
|
+
context: BrowserContext$1;
|
|
216
217
|
debugUrl?: string;
|
|
217
218
|
sessionUrl?: string;
|
|
218
219
|
contextPath?: string;
|
|
@@ -242,7 +243,6 @@ declare class Stagehand {
|
|
|
242
243
|
verbose: 0 | 1 | 2;
|
|
243
244
|
llmProvider: LLMProvider;
|
|
244
245
|
enableCaching: boolean;
|
|
245
|
-
private internalLogger;
|
|
246
246
|
private apiKey;
|
|
247
247
|
private projectId;
|
|
248
248
|
private externalLogger?;
|
|
@@ -252,8 +252,6 @@ declare class Stagehand {
|
|
|
252
252
|
};
|
|
253
253
|
private contextPath?;
|
|
254
254
|
private llmClient;
|
|
255
|
-
private extractHandler?;
|
|
256
|
-
private observeHandler?;
|
|
257
255
|
constructor({ env, apiKey, projectId, verbose, debugDom, llmProvider, headless, logger, browserbaseSessionCreateParams, domSettleTimeoutMs, enableCaching, browserbaseSessionID, modelName, modelClientOptions, }?: ConstructorParams);
|
|
258
256
|
get logger(): (logLine: LogLine) => void;
|
|
259
257
|
get page(): Page;
|
|
@@ -278,4 +276,4 @@ declare class Stagehand {
|
|
|
278
276
|
close(): Promise<void>;
|
|
279
277
|
}
|
|
280
278
|
|
|
281
|
-
export { type ActOptions, type ActResult, type AnthropicJsonSchemaObject, type AnthropicTransformedResponse, type AvailableModel, AvailableModelSchema, type BrowserResult, type ClientOptions, type ConstructorParams, type ExtractOptions, type ExtractResult, type GotoOptions, type InitFromPageOptions, type InitFromPageResult, type InitOptions, type InitResult, type LogLine, type ModelProvider, type ObserveOptions, type ObserveResult, PlaywrightCommandException, PlaywrightCommandMethodNotSupportedException, Stagehand, type ToolCall };
|
|
279
|
+
export { type ActOptions, type ActResult, type AnthropicJsonSchemaObject, type AnthropicTransformedResponse, type AvailableModel, AvailableModelSchema, type BrowserContext, type BrowserResult, type ClientOptions, type ConstructorParams, type ExtractOptions, type ExtractResult, type GotoOptions, type InitFromPageOptions, type InitFromPageResult, type InitOptions, type InitResult, type LogLine, type ModelProvider, type ObserveOptions, type ObserveResult, type Page, PlaywrightCommandException, PlaywrightCommandMethodNotSupportedException, Stagehand, type ToolCall };
|
package/dist/index.js
CHANGED
|
@@ -4780,6 +4780,9 @@ function applyStealthScripts(context) {
|
|
|
4780
4780
|
});
|
|
4781
4781
|
});
|
|
4782
4782
|
}
|
|
4783
|
+
var defaultLogger = (logLine) => __async(void 0, null, function* () {
|
|
4784
|
+
console.log(logLineToString(logLine));
|
|
4785
|
+
});
|
|
4783
4786
|
var Stagehand = class {
|
|
4784
4787
|
constructor({
|
|
4785
4788
|
env,
|
|
@@ -4801,8 +4804,7 @@ var Stagehand = class {
|
|
|
4801
4804
|
}) {
|
|
4802
4805
|
this.pending_logs_to_send_to_browserbase = [];
|
|
4803
4806
|
this.is_processing_browserbase_logs = false;
|
|
4804
|
-
this.externalLogger = logger;
|
|
4805
|
-
this.internalLogger = this.log.bind(this);
|
|
4807
|
+
this.externalLogger = logger || defaultLogger;
|
|
4806
4808
|
this.enableCaching = enableCaching != null ? enableCaching : process.env.ENABLE_CACHING && process.env.ENABLE_CACHING === "true";
|
|
4807
4809
|
this.llmProvider = llmProvider || new LLMProvider(this.logger, this.enableCaching);
|
|
4808
4810
|
this.intEnv = env;
|
|
@@ -4821,10 +4823,7 @@ var Stagehand = class {
|
|
|
4821
4823
|
}
|
|
4822
4824
|
get logger() {
|
|
4823
4825
|
return (logLine) => {
|
|
4824
|
-
this.
|
|
4825
|
-
if (this.externalLogger) {
|
|
4826
|
-
this.externalLogger(logLine);
|
|
4827
|
-
}
|
|
4826
|
+
this.log(logLine);
|
|
4828
4827
|
};
|
|
4829
4828
|
}
|
|
4830
4829
|
get page() {
|
|
@@ -4842,6 +4841,11 @@ var Stagehand = class {
|
|
|
4842
4841
|
return "LOCAL";
|
|
4843
4842
|
}
|
|
4844
4843
|
get context() {
|
|
4844
|
+
if (!this.stagehandContext) {
|
|
4845
|
+
throw new Error(
|
|
4846
|
+
"Stagehand not initialized. Make sure to await stagehand.init() first."
|
|
4847
|
+
);
|
|
4848
|
+
}
|
|
4845
4849
|
return this.stagehandContext.context;
|
|
4846
4850
|
}
|
|
4847
4851
|
init(initOptions) {
|
|
@@ -4928,9 +4932,6 @@ var Stagehand = class {
|
|
|
4928
4932
|
logObj.level = logObj.level || 1;
|
|
4929
4933
|
if (this.externalLogger) {
|
|
4930
4934
|
this.externalLogger(logObj);
|
|
4931
|
-
} else {
|
|
4932
|
-
const logMessage = logLineToString(logObj);
|
|
4933
|
-
console.log(logMessage);
|
|
4934
4935
|
}
|
|
4935
4936
|
this.pending_logs_to_send_to_browserbase.push(__spreadProps(__spreadValues({}, logObj), {
|
|
4936
4937
|
id: (0, import_crypto2.randomUUID)()
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type BrowserContext } from "@playwright/test";
|
|
2
1
|
import { z } from "zod";
|
|
3
2
|
import { LogLine } from "../types/log";
|
|
4
|
-
import { Page } from "../types/page";
|
|
3
|
+
import { Page, BrowserContext } from "../types/page";
|
|
5
4
|
import { ActOptions, ActResult, ConstructorParams, ExtractOptions, ExtractResult, InitFromPageOptions, InitFromPageResult, InitOptions, InitResult, ObserveOptions, ObserveResult } from "../types/stagehand";
|
|
6
5
|
import { LLMProvider } from "./llm/LLMProvider";
|
|
7
6
|
export declare class Stagehand {
|
|
@@ -15,7 +14,6 @@ export declare class Stagehand {
|
|
|
15
14
|
verbose: 0 | 1 | 2;
|
|
16
15
|
llmProvider: LLMProvider;
|
|
17
16
|
enableCaching: boolean;
|
|
18
|
-
private internalLogger;
|
|
19
17
|
private apiKey;
|
|
20
18
|
private projectId;
|
|
21
19
|
private externalLogger?;
|
|
@@ -25,8 +23,6 @@ export declare class Stagehand {
|
|
|
25
23
|
};
|
|
26
24
|
private contextPath?;
|
|
27
25
|
private llmClient;
|
|
28
|
-
private extractHandler?;
|
|
29
|
-
private observeHandler?;
|
|
30
26
|
constructor({ env, apiKey, projectId, verbose, debugDom, llmProvider, headless, logger, browserbaseSessionCreateParams, domSettleTimeoutMs, enableCaching, browserbaseSessionID, modelName, modelClientOptions, }?: ConstructorParams);
|
|
31
27
|
get logger(): (logLine: LogLine) => void;
|
|
32
28
|
get page(): Page;
|
|
@@ -55,3 +51,4 @@ export * from "../types/log";
|
|
|
55
51
|
export * from "../types/model";
|
|
56
52
|
export * from "../types/playwright";
|
|
57
53
|
export * from "../types/stagehand";
|
|
54
|
+
export * from "../types/page";
|
package/dist/types/page.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Page as PlaywrightPage } from "@playwright/test";
|
|
2
|
+
import type { BrowserContext as PlaywrightContext } from "@playwright/test";
|
|
2
3
|
import type { ActResult } from "./act";
|
|
3
4
|
import type { ActOptions, ExtractOptions, ExtractResult, ObserveOptions, ObserveResult } from "./stagehand";
|
|
4
5
|
import type { z } from "zod";
|
|
@@ -7,3 +8,4 @@ export interface Page extends PlaywrightPage {
|
|
|
7
8
|
extract: <T extends z.AnyZodObject>(options: ExtractOptions<T>) => Promise<ExtractResult<T>>;
|
|
8
9
|
observe: (options?: ObserveOptions) => Promise<ObserveResult[]>;
|
|
9
10
|
}
|
|
11
|
+
export type BrowserContext = PlaywrightContext;
|
|
@@ -12,7 +12,7 @@ export interface ConstructorParams {
|
|
|
12
12
|
debugDom?: boolean;
|
|
13
13
|
llmProvider?: LLMProvider;
|
|
14
14
|
headless?: boolean;
|
|
15
|
-
logger?: (message: LogLine) => void
|
|
15
|
+
logger?: (message: LogLine) => void | Promise<void>;
|
|
16
16
|
domSettleTimeoutMs?: number;
|
|
17
17
|
browserbaseSessionCreateParams?: Browserbase.Sessions.SessionCreateParams;
|
|
18
18
|
enableCaching?: boolean;
|
package/lib/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Browserbase } from "@browserbasehq/sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { chromium } from "@playwright/test";
|
|
3
3
|
import { randomUUID } from "crypto";
|
|
4
4
|
import dotenv from "dotenv";
|
|
5
5
|
import fs from "fs";
|
|
@@ -9,7 +9,7 @@ import { z } from "zod";
|
|
|
9
9
|
import { BrowserResult } from "../types/browser";
|
|
10
10
|
import { LogLine } from "../types/log";
|
|
11
11
|
import { GotoOptions } from "../types/playwright";
|
|
12
|
-
import { Page } from "../types/page";
|
|
12
|
+
import { Page, BrowserContext } from "../types/page";
|
|
13
13
|
import {
|
|
14
14
|
ActOptions,
|
|
15
15
|
ActResult,
|
|
@@ -24,8 +24,6 @@ import {
|
|
|
24
24
|
ObserveResult,
|
|
25
25
|
} from "../types/stagehand";
|
|
26
26
|
import { scriptContent } from "./dom/build/scriptContent";
|
|
27
|
-
import { StagehandExtractHandler } from "./handlers/extractHandler";
|
|
28
|
-
import { StagehandObserveHandler } from "./handlers/observeHandler";
|
|
29
27
|
import { LLMClient } from "./llm/LLMClient";
|
|
30
28
|
import { LLMProvider } from "./llm/LLMProvider";
|
|
31
29
|
import { logLineToString } from "./utils";
|
|
@@ -303,6 +301,10 @@ async function applyStealthScripts(context: BrowserContext) {
|
|
|
303
301
|
});
|
|
304
302
|
}
|
|
305
303
|
|
|
304
|
+
const defaultLogger = async (logLine: LogLine) => {
|
|
305
|
+
console.log(logLineToString(logLine));
|
|
306
|
+
};
|
|
307
|
+
|
|
306
308
|
export class Stagehand {
|
|
307
309
|
private stagehandPage!: StagehandPage;
|
|
308
310
|
private stagehandContext!: StagehandContext;
|
|
@@ -316,18 +318,15 @@ export class Stagehand {
|
|
|
316
318
|
public llmProvider: LLMProvider;
|
|
317
319
|
public enableCaching: boolean;
|
|
318
320
|
|
|
319
|
-
private internalLogger: (logLine: LogLine) => void;
|
|
320
321
|
private apiKey: string | undefined;
|
|
321
322
|
private projectId: string | undefined;
|
|
322
|
-
|
|
323
|
+
// We want external logger to accept async functions
|
|
324
|
+
private externalLogger?: (logLine: LogLine) => void | Promise<void>;
|
|
323
325
|
private browserbaseSessionCreateParams?: Browserbase.Sessions.SessionCreateParams;
|
|
324
326
|
public variables: { [key: string]: unknown };
|
|
325
327
|
private contextPath?: string;
|
|
326
328
|
private llmClient: LLMClient;
|
|
327
329
|
|
|
328
|
-
private extractHandler?: StagehandExtractHandler;
|
|
329
|
-
private observeHandler?: StagehandObserveHandler;
|
|
330
|
-
|
|
331
330
|
constructor(
|
|
332
331
|
{
|
|
333
332
|
env,
|
|
@@ -348,8 +347,7 @@ export class Stagehand {
|
|
|
348
347
|
env: "BROWSERBASE",
|
|
349
348
|
},
|
|
350
349
|
) {
|
|
351
|
-
this.externalLogger = logger;
|
|
352
|
-
this.internalLogger = this.log.bind(this);
|
|
350
|
+
this.externalLogger = logger || defaultLogger;
|
|
353
351
|
this.enableCaching =
|
|
354
352
|
enableCaching ??
|
|
355
353
|
(process.env.ENABLE_CACHING && process.env.ENABLE_CACHING === "true");
|
|
@@ -372,10 +370,7 @@ export class Stagehand {
|
|
|
372
370
|
|
|
373
371
|
public get logger(): (logLine: LogLine) => void {
|
|
374
372
|
return (logLine: LogLine) => {
|
|
375
|
-
this.
|
|
376
|
-
if (this.externalLogger) {
|
|
377
|
-
this.externalLogger(logLine);
|
|
378
|
-
}
|
|
373
|
+
this.log(logLine);
|
|
379
374
|
};
|
|
380
375
|
}
|
|
381
376
|
|
|
@@ -398,6 +393,11 @@ export class Stagehand {
|
|
|
398
393
|
}
|
|
399
394
|
|
|
400
395
|
public get context(): BrowserContext {
|
|
396
|
+
if (!this.stagehandContext) {
|
|
397
|
+
throw new Error(
|
|
398
|
+
"Stagehand not initialized. Make sure to await stagehand.init() first.",
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
401
|
return this.stagehandContext.context;
|
|
402
402
|
}
|
|
403
403
|
|
|
@@ -504,9 +504,6 @@ export class Stagehand {
|
|
|
504
504
|
// Normal Logging
|
|
505
505
|
if (this.externalLogger) {
|
|
506
506
|
this.externalLogger(logObj);
|
|
507
|
-
} else {
|
|
508
|
-
const logMessage = logLineToString(logObj);
|
|
509
|
-
console.log(logMessage);
|
|
510
507
|
}
|
|
511
508
|
|
|
512
509
|
// Add the logs to the browserbase session
|
|
@@ -613,3 +610,4 @@ export * from "../types/log";
|
|
|
613
610
|
export * from "../types/model";
|
|
614
611
|
export * from "../types/playwright";
|
|
615
612
|
export * from "../types/stagehand";
|
|
613
|
+
export * from "../types/page";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserbasehq/stagehand",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.1-alpha-5c6f14bade201e08cb86d2e14e246cb65707f7ee",
|
|
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",
|