Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Merge branch 'main' into jonathan/fire-engine-webhook

Nicolas48b8e7515375
diff --cc apps/api/src/controllers/v2/browser.ts
index 0aef4427f,5139ca875..b484c7d37
--- a/apps/api/src/controllers/v2/browser.ts
+++ b/apps/api/src/controllers/v2/browser.ts
@@@ -503,52 -447,3 +448,43 @@@ export async function browserListContro
})),
});
}
+
+export async function browserWebhookDestroyedController(
+ req: Request,
+ res: Response,
+) {
+ const logger = _logger.child({
+ module: "api/v2",
+ method: "browserWebhookDestroyedController",
+ });
+
+ // Validate fire-engine secret
+ const secret = req.headers["x-fire-engine-secret"];
+ if (!secret || secret !== process.env.FIRE_ENGINE_WEBHOOK_SECRET) {
+ return res.status(401).json({ error: "Unauthorized" });
+ }
+
+ const { browserId } = req.body as { browserId?: string };
+ if (!browserId) {
+ return res.status(400).json({ error: "Missing browserId" });
+ }
+
+ logger.info("Received destroyed webhook from fire-engine", { browserId });
+
+ const session = await getBrowserSessionByBrowserId(browserId);
+ if (!session) {
+ logger.warn("No session found for destroyed webhook", { browserId });
+ return res.status(200).json({ ok: true });
+ }
+
+ if (session.status === "destroyed") {
+ logger.info("Session already destroyed", { sessionId: session.id, browserId });
+ return res.status(200).json({ ok: true });
+ }
+
- // Destroy sandbox workspace if still active
- try {
- const client = getSandboxClient();
- const workspace = reconstructWorkspace(client, session);
- await workspace.destroy().catch(() => {});
- } catch (err) {
- logger.warn("Error destroying sandbox for webhook", { error: err, sessionId: session.id });
- }
-
+ await updateBrowserSessionStatus(session.id, "destroyed");
+
+ logger.info("Session marked as destroyed via webhook", { sessionId: session.id, browserId });
+
+ return res.status(200).json({ ok: true });
+}