Class: A2A::Server::Triage

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/server/triage.rb

Overview

Rack middleware that resolves which A2A operation a request targets.

Reads the raw protocol data left in env by the binding middleware (JSON-RPC method name or HTTP verb + path), looks up the matching Proto::Operation, wraps the request body into a Schema::Definition, and sets env keys for downstream consumption by the Dispatcher.

Env keys read:

"a2a.json_rpc_method" — set by Bindings::JsonRpc
"a2a.verb"            — set by Bindings::Rest
"a2a.path"            — set by Bindings::Rest
"a2a.body"            — set by either binding

Env keys set:

"a2a.operation"       — operation name string (e.g. "SendMessage")
"a2a.proto_operation" — Proto::Operation instance
"a2a.request"         — Schema::Definition instance (validated request)

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Triage

Returns a new instance of Triage.



27
28
29
# File 'lib/a2a/server/triage.rb', line 27

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/a2a/server/triage.rb', line 31

def call(env)
  op = resolve_operation(env)

  unless op
    return [404, { "content-type" => "text/plain" }, ["Unknown operation"]]
  end

  env["a2a.operation"]       = op.name
  env["a2a.proto_operation"] = op

  body = env["a2a.body"] || {}

  # For REST, merge extracted path params into the body.
  if env["a2a.path"]
    path_params = extract_path_params(op.rest_path, env["a2a.path"])
    body = body.merge(path_params)
  end

  if op.request_schema
    env["a2a.request"] = op.request_schema.new(body)
  end

  @app.call(env)
end