Create Ava web server module

t-272.2·WorkTask·
·
·
Parent:t-272·Created2 months ago·Updated2 months ago

Dependencies

Description

Edit

Create a lightweight Warp web server for serving the trace viewer.

Context

This is a new module that will run alongside the Telegram bot. It serves HTML pages and JSON API for viewing tool traces. The server should be minimal - just enough to serve traces.

Module Location

Create: Omni/Ava/Web.hs

Dependencies

Use existing dependencies from the project:

  • warp (web server)
  • wai (web application interface)
  • http-types (status codes, headers)
  • aeson (JSON)
  • text, bytestring

Check Omni/Bild.nix for available Haskell packages.

Endpoints

GET /trace/:id

Returns full HTML page with trace data embedded. Use a simple HTML template (can be a Text string in Haskell, or load from file).

Response: HTML page (Content-Type: text/html)

  • 200 OK with trace viewer page
  • 404 Not Found if trace doesn't exist

GET /api/trace/:id

Returns raw trace data as JSON for dynamic loading.

Response: { "id": "trace-abc123", "created_at": "2025-12-20T00:00:00Z", "tool_name": "python_exec", "input": {...}, "output": {...}, "duration_ms": 1234 }

  • 200 OK with JSON
  • 404 Not Found

GET /health

Simple health check for monitoring.

Response: 200 OK, body: "ok"

Configuration

  • Port: Read from AVA_WEB_PORT env var, default 8079
  • DB path: Read from AVA_DATA_ROOT env var + "/ava.db"

Integration with Ava Main

Export a function: startWebServer :: Int -> FilePath -> IO () Call this from Omni/Ava.hs main, running in a separate thread (forkIO).

Example Structure

module Omni.Ava.Web where

import qualified Network.Wai as Wai import qualified Network.Wai.Handler.Warp as Warp import qualified Network.HTTP.Types as HTTP

startWebServer :: Int -> FilePath -> IO () startWebServer port dbPath = Warp.run port (app dbPath)

app :: FilePath -> Wai.Application app dbPath request respond = do case Wai.pathInfo request of ["trace", traceId] -> serveTracePage dbPath traceId respond ["api", "trace", traceId] -> serveTraceJson dbPath traceId respond ["health"] -> respond $ Wai.responseLBS HTTP.status200 [] "ok" _ -> respond $ Wai.responseLBS HTTP.status404 [] "Not found"

Testing

Add basic tests for routing and 404 handling. Can use wai-extra for testing.

Timeline (1)

🔄[human]Open → Done2 months ago