Module em_filter_http

em_filter_http — Cowboy handler for the direct agent query endpoint.

Behaviours: cowboy_handler.

Authors: Steve Roques.

Description

em_filter_http — Cowboy handler for the direct agent query endpoint.

Route: POST /agent/query

This handler is the network entry point for Emquest's em_pop-based direct dispatch. When Emquest finds this agent via kvex similarity search and decides to query it directly, the HTTP request lands here.

Request body (JSON):
   {"query": "user query text"}
Success response — HTTP 200:
   {"results": [... agent handler output ...]}

where <agent handler output> is whatever handler:handle/2 returns (a JSON-encoded binary), decoded once so it is properly nested in the response JSON rather than appearing as an escaped string.

Error responses: 400 — malformed JSON or missing "query" field 500 — internal handler error or gen_server call timeout

The Cowboy route options map MUST contain: server => atom() — registered name of the em_filter_server (always <agent>_server for index 1)

Function Index

init/2Handle one POST /agent/query request.

Function Details

init/2

init(Req0, State) -> any()

Handle one POST /agent/query request.

Reads the full body, extracts the "query" field, calls the local agent gen_server synchronously (30 s timeout), and returns the result as JSON.

The handler's raw output is decoded before embedding in the response so that the result is a proper JSON value rather than an escaped string:

  handler returns:  <<"[{\"url\":\"...\"}]">>   (binary)
  response body:    {"results": [{"url": "..."}]}


Generated by EDoc