diff --git a/src/gateway/routes.c b/src/gateway/routes.c index 514b60f..a850dac 100644 --- a/src/gateway/routes.c +++ b/src/gateway/routes.c @@ -12,6 +12,8 @@ #include "asap/envelope.h" #include "asap/server.h" #include "asap/log.h" +#include "core/agent.h" +#include "core/bootstrap.h" #include "core/config.h" #include "core/memory.h" #include "core/skill.h" @@ -576,6 +578,7 @@ static void handle_asap(http_server_ctx_t *ctx, const char *client_ip, char *resp_json; char *snippet; int rc; + (void)ctx; (void)body_len; /* TODO (Task 6.0): tighten rate limit with X-Forwarded-For proxy awareness. */ if (rate_limit_asap(client_ip, time(NULL))) { @@ -595,8 +598,26 @@ static void handle_asap(http_server_ctx_t *ctx, const char *client_ip, snippet = in.payload ? cJSON_PrintUnformatted(in.payload) : NULL; asap_log_append_in(in.payload_type, in.id, snippet); free(snippet); - memset(&asap_ctx, 0, sizeof asap_ctx); - asap_ctx.cfg = ctx ? ctx->cfg : NULL; + { + size_t tool_count = bootstrap_tool_count(); + agent_tool_t flat_tools[8]; + size_t i; + + for (i = 0; i < tool_count; i++) { + const tool_t *t = bootstrap_tool_at(i); + if (!t) + break; + flat_tools[i].name = t->name; + flat_tools[i].description = t->description; + flat_tools[i].parameters_json = t->parameters_json; + flat_tools[i].execute = t->execute; + } + memset(&asap_ctx, 0, sizeof asap_ctx); + asap_ctx.cfg = bootstrap_get_cfg(); + asap_ctx.provider = bootstrap_get_provider(); + asap_ctx.tools = flat_tools; + asap_ctx.tool_count = tool_count; + } err_msg[0] = '\0'; asap_envelope_init(&out); rc = asap_server_handle(&in, &out, &asap_ctx, err_msg, sizeof err_msg); diff --git a/tests/test_gateway_http.c b/tests/test_gateway_http.c index 5769a73..6a27260 100644 --- a/tests/test_gateway_http.c +++ b/tests/test_gateway_http.c @@ -331,6 +331,33 @@ static int test_asap_missing_fields(void) return 0; } +static int test_asap_task_request(void) +{ + long code; + char *body = NULL; + static const char *req = + "{\"jsonrpc\":\"2.0\",\"method\":\"asap.send\"," + "\"params\":{" + "\"id\":\"01HZABC123\"," + "\"asap_version\":\"2.1\"," + "\"sender\":\"urn:asap:agent:a\"," + "\"recipient\":\"urn:asap:agent:b\"," + "\"payload_type\":\"task.request\"," + "\"payload\":{\"input\":\"hello\"}," + "\"correlation_id\":\"c1\"," + "\"trace_id\":\"t1\"," + "\"timestamp\":\"2026-01-01T00:00:00Z\"" + "},\"id\":42}"; + int r = http_post(gw_url("/asap"), req, &code, &body); + ASSERT(r == 0); + ASSERT(code == 200); + ASSERT(body != NULL); + ASSERT(strstr(body, "task.response") != NULL); + ASSERT(strstr(body, "server missing cfg or provider") == NULL); + free(body); + return 0; +} + static int test_manifest(void) { long code; @@ -677,6 +704,7 @@ int main(int argc, char **argv) if (test_health_wellknown() != 0) { fprintf(stderr, "test_health_wellknown failed\n"); failed++; } if (test_asap_invalid_body() != 0) { fprintf(stderr, "test_asap_invalid_body failed\n"); failed++; } if (test_asap_missing_fields() != 0) { fprintf(stderr, "test_asap_missing_fields failed\n"); failed++; } + if (test_asap_task_request() != 0) { fprintf(stderr, "test_asap_task_request failed\n"); failed++; } if (test_api_asap_log_401() != 0) { fprintf(stderr, "test_api_asap_log_401 failed\n"); failed++; } if (token[0]) { if (test_api_config_get(token) != 0) { fprintf(stderr, "test_api_config_get failed\n"); failed++; }