Skip to content

Commit dfd24e6

Browse files
support api usage for extract with no args (#582)
1 parent c7c1a80 commit dfd24e6

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Diff for: .changeset/petite-donuts-lead.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
support api usage for extract with no args

Diff for: lib/StagehandPage.ts

+3
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ export class StagehandPage {
547547

548548
// check if user called extract() with no arguments
549549
if (!instructionOrOptions) {
550+
if (this.api) {
551+
return this.api.extract<T>({});
552+
}
550553
return this.extractHandler.extract();
551554
}
552555

Diff for: lib/api.ts

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ export class StagehandAPI {
9191
async extract<T extends z.AnyZodObject>(
9292
options: ExtractOptions<T>,
9393
): Promise<ExtractResult<T>> {
94+
if (!options.schema) {
95+
return this.execute<ExtractResult<T>>({
96+
method: "extract",
97+
args: {},
98+
});
99+
}
94100
const parsedSchema = zodToJsonSchema(options.schema);
95101
return this.execute<ExtractResult<T>>({
96102
method: "extract",

Diff for: types/stagehand.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export interface ActResult {
9898
}
9999

100100
export interface ExtractOptions<T extends z.AnyZodObject> {
101-
instruction: string;
102-
schema: T;
101+
instruction?: string;
102+
schema?: T;
103103
modelName?: AvailableModel;
104104
modelClientOptions?: ClientOptions;
105105
domSettleTimeoutMs?: number;

0 commit comments

Comments
 (0)