GoogleClient gets every verb and stream_json (SSE and plain JSON), typed Content/Part/Tool/GenerateRequest with the LanguageModel seam, CloudContext resource names, long-running operation polling and pagination, OAuth bearer tokens via GOOGLE_ACCESS_TOKEN. Example scaffold: one stub per agent module under example/app/agent, wildcard builds, locust excludes /voice /google /agent. plans/16-agent-platform.md splits the work into nine modules. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
#pragma once
|
|
|
|
// Long-running operations (google.longrunning) and pagination, shared by
|
|
// every module that creates, deletes or lists Cloud resources.
|
|
|
|
#include <chrono>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "google/client.h"
|
|
|
|
namespace molo::google {
|
|
|
|
struct Operation {
|
|
std::string name; // projects/.../operations/{id}
|
|
bool done = false;
|
|
clients::body::Json response; // Set when done and successful.
|
|
clients::body::Json metadata;
|
|
int error_code = 0; // google.rpc.Status, 0: no error
|
|
std::string error_message;
|
|
|
|
bool failed() const { return error_code != 0; }
|
|
static Operation from_json(const clients::body::Json& doc);
|
|
};
|
|
|
|
struct OperationCaps {
|
|
static constexpr std::chrono::seconds kMaxWait{600};
|
|
static constexpr std::chrono::milliseconds kInterval{2000};
|
|
static constexpr std::size_t kMaxPolls = 400;
|
|
};
|
|
|
|
using Sleeper = std::function<void(std::chrono::milliseconds)>;
|
|
|
|
// Polls GET {name} on the given endpoint until done. Throws GoogleError
|
|
// (status DEADLINE_EXCEEDED) at the cap and (status from the operation, or
|
|
// UNKNOWN) when the operation failed. `sleeper` is injectable for tests.
|
|
Operation wait_operation(GoogleClient& client, const ServiceEndpoint& endpoint,
|
|
const std::string& operation_name,
|
|
const Sleeper& sleeper = nullptr);
|
|
|
|
// Follows nextPageToken. `path` may already hold a query string. Collects
|
|
// `items_key` arrays into one Json array; stops at max_pages (default 100).
|
|
clients::body::Json list_all(GoogleClient& client, const ServiceEndpoint& endpoint,
|
|
const std::string& path, const std::string& items_key,
|
|
std::size_t max_pages = 100);
|
|
|
|
} // namespace molo::google
|