From 61bf501b844ce9da5cd1337e2041afd4b1646fb2 Mon Sep 17 00:00:00 2001 From: Will Anderson Date: Wed, 6 May 2026 21:01:46 -0500 Subject: [PATCH] fix: add __http_do_map_to_file runtime primitive el-install.el generates calls to __http_do_map_to_file (HTTP request with JSON headers map, streaming response to file). Add it to both the HAVE_CURL implementation and the no-curl stub section. --- lang/el-compiler/runtime/el_runtime.c | 17 +++++++++++++++++ lang/el-compiler/runtime/el_runtime.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/lang/el-compiler/runtime/el_runtime.c b/lang/el-compiler/runtime/el_runtime.c index 7ef3b6a..df83e95 100644 --- a/lang/el-compiler/runtime/el_runtime.c +++ b/lang/el-compiler/runtime/el_runtime.c @@ -11372,6 +11372,22 @@ el_val_t __http_do_map(el_val_t method, el_val_t url, el_val_t body, if (h) curl_slist_free_all(h); return r; } + +/* __http_do_map_to_file — same as __http_do_map but streams response body + * to a local file path rather than returning it as a string. */ +el_val_t __http_do_map_to_file(el_val_t method, el_val_t url, el_val_t body, + el_val_t headers_json, el_val_t output_path) { + const char* hj = EL_CSTR(headers_json); + struct curl_slist* h = NULL; + if (hj && *hj && *hj == '{') { + el_val_t map = json_parse(EL_STR(hj)); + h = headers_from_map(map); + } + el_val_t r = http_do_to_file(EL_CSTR(method), EL_CSTR(url), EL_CSTR(body), + h, EL_CSTR(output_path)); + if (h) curl_slist_free_all(h); + return r; +} #endif /* HAVE_CURL */ #ifndef HAVE_CURL @@ -11403,4 +11419,5 @@ void llm_register_tool(el_val_t n, el_val_t f) { (void)n; (void)f; } /* __ HTTP stubs (no-curl build) */ el_val_t __http_do(el_val_t m, el_val_t u, el_val_t b, el_val_t h, el_val_t t) { (void)m; (void)u; (void)b; (void)h; (void)t; return _no_curl_err(); } el_val_t __http_do_map(el_val_t m, el_val_t u, el_val_t b, el_val_t h, el_val_t t) { (void)m; (void)u; (void)b; (void)h; (void)t; return _no_curl_err(); } +el_val_t __http_do_map_to_file(el_val_t m, el_val_t u, el_val_t b, el_val_t h, el_val_t p) { (void)m; (void)u; (void)b; (void)h; (void)p; return _no_curl_err(); } #endif /* !HAVE_CURL */ diff --git a/lang/el-compiler/runtime/el_runtime.h b/lang/el-compiler/runtime/el_runtime.h index d2a6b01..c0529ef 100644 --- a/lang/el-compiler/runtime/el_runtime.h +++ b/lang/el-compiler/runtime/el_runtime.h @@ -842,6 +842,8 @@ el_val_t __http_do(el_val_t method, el_val_t url, el_val_t body, el_val_t headers_map, el_val_t timeout_ms); el_val_t __http_do_map(el_val_t method, el_val_t url, el_val_t body, el_val_t headers_json, el_val_t timeout_ms); +el_val_t __http_do_map_to_file(el_val_t method, el_val_t url, el_val_t body, + el_val_t headers_json, el_val_t output_path); /* JSON */ el_val_t __json_array_get(el_val_t json, el_val_t index); -- 2.52.0