feat(clients): sandbox: data plane (JWT proxy, CDP WebSocket), operations, SDK chunk shapes

Data plane per the computer use quickstart and SDK 2.6.0 source: signJwt
minted JWT, /cdp /tabs /cdp_ws_endpoint over HTTP with routing headers, CDP
over the live WsClient with capped reconnect. Operations methods wrapped,
input/output chunk shapes settled from the SDK, ComputerUse moved off execute.
Execution paths remain verified by Discovery, docs and SDK only.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 05:30:44 +02:00
co-authored by Claude Sonnet 5.5
parent 29d775a923
commit 1c3fbe1899
33 changed files with 3031 additions and 185 deletions
+34 -9
View File
@@ -1,34 +1,50 @@
#pragma once
// Computer use: browser actions in a computer use sandbox (navigate, click,
// type, screenshot). Docs describe the action set and that each action is a
// Chrome DevTools Protocol command ({"command","params"}); they send it to
// the sandbox data plane with a signed JWT. This class carries the same CDP
// commands as an application/json Chunk through sandboxEnvironments.execute,
// the only sandbox call in the REST surface. Whether the server routes that
// Chunk to the browser is unverified (SPEC Unverified).
// type, screenshot) over the sandbox data plane, as Google documents it:
// POST /cdp with {"command": "<CDP method>", "params": {...}} and a signed
// JWT (see data_plane.h). The commands are Chrome DevTools Protocol names.
// Tabs and the CDP WebSocket are exposed through the same connector.
#include <memory>
#include <string>
#include "google/sandbox/cdp_session.h"
#include "google/sandbox/data_plane_connector.h"
#include "google/sandbox/sandbox_service.h"
namespace molo::google::sandbox {
struct ActionResult {
clients::body::Json result; // The CDP result object ({} when none).
ExecutionResult exec; // Text, files and skip reasons of the reply.
int status = 0; // HTTP status of the data plane call.
std::string screenshot_png; // Raw PNG bytes, set by screenshot() only.
};
class ComputerUse : public SandboxService {
public:
explicit ComputerUse(std::shared_ptr<GoogleClient> client);
// connector null: one built from DataPlaneOptions::from_env().
explicit ComputerUse(std::shared_ptr<GoogleClient> client,
std::shared_ptr<DataPlaneConnector> connector = nullptr);
ActionResult navigate(const std::string& sandbox_name, const std::string& url) const;
// Left click at viewport coordinates: mousePressed then mouseReleased.
ActionResult click(const std::string& sandbox_name, int x, int y) const;
ActionResult type_text(const std::string& sandbox_name, const std::string& text) const;
ActionResult screenshot(const std::string& sandbox_name) const;
// Any CDP command (Domain.method) on the active tab.
ActionResult command(const std::string& sandbox_name, const std::string& cdp_method,
const clients::body::Json& params) const;
// Data plane routes.
clients::body::Json health(const std::string& sandbox_name) const;
clients::body::Json list_tabs(const std::string& sandbox_name) const;
clients::body::Json create_tab(const std::string& sandbox_name) const;
clients::body::Json activate_tab(const std::string& sandbox_name, const std::string& tab_id) const;
clients::body::Json close_tab(const std::string& sandbox_name, const std::string& tab_id) const;
// The CDP WebSocket (not yet connected; call connect()).
std::unique_ptr<CdpSession> open_cdp(const std::string& sandbox_name,
CdpOptions options = {}) const;
static void validate_url(const std::string& url); // http(s) only, capped
static void validate_point(int x, int y);
@@ -38,10 +54,19 @@ class ComputerUse : public SandboxService {
static clients::body::Json navigate_params(const std::string& url);
static clients::body::Json mouse_params(const char* type, int x, int y);
static clients::body::Json insert_text_params(const std::string& text);
static clients::body::Json screenshot_params();
// Pulls the result object out of a /cdp reply: {"result": {...}} or the
// object itself (the reply shape is unverified, SPEC section 7).
static clients::body::Json result_of(const DataPlaneReply& reply);
// Base64 PNG in "data" of a captureScreenshot result; empty when absent or
// over SandboxCaps::kMaxScreenshotBytes.
static std::string screenshot_of(const clients::body::Json& result);
private:
ActionResult send(const std::string& sandbox_name, const std::string& command,
ActionResult send(const std::string& sandbox_name, const std::string& cdp_method,
const clients::body::Json& params) const;
std::shared_ptr<DataPlaneConnector> connector_;
};
} // namespace molo::google::sandbox