feat(clients): google cloud voice: generic client, TTS, STT, Gemini audio, live voice page
src/google: GoogleClient over molo::clients (key in x-goog-api-key, never in
URLs), Service base, TextToSpeech, SpeechToText, Generative (replies, audio
in, audio out), Recognizer/Synthesizer seams with cloud, gemini and vertex
backends, VoicePipeline with bounded history. Example: /voice live
conversation page, /voice/{say,hear,turn,reset}, /google/status. Keys load
from env, .env.json.local, .env.json. Paid routes are excluded from locust.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#include "google/client.h"
|
||||
|
||||
#include "clients/transports/http_transport.h"
|
||||
#include "google/credentials.h"
|
||||
|
||||
namespace molo::google {
|
||||
|
||||
namespace {
|
||||
clients::ClientConfig make_config(std::shared_ptr<clients::Auth> auth) {
|
||||
clients::ClientConfig config;
|
||||
config.auth = std::move(auth);
|
||||
config.persist_cookies = false;
|
||||
return config;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
GoogleClient::GoogleClient(std::unique_ptr<clients::Transport> transport,
|
||||
std::shared_ptr<clients::Auth> auth)
|
||||
: client_(std::move(transport), make_config(auth)),
|
||||
configured_(auth != nullptr) {}
|
||||
|
||||
std::shared_ptr<GoogleClient> GoogleClient::from_env() {
|
||||
return std::make_shared<GoogleClient>(
|
||||
std::make_unique<clients::transports::HttpTransport>(),
|
||||
Credentials::from_env());
|
||||
}
|
||||
|
||||
clients::body::Json GoogleClient::post_json(const ServiceEndpoint& service,
|
||||
const std::string& path,
|
||||
const clients::body::Json& body) {
|
||||
if (!configured_) throw NotConfiguredError(service.name);
|
||||
try {
|
||||
return finish(service, client_.post_json_blocking(
|
||||
service.base_url + path, body));
|
||||
} catch (const GoogleError&) {
|
||||
throw;
|
||||
} catch (const std::exception& e) {
|
||||
throw GoogleError(502, "UNAVAILABLE", e.what(), service.name);
|
||||
}
|
||||
}
|
||||
|
||||
clients::body::Json GoogleClient::get_json(const ServiceEndpoint& service,
|
||||
const std::string& path) {
|
||||
if (!configured_) throw NotConfiguredError(service.name);
|
||||
try {
|
||||
return finish(service, client_.get_blocking(service.base_url + path));
|
||||
} catch (const GoogleError&) {
|
||||
throw;
|
||||
} catch (const std::exception& e) {
|
||||
throw GoogleError(502, "UNAVAILABLE", e.what(), service.name);
|
||||
}
|
||||
}
|
||||
|
||||
clients::body::Json GoogleClient::finish(
|
||||
const ServiceEndpoint& service, const clients::ClientResponse& response) {
|
||||
if (!response.is_success()) throw error_from_response(service.name, response);
|
||||
try {
|
||||
return response.json();
|
||||
} catch (const std::exception& e) {
|
||||
throw GoogleError(502, "BAD_RESPONSE", e.what(), service.name);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace molo::google
|
||||
Reference in New Issue
Block a user