diff --git a/apps/sim/app/api/tools/stagehand/agent/route.ts b/apps/sim/app/api/tools/stagehand/agent/route.ts index 34177f612..1e5f480fc 100644 --- a/apps/sim/app/api/tools/stagehand/agent/route.ts +++ b/apps/sim/app/api/tools/stagehand/agent/route.ts @@ -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' @@ -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 @@ -89,7 +90,7 @@ function substituteVariables(text: string, variables: Record | u } export async function POST(request: NextRequest) { - let stagehand: Stagehand | null = null + let stagehand: StagehandType | null = null try { const body = await request.json() @@ -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, diff --git a/apps/sim/app/api/tools/stagehand/extract/route.ts b/apps/sim/app/api/tools/stagehand/extract/route.ts index bd8a1e96a..7da282815 100644 --- a/apps/sim/app/api/tools/stagehand/extract/route.ts +++ b/apps/sim/app/api/tools/stagehand/extract/route.ts @@ -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' @@ -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 @@ -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() @@ -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, diff --git a/apps/sim/next.config.ts b/apps/sim/next.config.ts index e2f3ebaba..20e806387 100644 --- a/apps/sim/next.config.ts +++ b/apps/sim/next.config.ts @@ -79,7 +79,6 @@ const nextConfig: NextConfig = { 'pino', 'pino-pretty', 'thread-stream', - '@browserbasehq/stagehand', ], experimental: { optimizeCss: true,