Module: AgUi::RunInput
- Defined in:
- lib/ag_ui/run_input.rb
Overview
Parses and validates the POST body of /agent/:id/run — the RunAgentInput envelope (threadId, runId, messages, tools, context, forwardedProps, state, resume?).
Validation runs against the RAW parsed hash so explicit nulls (state: null, forwardedProps: null) survive — Definition#to_h compacts nils away, which would fail required-field checks. The returned Definition gives snake_case readers and pattern matching over the same data.
input = AgUi::RunInput.parse(request_body)
input.thread_id #=> "t1"
input. #=> [Definition(UserMessage), ...]
Defined Under Namespace
Classes: InvalidError
Constant Summary collapse
- SCHEMA_REF =
"#/definitions/RunAgentInput"
Class Method Summary collapse
Class Method Details
.parse(body) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ag_ui/run_input.rb', line 29 def parse(body) begin raw = JSON.parse(body) rescue JSON::ParserError => e raise InvalidError, "malformed JSON: #{e.}" end unless raw.is_a?(Hash) raise InvalidError, "expected a JSON object, got #{raw.class}" end errors = schema.validate(raw).to_a unless errors.empty? validation_error = Protocol::JsonSchema::ValidationError.new( errors, definition_name: "RunAgentInput", data: raw, ) raise InvalidError, validation_error. end Protocol::JsonSchema["RunAgentInput"].new(raw) end |
.schema ⇒ Object
53 54 55 |
# File 'lib/ag_ui/run_input.rb', line 53 def schema @schema ||= Protocol::JsonSchema.schemer.ref(SCHEMA_REF) end |