Skip to content
Merged
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
7 changes: 5 additions & 2 deletions apps/sim/app/api/tools/stagehand/agent/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Stagehand } from '@browserbasehq/stagehand'
import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { env } from '@/lib/core/config/env'
Expand All @@ -7,6 +6,8 @@ import { ensureZodObject, normalizeUrl } from '@/app/api/tools/stagehand/utils'

const logger = createLogger('StagehandAgentAPI')

type StagehandType = import('@browserbasehq/stagehand').Stagehand

const BROWSERBASE_API_KEY = env.BROWSERBASE_API_KEY
const BROWSERBASE_PROJECT_ID = env.BROWSERBASE_PROJECT_ID

Expand Down Expand Up @@ -89,7 +90,7 @@ function substituteVariables(text: string, variables: Record<string, string> | u
}

export async function POST(request: NextRequest) {
let stagehand: Stagehand | null = null
let stagehand: StagehandType | null = null

try {
const body = await request.json()
Expand Down Expand Up @@ -157,6 +158,8 @@ export async function POST(request: NextRequest) {
try {
logger.info('Initializing Stagehand with Browserbase (v3)', { provider, modelName })

const { Stagehand } = await import('@browserbasehq/stagehand')

stagehand = new Stagehand({
env: 'BROWSERBASE',
apiKey: BROWSERBASE_API_KEY,
Expand Down
7 changes: 5 additions & 2 deletions apps/sim/app/api/tools/stagehand/extract/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Stagehand } from '@browserbasehq/stagehand'
import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { env } from '@/lib/core/config/env'
Expand All @@ -7,6 +6,8 @@ import { ensureZodObject, normalizeUrl } from '@/app/api/tools/stagehand/utils'

const logger = createLogger('StagehandExtractAPI')

type StagehandType = import('@browserbasehq/stagehand').Stagehand

const BROWSERBASE_API_KEY = env.BROWSERBASE_API_KEY
const BROWSERBASE_PROJECT_ID = env.BROWSERBASE_PROJECT_ID

Expand All @@ -21,7 +22,7 @@ const requestSchema = z.object({
})

export async function POST(request: NextRequest) {
let stagehand: Stagehand | null = null
let stagehand: StagehandType | null = null

try {
const body = await request.json()
Expand Down Expand Up @@ -93,6 +94,8 @@ export async function POST(request: NextRequest) {

logger.info('Initializing Stagehand with Browserbase (v3)', { provider, modelName })

const { Stagehand } = await import('@browserbasehq/stagehand')

stagehand = new Stagehand({
env: 'BROWSERBASE',
apiKey: BROWSERBASE_API_KEY,
Expand Down
1 change: 0 additions & 1 deletion apps/sim/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const nextConfig: NextConfig = {
'pino',
'pino-pretty',
'thread-stream',
'@browserbasehq/stagehand',
],
experimental: {
optimizeCss: true,
Expand Down