mcp/cdp: fix inactivity timeout

- Fixed CDP inactivity timeout by resetting it when the browser is busy (loading or executing macrotasks).
- Removed the placeholder screenshot tool.
- Refactored MCP tool schemas to constants to avoid duplication.
This commit is contained in:
Adrià Arrufat
2026-04-01 13:51:46 +02:00
parent 58fc60d669
commit fffa8b6d4b
2 changed files with 70 additions and 137 deletions

View File

@@ -330,6 +330,11 @@ pub const Client = struct {
ms_remaining = self.ws.timeout_ms;
},
.done => {
if (self.isBusy()) {
last_message = milliTimestamp(.monotonic);
ms_remaining = self.ws.timeout_ms;
continue;
}
const now = milliTimestamp(.monotonic);
const elapsed = now - last_message;
if (elapsed >= ms_remaining) {
@@ -343,6 +348,24 @@ pub const Client = struct {
}
}
fn isBusy(self: *const Client) bool {
if (self.http.active > 0 or self.http.intercepted > 0) {
return true;
}
const cdp = switch (self.mode) {
.cdp => |*c| c,
.http => return false,
};
const session = cdp.browser.session orelse return false;
if (session.browser.hasBackgroundTasks() or session.browser.msToNextMacrotask() != null) {
return true;
}
return false;
}
fn blockingReadStart(ctx: *anyopaque) bool {
const self: *Client = @ptrCast(@alignCast(ctx));
self.ws.setBlocking(true) catch |err| {