Skip to content
Closed

Zodv4 #1157

Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7cdaa0c
zodv4
tkattkat Oct 22, 2025
004614a
cleanup
tkattkat Oct 22, 2025
e9d5548
add comment
tkattkat Oct 22, 2025
3306f21
remove logging
tkattkat Oct 22, 2025
c5c8c62
rm
tkattkat Oct 22, 2025
0a79127
clean
tkattkat Oct 22, 2025
6e18601
rm
tkattkat Oct 22, 2025
77ada5c
Merge branch 'v3' into zodv4
tkattkat Oct 28, 2025
ed6e6eb
remove json schema to zod
tkattkat Oct 28, 2025
4f25abe
Merge branch 'v3' into zodv4
tkattkat Oct 28, 2025
3998f54
remove zod to schema
tkattkat Oct 28, 2025
04e6211
Merge branch 'zodv4' of https://github.com/browserbase/stagehand into…
tkattkat Oct 28, 2025
6e00759
remove zod v3
tkattkat Oct 28, 2025
b15fd50
move zod out of peer dependencies
tkattkat Oct 28, 2025
a45de88
Merge branch 'v3' into zodv4
miguelg719 Oct 28, 2025
4658860
test release
miguelg719 Oct 28, 2025
5834b5b
update readme (#1192)
miguelg719 Oct 29, 2025
5f4a47e
update readme (#1195)
seanmcguire12 Oct 29, 2025
e634539
rm `orca` pkg from evals (#1197)
seanmcguire12 Oct 29, 2025
49bc5b6
rm empty changeset (#1198)
seanmcguire12 Oct 29, 2025
84c2105
rm old changesets (#1199)
seanmcguire12 Oct 29, 2025
0a5ee63
log warning on scope narrowing failure (#1200)
seanmcguire12 Oct 29, 2025
4722130
[docs] fix github links (#1202)
seanmcguire12 Oct 29, 2025
ee76881
changelog v3 and core package readme (#1205)
miguelg719 Oct 30, 2025
55da8c6
Fix broken link to quickstart in the README (#1207)
miguelg719 Oct 30, 2025
d5ecbfc
Export AISdkClient (#1206)
miguelg719 Oct 30, 2025
30d0a24
Fix e2e:bb tests (#1208)
miguelg719 Oct 30, 2025
da33c5a
fix ref for python (#1210)
derekmeegan Oct 31, 2025
9e95add
don't import from barrel in exported example aisdk client (#1209)
seanmcguire12 Oct 31, 2025
98e212b
add example for custom tools and docs (#1211)
miguelg719 Oct 31, 2025
9ab5725
Version Packages (#1126)
github-actions[bot] Oct 31, 2025
08b19bd
Correct installation example (#1214)
sophie2chance2 Oct 31, 2025
b341515
revert testing changes
tkattkat Nov 3, 2025
b4bd179
Merge remote-tracking branch 'origin/main' into zodv4
tkattkat Nov 3, 2025
f5d2a31
remove zod version pinning from few examples
tkattkat Nov 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/examples/2048.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Stagehand } from "../lib/v3";
import { z } from "zod/v3";
import { z } from "zod";

async function example() {
console.log("🎮 Starting 2048 bot...");
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/custom_client_aisdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { Stagehand } from "../lib/v3";
import { AISdkClient } from "./external_clients/aisdk";
import { z } from "zod/v3";
import { z } from "zod";
import { openai } from "@ai-sdk/openai";

async function example() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/custom_client_langchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* You will need to reference the Langchain Client in /external_clients/langchain.ts
*/
import { z } from "zod/v3";
import { z } from "zod";
import { Stagehand } from "../lib/v3";
import { LangchainClient } from "./external_clients/langchain";
import { ChatOpenAI } from "@langchain/openai";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/custom_client_openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* You will need to reference the Custom OpenAI Client in /external_clients/customOpenAI.ts
*/
import { Stagehand } from "../lib/v3";
import { z } from "zod/v3";
import { z } from "zod";
import { CustomOpenAIClient } from "./external_clients/customOpenAI";
import OpenAI from "openai";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/external_clients/customOpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
ChatCompletionSystemMessageParam,
ChatCompletionUserMessageParam,
} from "openai/resources/chat/completions";
import { z } from "zod/v3";
import { z } from "zod";
import { CreateChatCompletionResponseError } from "../../lib/v3";

function validateZodSchema(schema: z.ZodTypeAny, data: unknown) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/parameterizeApiKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Stagehand } from "../lib/v3";
import { z } from "zod/v3";
import { z } from "zod";

/**
* This example shows how to parameterize the API key for the LLM provider.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/v3/patchright.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stagehand } from "../../lib/v3";
import { chromium } from "patchright-core";
import { z } from "zod/v3";
import { z } from "zod";

async function example(stagehand: Stagehand) {
const browser = await chromium.connectOverCDP({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/v3/playwright.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stagehand } from "../../lib/v3";
import { chromium } from "playwright-core";
import { z } from "zod/v3";
import { z } from "zod";

async function example(stagehand: Stagehand) {
const browser = await chromium.connectOverCDP({
Expand Down
28 changes: 13 additions & 15 deletions packages/core/examples/v3/targetedExtract.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops was testing and accidentally commited, reverting

Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import { Stagehand } from "../../lib/v3";
import { z } from "zod/v3";
import { z } from "zod";

async function example(stagehand: Stagehand) {
const page = stagehand.context.pages()[0];
await page.goto(
"https://ambarc.github.io/web-element-test/stagehand-breaking-test.html",
"https://browserbase.github.io/stagehand-eval-sites/sites/jfk/",
);

await page
.deepLocator("/html/body/div[2]/div[3]/iframe/html/body/p")
.highlight({
durationMs: 5000,
contentColor: { r: 255, g: 0, b: 0 },
});

const reason = await stagehand.extract(
"extract the reason why script injection fails",
z.string(),
// selector: "// body > div.test-container > div:nth-child(3) > iframe >> body > p:nth-child(3)",
{ selector: "/html/body/div[2]/div[3]/iframe/html/body/p[2]" },
const extraction = await stagehand.extract(
"extract all the record file name and their corresponding links",
z.object({
records: z.array(
z.object({
file_name: z.string().describe("the file name of the record"),
link: z.url().describe("the link to the record"),
}),
),
}),
);
console.log(reason);
console.log(extraction);
}

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/v3_example.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { V3 } from "../lib/v3";
import { z } from "zod/v3";
import { z } from "zod";

async function example(v3: V3) {
const page = v3.context.pages()[0];
Expand Down
29 changes: 7 additions & 22 deletions packages/core/lib/inference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from "zod/v3";
import { z } from "zod";
import { LogLine } from "./v3/types/public/logs";
import { ChatMessage, LLMClient } from "./v3/llm/LLMClient";
import {
Expand All @@ -12,20 +12,8 @@ import {
} from "./prompt";
import { appendSummary, writeTimestampedTxtFile } from "./inferenceLogUtils";

/** Simple usage shape if your LLM returns usage tokens. */
interface LLMUsage {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
}

/**
* For calls that use a schema: the LLMClient may return { data: T; usage?: LLMUsage }
*/
export interface LLMParsedResponse<T> {
data: T;
usage?: LLMUsage;
}
// Re-export for backward compatibility
export type { LLMParsedResponse } from "./v3/llm/LLMClient";

export async function extract({
instruction,
Expand Down Expand Up @@ -101,8 +89,7 @@ export async function extract({
});
const extractEndTime = Date.now();

const { data: extractedData, usage: extractUsage } =
extractionResponse as LLMParsedResponse<ExtractionResponse>;
const { data: extractedData, usage: extractUsage } = extractionResponse;

let extractResponseFile = "";
if (logInferenceToFile) {
Expand Down Expand Up @@ -171,7 +158,7 @@ export async function extract({
progress: metadataResponseProgress,
},
usage: metadataResponseUsage,
} = metadataResponse as LLMParsedResponse<MetadataResponse>;
} = metadataResponse;

let metadataResponseFile = "";
if (logInferenceToFile) {
Expand Down Expand Up @@ -308,8 +295,7 @@ export async function observe({
const end = Date.now();
const usageTimeMs = end - start;

const { data: observeData, usage: observeUsage } =
rawResponse as LLMParsedResponse<ObserveResponse>;
const { data: observeData, usage: observeUsage } = rawResponse;
const promptTokens = observeUsage?.prompt_tokens ?? 0;
const completionTokens = observeUsage?.completion_tokens ?? 0;

Expand Down Expand Up @@ -440,8 +426,7 @@ export async function act({
const end = Date.now();
const usageTimeMs = end - start;

const { data: actData, usage: actUsage } =
rawResponse as LLMParsedResponse<ActResponse>;
const { data: actData, usage: actUsage } = rawResponse;
const promptTokens = actUsage?.prompt_tokens ?? 0;
const completionTokens = actUsage?.completion_tokens ?? 0;

Expand Down
Loading
Loading