121-call table checked against the OpenAI OpenAPI document, admin-key-only client, destructive guards, WebhookVerifier (Standard Webhooks HMAC-SHA256), demo routes under /ai/openai/admin, local and opt-in live tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
60 lines
2.0 KiB
C++
60 lines
2.0 KiB
C++
#pragma once
|
|
|
|
// List envelopes and bounded page walks.
|
|
//
|
|
// Two paging styles exist in the API:
|
|
// cursor {object:"list", data, first_id, last_id, has_more}, next page is
|
|
// `after=<last_id>` (users, projects, groups, audit logs, ...)
|
|
// token {object:"page", data, has_more, next_page}, next page is
|
|
// `page=<next_page>` (usage and costs)
|
|
// A walk never exceeds AdminCaps::kMaxListPages pages or kMaxWalkItems items;
|
|
// when it stops with more data available, `truncated` is true and `reason`
|
|
// says which ceiling was hit. Truncation is never silent.
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
#include "clients/body/json.h"
|
|
|
|
namespace molo::openai::admin {
|
|
|
|
class Page {
|
|
public:
|
|
explicit Page(clients::body::Json envelope);
|
|
|
|
const clients::body::Json& envelope() const { return envelope_; }
|
|
const clients::body::Json::Array& items() const;
|
|
bool has_more() const { return has_more_; }
|
|
bool token_style() const { return token_style_; }
|
|
const std::string& first_id() const { return first_id_; }
|
|
const std::string& last_id() const { return last_id_; }
|
|
const std::string& next_page() const { return next_page_; }
|
|
// The value to send as `after` (cursor) or `page` (token); "" when done.
|
|
std::string next_cursor() const;
|
|
|
|
private:
|
|
clients::body::Json envelope_;
|
|
bool has_more_ = false;
|
|
bool token_style_ = false;
|
|
std::string first_id_, last_id_, next_page_;
|
|
};
|
|
|
|
struct WalkResult {
|
|
clients::body::Json items = clients::body::Json::array();
|
|
int pages = 0;
|
|
bool truncated = false;
|
|
std::string reason; // "" or "page ceiling" / "item ceiling"
|
|
std::string next_cursor; // resume point when truncated
|
|
|
|
clients::body::Json to_json() const;
|
|
};
|
|
|
|
class PageWalker {
|
|
public:
|
|
// fetch(cursor) returns one envelope; cursor is "" for the first page.
|
|
using Fetch = std::function<clients::body::Json(const std::string& cursor)>;
|
|
static WalkResult walk(const Fetch& fetch, const std::string& start_cursor = "");
|
|
};
|
|
|
|
} // namespace molo::openai::admin
|