mirror of
https://github.com/hanzo-cpp/sdk.git
synced 2026-11-20 19:55:32 +00:00
This repo carried a refusal — the seam, the CI gates and the template overrides,
but no client, because no openapi-generator 7.14.0 C++ generator emitted a tree
that compiled from hanzo.yaml. That was true and is no longer.
WHAT CHANGED, in the order it mattered:
* openapi-generator 7.24.0 instead of 7.14.0. The 10 translation units the
previous measurement could not fix were two defects in the generator's own
Java type resolution, and mustache cannot reach either — it interpolates the
strings resolution produces, it cannot recompute a type. 9 TUs were
`additionalProperties: {$ref: <array-typed schema>}` dropping the aliased
array's element type (`std::map<utility::string_t, std::vector>`, never
valid C++); 1 was an integer-backed enum declared over utility::string_t and
defined over int32_t. Both are fixed upstream in 7.24.0. The floor is stated
once, in scripts/generate.sh, with the measurement — a row in sdks.yaml says
one version for EVERY language, and raising the fleet pin would rewrite
every other client's committed output.
* The four template overrides re-derived from 7.24.0 stock rather than merged
onto it, so a future bump re-derives them again. 7.24.0 fixed two of the
five defect classes the 7.14.0 overrides carried; it also has two of its own
in the enum path, both template-shaped: isPrimitiveType and isEnum are not
exclusive, so an integer-backed enum declared its setter twice and defined
it once, and the conversion helpers disagreed between header and source.
* -DmaxYamlCodePoints. hanzo.yaml crossed snakeyaml's 3145728 code-point
ceiling (3,654,449 at spec 1bac13f) and the failure does not say so: the
parser logs SnakeException, silently falls through to the SWAGGER 2.0 compat
reader, and dies with "Issues with the OpenAPI input", which reads like a
malformed spec. The document validates at 0 errors and 0 warnings. This is
fleet-wide, so it is also set in hanzoai/openapi's generate.py, once, where
every language picks it up.
WHAT IS HERE NOW: include/hanzo (2377 headers, 264 API classes, 2103 models) and
src (2376 sources), the hanzo::hanzo CMake target with its install/export set,
and the six canonical flows from hanzoai/openapi's flows.yaml — hello, chat,
money, store, agent, tools — each compiled by the examples gate, resolving
HANZO_API_KEY / HANZO_BASE_URL / HANZO_ORG_ID in ONE place rather than six.
The generator's CMakeLists.txt and Config.cmake.in are dropped before the tree
lands: the target name, the export set and HANZO_BUILD_EXAMPLES are this repo's
contract with a consumer, not a generator artifact.
CI is wired and UNEXERCISED — hanzoai/ci defaults to the hanzo-build-linux-amd64
arc pool, which has zero registered runners, so a run queues rather than
executes. Every number above is from a clean-clone local build on aarch64
Ubuntu 24.04, g++ 13.3, cmake 3.28.3, cpprestsdk 2.10.19, against
hanzoai/openapi@1bac13fb75.
82 lines
2.8 KiB
C++
82 lines
2.8 KiB
C++
#include "hanzo.h"
|
|
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
|
|
#include "hanzo/ApiConfiguration.h"
|
|
#include "hanzo/ApiException.h"
|
|
|
|
namespace hanzo {
|
|
namespace examples {
|
|
namespace {
|
|
|
|
utility::string_t env(const char* name, const utility::string_t& fallback) {
|
|
const char* value = std::getenv(name);
|
|
if (value == nullptr || *value == '\0') {
|
|
return fallback;
|
|
}
|
|
return utility::conversions::to_string_t(value);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
utility::string_t baseUrl() {
|
|
return env("HANZO_BASE_URL", utility::conversions::to_string_t("https://api.hanzo.ai"));
|
|
}
|
|
|
|
utility::string_t model() {
|
|
return env("HANZO_MODEL", utility::conversions::to_string_t("zen-1"));
|
|
}
|
|
|
|
std::shared_ptr<api::ApiClient> client() {
|
|
const char* key = std::getenv("HANZO_API_KEY");
|
|
if (key == nullptr || *key == '\0') {
|
|
throw std::runtime_error("HANZO_API_KEY is not set");
|
|
}
|
|
|
|
auto config = std::make_shared<api::ApiConfiguration>();
|
|
config->setBaseUrl(baseUrl());
|
|
config->setUserAgent(utility::conversions::to_string_t("hanzo-cpp-sdk/examples"));
|
|
|
|
// cpp-restsdk emits header handling for apiKey schemes only, so an http
|
|
// bearer scheme — which is what hanzo.yaml declares globally — has to be
|
|
// set as a default header. Once, here, rather than in six flows.
|
|
config->getDefaultHeaders()[utility::conversions::to_string_t("Authorization")] =
|
|
utility::conversions::to_string_t("Bearer ") + utility::conversions::to_string_t(key);
|
|
|
|
// Harmless where the tenant comes from the token, required where it does
|
|
// not: /v1/kv and /v1/agents answer 403 "X-Org-Id required" without it.
|
|
const utility::string_t org = env("HANZO_ORG_ID", utility::string_t());
|
|
if (!org.empty()) {
|
|
config->getDefaultHeaders()[utility::conversions::to_string_t("X-Org-Id")] = org;
|
|
}
|
|
|
|
return std::make_shared<api::ApiClient>(config);
|
|
}
|
|
|
|
void print(const utility::string_t& label, const utility::string_t& value) {
|
|
std::cout << utility::conversions::to_utf8string(label) << " "
|
|
<< utility::conversions::to_utf8string(value) << std::endl;
|
|
}
|
|
|
|
void print(const utility::string_t& label, int64_t value) {
|
|
std::cout << utility::conversions::to_utf8string(label) << " " << value << std::endl;
|
|
}
|
|
|
|
int fail(const utility::string_t& what, const std::exception& e) {
|
|
std::cerr << utility::conversions::to_utf8string(what) << " failed: " << e.what() << std::endl;
|
|
if (const auto* apiError = dynamic_cast<const api::ApiException*>(&e)) {
|
|
if (auto body = apiError->getContent()) {
|
|
std::stringstream text;
|
|
text << body->rdbuf();
|
|
std::cerr << " body: " << text.str() << std::endl;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
} // namespace examples
|
|
} // namespace hanzo
|