Module: Brute::Rack

Defined in:
lib/brute/rack/adapter.rb

Overview

The mirror image of protocol-rack. Where Protocol::Rack::Adapter wraps a Rack app so an HTTP server can drive it (env in, [status, headers, body] out), Brute::Rack::Adapter wraps a Brute agent so a Rack server can drive it. It is itself a Rack app — call(env) -> [status, headers, body] — so any AgentPipeline drops straight into a config.ru and serves over HTTP behind Falcon/Puma/etc:

# config.ru
agent = Brute::Turn::AgentPipeline.parse_file("examples/agents/brute.ru")
run Brute::Rack::Adapter.for(agent)

$ curl -d 'What files are here?' localhost:9292
$ curl -H 'content-type: application/json' -d '{"prompt":"hi"}' localhost:9292
$ curl 'localhost:9292/?prompt=hi'

The whole job is two pure transforms — the two directions the request named:

env    -> prompt string      (#prompt_from)   the request half
output -> [status, headers, body] (#response_for) the response half

call just wires them together around one agent.start.

Defined Under Namespace

Classes: Adapter