chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 11:58:09 +08:00
commit c48e26cdd0
2909 changed files with 1591131 additions and 0 deletions
@@ -0,0 +1,104 @@
import esbuild from 'esbuild';
import fs from 'node:fs'; // Import the full fs module
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const manifestPath = path.resolve(
__dirname,
'../src/agents/browser/browser-tools-manifest.json',
);
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
// Only exclude tools explicitly mentioned in the manifest's exclude list
const excludedToolsFiles = (manifest.exclude || []).map((t) => t.name);
// Basic esbuild plugin to empty out excluded modules
const emptyModulePlugin = {
name: 'empty-modules',
setup(build) {
if (excludedToolsFiles.length === 0) return;
// Create a filter that matches any of the excluded tools
const excludeFilter = new RegExp(`(${excludedToolsFiles.join('|')})\\.js$`);
build.onResolve({ filter: excludeFilter }, (args) => {
// Check if we are inside a tools directory to avoid accidental matches
if (
args.importer.includes('chrome-devtools-mcp') &&
/[\\/]tools[\\/]/.test(args.importer)
) {
return { path: args.path, namespace: 'empty' };
}
return null;
});
build.onLoad({ filter: /.*/, namespace: 'empty' }, (_args) => ({
contents: 'export {};', // Empty module (ESM)
loader: 'js',
}));
},
};
async function bundle() {
try {
const entryPoint = path.resolve(
__dirname,
'../../../node_modules/chrome-devtools-mcp/build/src/index.js',
);
await esbuild.build({
entryPoints: [entryPoint],
bundle: true,
outfile: path.resolve(
__dirname,
'../dist/bundled/chrome-devtools-mcp.mjs',
),
format: 'esm',
platform: 'node',
plugins: [emptyModulePlugin],
external: [
'puppeteer-core',
'/bundled/*',
'../../../node_modules/puppeteer-core/*',
],
banner: {
js: 'import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);',
},
});
// Copy third_party assets
const srcThirdParty = path.resolve(
__dirname,
'../../../node_modules/chrome-devtools-mcp/build/src/third_party',
);
const destThirdParty = path.resolve(
__dirname,
'../dist/bundled/third_party',
);
if (fs.existsSync(srcThirdParty)) {
if (fs.existsSync(destThirdParty)) {
fs.rmSync(destThirdParty, { recursive: true, force: true });
}
fs.cpSync(srcThirdParty, destThirdParty, {
recursive: true,
filter: (src) => {
// Skip large/unnecessary bundles that are either explicitly excluded
// or not required for the browser agent functionality.
return (
!src.includes('lighthouse-devtools-mcp-bundle.js') &&
!src.includes('devtools-formatter-worker.js')
);
},
});
} else {
console.warn(`Warning: third_party assets not found at ${srcThirdParty}`);
}
} catch (error) {
console.error('Error bundling chrome-devtools-mcp:', error);
process.exit(1);
}
}
bundle();
@@ -0,0 +1,121 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-env node */
import { spawnSync } from 'node:child_process';
import path from 'node:path';
import fs from 'node:fs';
import os from 'node:os';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Compiles the GeminiSandbox C# helper on Windows.
* This is used to provide native restricted token sandboxing.
*/
function compileWindowsSandbox() {
if (os.platform() !== 'win32') {
return;
}
const srcHelperPath = path.resolve(
__dirname,
'../src/sandbox/windows/GeminiSandbox.exe',
);
const distHelperPath = path.resolve(
__dirname,
'../dist/src/sandbox/windows/GeminiSandbox.exe',
);
const sourcePath = path.resolve(
__dirname,
'../src/sandbox/windows/GeminiSandbox.cs',
);
if (!fs.existsSync(sourcePath)) {
console.error(`Sandbox source not found at ${sourcePath}`);
return;
}
// Ensure directories exist
[srcHelperPath, distHelperPath].forEach((p) => {
const dir = path.dirname(p);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
});
// Find csc.exe (C# Compiler) which is built into Windows .NET Framework
const systemRoot = process.env['SystemRoot'] || 'C:\\Windows';
const cscPaths = [
'csc.exe', // Try in PATH first
path.join(
systemRoot,
'Microsoft.NET',
'Framework64',
'v4.0.30319',
'csc.exe',
),
path.join(
systemRoot,
'Microsoft.NET',
'Framework',
'v4.0.30319',
'csc.exe',
),
];
let csc = undefined;
for (const p of cscPaths) {
if (p === 'csc.exe') {
const result = spawnSync('where', ['csc.exe'], { stdio: 'ignore' });
if (result.status === 0) {
csc = 'csc.exe';
break;
}
} else if (fs.existsSync(p)) {
csc = p;
break;
}
}
if (!csc) {
console.warn(
'Windows C# compiler (csc.exe) not found. Native sandboxing will attempt to compile on first run.',
);
return;
}
console.log(`Compiling native Windows sandbox helper...`);
// Compile to src
let result = spawnSync(
csc,
[`/out:${srcHelperPath}`, '/optimize', sourcePath],
{
stdio: 'inherit',
},
);
if (result.status === 0) {
console.log('Successfully compiled GeminiSandbox.exe to src');
// Copy to dist if dist exists
const distDir = path.resolve(__dirname, '../dist');
if (fs.existsSync(distDir)) {
const distScriptsDir = path.dirname(distHelperPath);
if (!fs.existsSync(distScriptsDir)) {
fs.mkdirSync(distScriptsDir, { recursive: true });
}
fs.copyFileSync(srcHelperPath, distHelperPath);
console.log('Successfully copied GeminiSandbox.exe to dist');
}
} else {
console.error('Failed to compile Windows sandbox helper.');
}
}
compileWindowsSandbox();