#include "amduatd_ui.h" #include "amduat/asl/artifact_io.h" #include "amduat/asl/asl_store_fs.h" #include "amduat/asl/asl_store_fs_meta.h" #include "amduat/asl/ref_derive.h" #include #include #include #include bool amduatd_http_send_text(int fd, int code, const char *reason, const char *text, bool head_only); bool amduatd_http_send_status(int fd, int code, const char *reason, const char *content_type, const uint8_t *body, size_t body_len, bool head_only); static const char k_amduatd_ui_html[] = "\n" "\n" "\n" " \n" " \n" " amduatd — Concept editor\n" " \n" "\n" "\n" "
\n" "
\n" "
\n" "
\n" " amduatd\n" "
\n" " \n" "
\n" "
\n" "
\n" "

Concept editor + PEL runner

\n" "

Load shows the latest materialized bytes; Save uploads a new artifact and publishes a new version. Use the runner to execute PEL programs against stored artifacts.

\n" "
\n" " Open editor\n" " Run program\n" "
\n" "
\n" "
\n" "
\n" "
\n" " \n" " \n" " \n" " \n" "
\n" "
\n" " \n" " \n" " \n" "
\n" " \n" "
\n" " \n" "
\n" "
\n" " \n" " \n" "
\n" "
\n" "\n" "
\n" "
\n" "
Upload bytes (sets program_ref)
\n" "
\n" " \n" " \n" "
\n" "
\n" "
Run
\n" " \n" "
input_refs (comma-separated hex refs or names)
\n" " \n" "
params_ref (optional)
\n" " \n" "
scheme_ref (optional, default dag)
\n" " \n" "
\n" " \n" " /v1/contract\n" " /v1/meta\n" "
\n" "
Response
\n" "
\n"
    "          
\n" "
\n" "
Relations
\n" "
\n" " \n" "
\n" "
\n"
    "          
\n" "
\n" "
\n" "
\n" "
\n" "

About

\n" "

amduatd is a local-first mapping surface over a single ASL store root. This UI is a lightweight editor and runner for concepts and PEL programs.

\n" "
\n" " \n" "
\n" "
\n" " \n" "
\n" "\n" " \n" "\n" "\n"; static void amduatd_ui_path_without_query(const char *path, char *out, size_t cap) { const char *q = NULL; size_t n = 0; if (out == NULL || cap == 0) { return; } out[0] = '\0'; if (path == NULL) { return; } q = strchr(path, '?'); n = q != NULL ? (size_t)(q - path) : strlen(path); if (n >= cap) { n = cap - 1; } memcpy(out, path, n); out[n] = '\0'; } bool amduatd_ui_can_handle(const amduatd_http_req_t *req) { char no_query[1024]; if (req == NULL) { return false; } if (strcmp(req->method, "GET") != 0) { return false; } amduatd_ui_path_without_query(req->path, no_query, sizeof(no_query)); return strcmp(no_query, "/v1/ui") == 0; } bool amduatd_ui_handle(amduatd_ctx_t *ctx, const amduatd_http_req_t *req, amduatd_http_resp_t *resp) { amduat_artifact_t artifact; amduat_asl_store_error_t err; if (ctx == NULL || req == NULL || resp == NULL) { return false; } if (!amduatd_ui_can_handle(req)) { return false; } if (ctx->store == NULL || ctx->ui_ref.hash_id == 0 || ctx->ui_ref.digest.data == NULL || ctx->ui_ref.digest.len == 0) { resp->ok = amduatd_http_send_text(resp->fd, 500, "Internal Server Error", "ui not available\n", false); return true; } memset(&artifact, 0, sizeof(artifact)); err = amduat_asl_store_get(ctx->store, ctx->ui_ref, &artifact); if (err == AMDUAT_ASL_STORE_ERR_NOT_FOUND) { resp->ok = amduatd_http_send_text(resp->fd, 404, "Not Found", "not found\n", false); return true; } if (err != AMDUAT_ASL_STORE_OK) { amduat_asl_artifact_free(&artifact); resp->ok = amduatd_http_send_text(resp->fd, 500, "Internal Server Error", "store error\n", false); return true; } if (artifact.bytes.len != 0 && artifact.bytes.data == NULL) { amduat_asl_artifact_free(&artifact); resp->ok = amduatd_http_send_text(resp->fd, 500, "Internal Server Error", "store error\n", false); return true; } resp->ok = amduatd_http_send_status(resp->fd, 200, "OK", "text/html; charset=utf-8", artifact.bytes.data, artifact.bytes.len, false); amduat_asl_artifact_free(&artifact); return true; } bool amduatd_seed_ui_html(amduat_asl_store_t *store, const amduat_asl_store_fs_config_t *cfg, amduat_reference_t *out_ref) { amduat_artifact_t artifact; amduat_asl_store_error_t err; if (out_ref != NULL) { memset(out_ref, 0, sizeof(*out_ref)); } if (store == NULL || cfg == NULL || out_ref == NULL) { return false; } artifact = amduat_artifact(amduat_octets(k_amduatd_ui_html, strlen(k_amduatd_ui_html))); (void)amduat_asl_ref_derive(artifact, cfg->config.encoding_profile_id, cfg->config.hash_id, out_ref, NULL); err = amduat_asl_store_put(store, artifact, out_ref); if (err != AMDUAT_ASL_STORE_OK) { return false; } return true; }