#pragma once // Shared plumbing of the provider classes: building a Gateway over one // ApiClient per host, and small Json helpers so each provider file only holds // what is specific to the provider. #include #include #include #include #include "clients/transport.h" #include "llm/api_client.h" #include "vendors/retrieval/gateway.h" namespace molo::retrieval { struct HostSpec { std::string host; // name used in CallRow::host std::string base_url; // https://..., no trailing slash }; using TransportFactory = std::function()>; // One ApiClient per host. `factory` null = real HTTPS. `key` empty = look up // base.key_env through llm::Config (empty there too = not configured). std::shared_ptr make_gateway(const CallTable& table, const llm::ApiClientConfig& base, const std::vector& hosts, std::string key, const TransportFactory& factory); // A host name from the data plane of a database must be a bare https host. void check_host(const std::string& vendor, const std::string& host); class Provider { public: explicit Provider(std::shared_ptr gateway) : gw_(std::move(gateway)) {} virtual ~Provider() = default; Gateway& gateway() const { return *gw_; } std::shared_ptr shared_gateway() const { return gw_; } bool configured() const { return gw_->configured(); } const CallTable& table() const { return gw_->table(); } protected: std::shared_ptr gw_; }; // Json helpers struct J { static Json strings(const std::vector& v); static Json object() { return Json::object(); } static std::string str(const Json& doc, const std::string& key, const std::string& fallback = ""); static double num(const Json& doc, const std::string& key, double fallback = 0); static bool has_array(const Json& doc, const std::string& key); static const Json* at(const Json& doc, const std::string& key); static std::vector floats(const Json& arr); // The array at `key`, or an empty static array. static const Json::Array& array(const Json& doc, const char* key); }; } // namespace molo::retrieval