class Request
Faraday request middleware that rewrites the request for the A2A HTTP+JSON/REST protocol binding.
Reads env.request.context[:a2a_operation] to determine the
HTTP verb and path. Interpolates path parameters from the
request body (e.g. id=* placeholders). For GET/DELETE
operations, remaining params become query string parameters.
Sets Content-Type to application/a2a+json for POST requests.
Definitions
def path_param_names(pattern)
Extract name=* placeholder names from a path pattern.
Implementation
def path_param_names(pattern)
pattern.scan(/\{(\w+)(?:=[^}]*)?\}/).flatten
end
def interpolate_path(pattern, params)
Substitute name=* placeholders with values from params.
Pattern names are snake_case (e.g. task_id) but Schema#to_h
produces camelCase keys (e.g. taskId), so we check both.
Implementation
def interpolate_path(pattern, params)
pattern.gsub(/\{(\w+)(?:=[^}]*)?\}/) do
name = $1
camel = snake_to_camel(name)
params[name] || params[name.to_sym] ||
params[camel] || params[camel.to_sym] || ""
end
end
def remove_path_params(pattern, params)
Return params with path-interpolated keys removed.
Implementation
def remove_path_params(pattern, params)
names = path_param_names(pattern)
camel_names = names.map { |n| snake_to_camel(n) }
all_names = (names + camel_names).to_a
params.reject { |k, _| all_names.include?(k.to_s) }
end
def snake_to_camel(str)
"task_id" => "taskId"
Implementation
def snake_to_camel(str)
str.gsub(/_([a-z])/) { $1.upcase }
end