import type { ElectrobunConfig } from "electrobun";

// CEF mode: opt-in via AGOR_CEF=1. Used for dev/test (E2E automation via CDP,
// WebGL support, unlimited xterm instances). Production uses WebKitGTK (lighter,
// no Chromium dependency, system-native).
const useCEF = process.env.AGOR_CEF === "1";

// When CEF is active, enable remote debugging for CDP-based E2E automation.
const cefFlags: Record<string, string | boolean> | undefined = useCEF
	? {
			"remote-debugging-port": "9222",
			"remote-allow-origins": "*",
			// Reduce CPU: disable GPU acceleration (GLXBadWindow errors on Linux
			// cause continuous error recovery loop in software fallback mode)
			"disable-gpu": true,
			"disable-gpu-compositing": true,
			"disable-software-rasterizer": false,
		}
	: undefined;

export default {
	app: {
		name: "Agent Orchestrator",
		identifier: "dev.agor.orchestrator",
		version: "0.0.1",
	},
	build: {
		bun: {
			entrypoint: "src/bun/index.ts",
		},
		copy: {
			"dist/index.html": "views/mainview/index.html",
			"dist/assets": "views/mainview/assets",
		},
		watchIgnore: ["dist/**"],
		mac: {
			bundleCEF: useCEF,
			bundleWGPU: true,
			...(useCEF && { defaultRenderer: "cef" as const }),
			...(cefFlags && { chromiumFlags: cefFlags }),
		},
		linux: {
			bundleCEF: useCEF,
			bundleWGPU: true,
			...(useCEF && { defaultRenderer: "cef" as const }),
			...(cefFlags && { chromiumFlags: cefFlags }),
		},
		win: {
			bundleCEF: useCEF,
			bundleWGPU: true,
			...(useCEF && { defaultRenderer: "cef" as const }),
			...(cefFlags && { chromiumFlags: cefFlags }),
		},
	},
} satisfies ElectrobunConfig;
