This commit is contained in:
Krishav Raj Singh 2025-08-11 14:59:33 +05:30
parent cfb0ed9049
commit 93892535c2
9 changed files with 8 additions and 2124 deletions

View File

@ -104,7 +104,7 @@ class BrowserTool(SandboxToolsBase):
await self._ensure_sandbox()
# Check what processes are running
ps_cmd = "ps aux | grep -E '(python|uvicorn|stagehand)' | grep -v grep"
ps_cmd = "ps aux | grep -E '(python|uvicorn|stagehand|node)' | grep -v grep"
response = await self.sandbox.process.exec(ps_cmd, timeout=10)
processes = response.result if response.exit_code == 0 else "Failed to get process list"

View File

@ -106,7 +106,7 @@ RUN npx playwright install chromium
# Verify installation
RUN node -e "import('playwright').then(() => console.log('Playwright installation verified')).catch(e => { console.error('Playwright verification failed:', e); process.exit(1); })"
# Copy server scripts
# Copy server script
COPY . /app
COPY server.py /app/server.py

View File

@ -1,6 +1,5 @@
import express from 'express';
import { Stagehand, type LogLine, type ObserveResult, type Page } from '@browserbasehq/stagehand';
// import logging from 'logging';
import { Stagehand, type LogLine, type Page } from '@browserbasehq/stagehand';
const app = express();
app.use(express.json());
@ -13,7 +12,6 @@ interface BrowserActionResult {
title: string;
screenshot_base64?: string;
action?: string;
observeResult?: ObserveResult[];
}
class BrowserAutomation {
@ -41,7 +39,7 @@ class BrowserAutomation {
try{
if (!this.browserInitialized) {
this.currentApiKey = apiKey;
console.log("Initializing browser with api key", apiKey);
console.log("Initializing browser with api key");
this.stagehand = new Stagehand({
env: "LOCAL",
enableCaching: true,
@ -227,7 +225,6 @@ class BrowserAutomation {
try {
if (this.page && this.browserInitialized) {
const { action, iframes, variables } = req.body;
console.log(action, iframes, variables);
const result = await this.page.act({action, iframes: iframes || true, variables});
const page_info = await this.get_stagehand_state();
const response: BrowserActionResult = {
@ -286,7 +283,7 @@ const browserAutomation = new BrowserAutomation();
app.use('/api', browserAutomation.router);
app.get('/api', (req, res) => {
console.log("Health check", browserAutomation);
console.log("Health check");
const health = browserAutomation.health();
if (health.status === "healthy") {
res.status(200).json({
@ -305,7 +302,7 @@ app.post('/api/init', async (req, res) => {
console.log("Initializing browser");
const {api_key} = req.body;
const result = await browserAutomation.init(api_key);
console.log(result);
if (result.status === "initialized") {
res.status(200).json({
"status": "healthy",

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "browserApi",
"version": "1.0.0",
"description": "Browser API server for sandbox",
"description": "Browser API server(Stagehand)",
"type": "module",
"scripts": {
"start": "tsx browserApi.ts"

View File

@ -83,7 +83,7 @@ stopwaitsecs=10
[program:browserApi]
command=npm start
directory=/app
autorestart=true
# autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr

View File

@ -47,7 +47,6 @@ export function getToolTitle(toolName: string): string {
'browser-act': 'Browser Action',
'browser-extract-content': 'Browser Extract',
'browser-screenshot': 'Browser Screenshot',
'browser-observe': 'Browser Observe',
'see-image': 'View Image',
'ask': 'Ask',
'complete': 'Task Complete',

View File

@ -39,7 +39,6 @@ const defaultRegistry: ToolViewRegistryType = {
'browser-navigate-to': BrowserToolView,
'browser-act': BrowserToolView,
'browser-extract-content': BrowserToolView,
'browser-observe': BrowserToolView,
'browser-screenshot': BrowserToolView,
'execute-command': CommandToolView,

View File

@ -85,7 +85,6 @@ export const getToolIcon = (toolName: string): ElementType => {
case 'browser-navigate-to':
case 'browser-act':
case 'browser-extract-content':
case 'browser-observe':
case 'browser-screenshot':
return Globe;