Files
BrowserOS/webpack.config.js
Nikhil e25d463d95 NewAgent (#91)
* PocAgent + refactor (#77)

* Screenshot tool fixed

* ReactAgent loop

ReactAgent loop

v0.2

* Trim to max tokens implemented correctly

trim max tokens

* JSON Parse fix

Fixed json.parse

* Minor fix -- add system message always at position 0

* minor fix

* Added support for passing screenshot size to captureScreenshot

backup

* Make react agent use screenshot tool

* Refactor backend and execution (#75)

* wip: new exection class and manager

* wip: new pubsub channels

* wip: new background handlers

* new execution logic

* removed execution status

* handle workflow status for processing in sidepanel

* mcp server fix

* sending pause message

* better portName parsing, sidepanel sends tabId, storing tabId too

* 49.0.0.26 release

* docs: OmkarBansod02 signed the CLA in browseros-ai/BrowserOS-agent#$pullRequestNo

* Refactor backend and execution (#75)

* wip: new exection class and manager

* wip: new pubsub channels

* wip: new background handlers

* new execution logic

* removed execution status

* handle workflow status for processing in sidepanel

* mcp server fix

* sending pause message

* better portName parsing, sidepanel sends tabId, storing tabId too

* Moved react agent into POCAgent

* Revert changes of ReacStrategy from BrowserAgent

* Minor fix

* fix: execution class abort issue

* clean-up: removed un-used MessageTypes

* clean-up: execution-manager simplified

* better abort handling

---------

Co-authored-by: Felarof <nithin.sonti@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Screenshot failure handling

* fixes to custom agent -> sidepanel

* fix: portName stable

* fix: pause/reset + newtab connector

* New agent: wip-1

* fix: JSONify message content in MessageManagerReadyOnly

* disable cacheLLM and fixing image type detection

* new agent: wip-2

* rename: <BrowserState> as <browser-state> and <SystemReminder> as <system-reminder>

* new-agent: wip-3

---------

Co-authored-by: Felarof <nithin.sonti@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-09-12 11:12:45 -07:00

191 lines
6.3 KiB
JavaScript

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')
const dotenv = require('dotenv')
const fs = require('fs')
const ExtensionReloader = require('webpack-ext-reloader')
// Load .env file
let envKeys = {}
// Load environment variables from .env file
const env = dotenv.config()
envKeys = env.parsed || {}
// Validate required API keys
if (!env.parsed) {
throw new Error('No .env file found. API keys must be set manually.')
}
// Create environment variables to inject
const processEnv = {
'process.env.POSTHOG_API_KEY': JSON.stringify(envKeys.POSTHOG_API_KEY || ''),
'process.env.KLAVIS_API_KEY': JSON.stringify(envKeys.KLAVIS_API_KEY || ''),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.MOONDREAM_API_KEY': JSON.stringify(envKeys.MOONDREAM_API_KEY || ''),
// Firebase environment variables
'process.env.FIREBASE_API_KEY': JSON.stringify(envKeys.FIREBASE_API_KEY || ''),
'process.env.FIREBASE_AUTH_DOMAIN': JSON.stringify(envKeys.FIREBASE_AUTH_DOMAIN || ''),
'process.env.FIREBASE_PROJECT_ID': JSON.stringify(envKeys.FIREBASE_PROJECT_ID || ''),
'process.env.FIREBASE_STORAGE_BUCKET': JSON.stringify(envKeys.FIREBASE_STORAGE_BUCKET || ''),
'process.env.FIREBASE_MESSAGING_SENDER_ID': JSON.stringify(envKeys.FIREBASE_MESSAGING_SENDER_ID || ''),
'process.env.FIREBASE_APP_ID': JSON.stringify(envKeys.FIREBASE_APP_ID || ''),
'process.env.FIREBASE_MEASUREMENT_ID': JSON.stringify(envKeys.FIREBASE_MEASUREMENT_ID || ''),
// Braintrust Telemetry Configuration
'process.env.ENABLE_TELEMETRY': JSON.stringify(envKeys.ENABLE_TELEMETRY || 'false'),
'process.env.ENABLE_EVALS2': JSON.stringify(envKeys.ENABLE_EVALS2 || 'false'),
'process.env.BRAINTRUST_API_KEY': JSON.stringify(envKeys.BRAINTRUST_API_KEY || ''),
'process.env.BRAINTRUST_PROJECT_UUID': JSON.stringify(envKeys.BRAINTRUST_PROJECT_UUID || ''),
'process.env.BRAINTRUST_PROJECT_NAME': JSON.stringify(envKeys.BRAINTRUST_PROJECT_NAME || 'browseros-agent-online'),
// Gemini API keys for evals2 scoring
'process.env.GOOGLE_GENAI_API_KEY': JSON.stringify(envKeys.GOOGLE_GENAI_API_KEY || ''),
'process.env.GEMINI_API_KEY': JSON.stringify(envKeys.GEMINI_API_KEY || '')
}
console.log('API keys will be injected at build time (keys hidden for security)')
// Determine environment (default to development if not specified)
const isDevelopment = process.env.NODE_ENV !== 'production'
// Detect if this is a Chrome build
const isChromeTarget = process.env.BUILD_TARGET === 'chrome'
// Detect if webpack is running in watch mode (CLI flag or env variable set by webpack)
const isWatch = process.argv.includes('--watch') || process.env.WEBPACK_WATCH === 'true'
module.exports = {
mode: isDevelopment ? 'development' : 'production',
devtool: isDevelopment ? 'source-map' : false,
entry: {
sidepanel: './src/sidepanel/index.tsx',
background: './src/background/index.ts',
'glow-animation': './src/content/glow-animation.ts',
newtab: './src/newtab/index.tsx'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true
}
},
exclude: [
/node_modules/,
/\.(test|spec)\.(ts|tsx)$/
]
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]--[hash:base64:5]'
}
}
},
{
loader: 'sass-loader',
options: {
api: 'modern' // Use the modern Sass API
}
}
]
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
'postcss-loader'
]
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@': path.resolve(__dirname, 'src')
}
},
optimization: {
splitChunks: false, // Disable all code splitting
runtimeChunk: false, // Keep runtime in each entry point
// Configure minimizer to prevent LICENSE file generation in production
minimizer: isDevelopment ? [] : [
new TerserPlugin({
extractComments: false, // Disable LICENSE file extraction
terserOptions: {
format: {
comments: false, // Remove all comments
},
compress: { // Remove console and debugger statements in production
drop_console: true,
drop_debugger: true
},
},
}),
],
},
plugins: [
// Limit chunks to entry points only - prevents dynamic chunk creation
// This forces all imports (including dynamic) to be bundled into their parent entry
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 4 // One chunk per entry point (sidepanel, background, glow-animation, newtab)
}),
new HtmlWebpackPlugin({
template: './src/sidepanel/index.html',
filename: 'sidepanel.html',
chunks: ['sidepanel']
}),
new HtmlWebpackPlugin({
template: './src/newtab/index.html',
filename: 'newtab.html',
chunks: ['newtab']
}),
new CopyPlugin({
patterns: [
{
from: 'manifest.json',
to: '.',
transform: (content) => {
if (isChromeTarget) {
const manifest = JSON.parse(content.toString());
manifest.component = true;
return JSON.stringify(manifest, null, 2);
}
return content;
}
},
{ from: 'assets', to: 'assets', noErrorOnMissing: true }
]
}),
new webpack.DefinePlugin(processEnv),
// Include hot-reload plugin only when in development AND watch mode to allow interactive dev
...(isDevelopment && isWatch
? [
new ExtensionReloader({
port: 9090,
reloadPage: true,
entries: {
background: 'background',
contentScript: 'content',
extensionPage: ['sidepanel']
}
})
]
: [])
]
}