feat(clients): adk+live: close gaps (YAML config import, VertexModel only, MCP tools/call and A2A card live, AP2 v0.2, live features verified, wolfSSL timeout/close status and MSG_NOSIGNAL)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
#include "../AgentDemos.hpp"
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "../../fw/Router.hpp"
|
||||
#include "../../fw/Templates.hpp"
|
||||
#include "google/adk/ap2.h"
|
||||
#include "google/adk/caps.h"
|
||||
#include "google/adk/direct_model.h"
|
||||
#include "google/adk/error.h"
|
||||
#include "google/adk/garden.h"
|
||||
#include "google/adk/runner.h"
|
||||
#include "google/adk/studio.h"
|
||||
#include "google/credentials.h"
|
||||
#include "google/generative.h"
|
||||
#include "google/models/gemini.h"
|
||||
#include "google/models/vertex_model.h"
|
||||
|
||||
namespace molo::example::app {
|
||||
|
||||
@@ -159,11 +162,12 @@ void register_agent_adk_demo(fw::Router& router, Services& services) {
|
||||
throw adk::AdkError::invalid("prompt must be 1..2000 characters");
|
||||
std::shared_ptr<adk::BaseAgent> agent = adk::AgentGarden::instantiate(tmpl, *registry);
|
||||
if (!gclient->configured()) throw google::NotConfiguredError("generativelanguage");
|
||||
bool express = google::Credentials::env().rfind("AQ.", 0) == 0;
|
||||
auto model = std::make_shared<adk::DirectModel>(
|
||||
gclient, google::Generative::default_model(),
|
||||
express ? google::endpoints::vertex_generative()
|
||||
: google::endpoints::generative());
|
||||
// One Gemini adapter: models::VertexModel (express key without a
|
||||
// project, project scoped with GOOGLE_CLOUD_PROJECT).
|
||||
auto gemini = std::make_shared<google::models::Gemini>(
|
||||
gclient, google::models::VertexTarget::from_env());
|
||||
auto model = std::make_shared<google::models::VertexModel>(
|
||||
gemini, google::Generative::default_model());
|
||||
adk::Runner runner(model, sessions);
|
||||
return json_out(runner.run(agent, cid, prompt).to_json());
|
||||
});
|
||||
@@ -189,22 +193,46 @@ void register_agent_adk_demo(fw::Router& router, Services& services) {
|
||||
});
|
||||
});
|
||||
|
||||
// {"intent": {...}, "cart": {...}, "payment": {...}} (cart and payment optional)
|
||||
// AP2 v0.2 mandate bodies, any of: "checkout", "payment" (validated
|
||||
// against "checkout" when both are given), "open_checkout", "open_payment",
|
||||
// "checkout_receipt", "payment_receipt". At least one is required.
|
||||
router.post("/agent/adk/ap2/validate", "agent-adk-ap2", [](fw::Request req) {
|
||||
Json in = parse_body(req);
|
||||
return guarded([&] {
|
||||
const Json* i = in.find("intent");
|
||||
if (!i) throw adk::AdkError::invalid("intent is required");
|
||||
auto intent = adk::ap2::IntentMandate::from_json(*i);
|
||||
intent.validate();
|
||||
if (const Json* c = in.find("cart")) {
|
||||
auto cart = adk::ap2::CartMandate::from_json(*c);
|
||||
cart.validate_against(intent);
|
||||
if (const Json* p = in.find("payment"))
|
||||
adk::ap2::PaymentMandate::from_json(*p).validate_against(cart);
|
||||
Json checked = Json::array();
|
||||
auto mark = [&](const char* name) { checked.push(Json(name)); };
|
||||
std::optional<adk::ap2::CheckoutMandate> checkout;
|
||||
if (const Json* c = in.find("checkout")) {
|
||||
checkout = adk::ap2::CheckoutMandate::from_json(*c);
|
||||
checkout->validate();
|
||||
mark("checkout");
|
||||
}
|
||||
if (const Json* p = in.find("payment")) {
|
||||
auto pay = adk::ap2::PaymentMandate::from_json(*p);
|
||||
if (checkout) pay.validate_against(*checkout);
|
||||
else pay.validate();
|
||||
mark("payment");
|
||||
}
|
||||
if (const Json* o = in.find("open_checkout")) {
|
||||
adk::ap2::OpenCheckoutMandate::from_json(*o).validate();
|
||||
mark("open_checkout");
|
||||
}
|
||||
if (const Json* o = in.find("open_payment")) {
|
||||
adk::ap2::OpenPaymentMandate::from_json(*o).validate();
|
||||
mark("open_payment");
|
||||
}
|
||||
if (const Json* r = in.find("checkout_receipt")) {
|
||||
adk::ap2::Receipt::from_json(*r, false).validate();
|
||||
mark("checkout_receipt");
|
||||
}
|
||||
if (const Json* r = in.find("payment_receipt")) {
|
||||
adk::ap2::Receipt::from_json(*r, true).validate();
|
||||
mark("payment_receipt");
|
||||
}
|
||||
if (checked.as_array().empty()) throw adk::AdkError::invalid("no mandate or receipt given");
|
||||
Json out = Json::object();
|
||||
out.set("valid", Json(true));
|
||||
out.set("checked", checked);
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user