Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/cruel-rivers-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

Migrate the AI SDK integration to v6 while preserving the existing public API surface.
6 changes: 6 additions & 0 deletions packages/core/lib/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function extract<T extends StagehandZodObject>({
instruction,
domElements,
schema,
strictSchema = true,
llmClient,
logger,
userProvidedInstructions,
Expand All @@ -42,6 +43,7 @@ export async function extract<T extends StagehandZodObject>({
instruction: string;
domElements: string;
schema: T;
strictSchema?: boolean;
llmClient: LLMClient;
userProvidedInstructions?: string;
logger: (message: LogLine) => void;
Expand Down Expand Up @@ -94,6 +96,7 @@ export async function extract<T extends StagehandZodObject>({
response_model: {
schema,
name: "Extraction",
strict: strictSchema,
},
temperature: isGPT5 ? 1 : 0.1,
top_p: 1,
Expand Down Expand Up @@ -161,6 +164,7 @@ export async function extract<T extends StagehandZodObject>({
response_model: {
name: "Metadata",
schema: metadataSchema,
strict: true,
},
temperature: isGPT5 ? 1 : 0.1,
top_p: 1,
Expand Down Expand Up @@ -330,6 +334,7 @@ export async function observe({
response_model: {
schema: observeSchema,
name: "Observation",
strict: true,
},
temperature: isGPT5 ? 1 : 0.1,
top_p: 1,
Expand Down Expand Up @@ -470,6 +475,7 @@ export async function act({
response_model: {
schema: actSchema,
name: "act",
strict: true,
},
temperature: isGPT5 ? 1 : 0.1,
top_p: 1,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/lib/v3/agent/tools/act.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tool } from "ai";
import { NoObjectGeneratedError, tool } from "ai";
import { z } from "zod";
import type { V3 } from "../../v3.js";
import type { Action } from "../../types/public/methods.js";
Expand Down Expand Up @@ -66,6 +66,9 @@ export const actTool = (
if (error instanceof TimeoutError) {
throw error;
}
if (NoObjectGeneratedError.isInstance(error)) {
throw error;
}
return {
success: false,
error: error?.message ?? String(error),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/v3/agent/tools/ariaTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const ariaTreeTool = (v3: V3, toolTimeout?: number) =>
};
}
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/v3/agent/tools/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const clickTool = (v3: V3, provider?: string) =>
};
}
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/v3/agent/tools/dragAndDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const dragAndDropTool = (v3: V3, provider?: string) =>
};
}
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down
5 changes: 4 additions & 1 deletion packages/core/lib/v3/agent/tools/extract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tool } from "ai";
import { NoObjectGeneratedError, tool } from "ai";
import { z, ZodTypeAny } from "zod";
import type { V3 } from "../../v3.js";
import type { AgentModelConfig } from "../../types/public/agent.js";
Expand Down Expand Up @@ -103,6 +103,9 @@ export const extractTool = (
if (error instanceof TimeoutError) {
throw error;
}
if (NoObjectGeneratedError.isInstance(error)) {
throw error;
}
return { success: false, error: error?.message ?? String(error) };
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/v3/agent/tools/fillFormVision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ MANDATORY USE CASES (always use fillFormVision for these):
};
}
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down
5 changes: 4 additions & 1 deletion packages/core/lib/v3/agent/tools/fillform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tool } from "ai";
import { NoObjectGeneratedError, tool } from "ai";
import { z } from "zod";
import type { V3 } from "../../v3.js";
import type { Action } from "../../types/public/methods.js";
Expand Down Expand Up @@ -77,6 +77,9 @@ export const fillFormTool = (
if (error instanceof TimeoutError) {
throw error;
}
if (NoObjectGeneratedError.isInstance(error)) {
throw error;
}
return {
success: false,
error: error?.message ?? String(error),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/v3/agent/tools/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const screenshotTool = (v3: V3) =>
};
}
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/v3/agent/tools/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const scrollTool = (v3: V3) =>
scrolledPixels: scrollDistance,
};
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down Expand Up @@ -169,7 +169,7 @@ export const scrollVisionTool = (v3: V3, provider?: string) =>
screenshotBase64,
};
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/v3/agent/tools/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const typeTool = (v3: V3, provider?: string, variables?: Variables) => {
};
}
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/v3/agent/tools/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const waitTool = (v3: V3, mode?: AgentToolMode) =>

return { success: true, waited: timeMs };
},
toModelOutput: (result) => {
toModelOutput: ({ output: result }) => {
if (result.success === false || result.error !== undefined) {
return {
type: "content",
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/v3/agent/utils/handleDoneToolCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Call the "done" tool with:
? "Complete the task with your assessment and the requested output data."
: "Complete the task with your final assessment.",
inputSchema: doneToolSchema,
strict: true,
execute: async (params) => {
return { success: true, ...params };
},
Expand Down
Loading
Loading