Class: ActiveHarness::Payload
- Inherits:
-
Object
- Object
- ActiveHarness::Payload
- Defined in:
- lib/active_harness/payload.rb
Overview
Unified request context — the single object available in every hook.
Passed as the first argument to ALL before/after callbacks and to setup:
setup do |payload|
payload.[:started_at] = Time.now
payload # must return payload
end
before :guards do |payload, input| # input = String
input.strip # return new String
end
after :guards do |payload, result| # result = InputResult
result # return InputResult
end
before :request do |payload, prompt| # prompt = { system:, user: }
prompt # return Hash
end
after :request do |payload, response| # response = ModelResponse
response # return ModelResponse
end
Fields:
input — raw input text; can be modified in +setup+
context — runtime context Hash (e.g. user_id, session data)
language — language hint for guards / responses (e.g. :ru, :en)
translate — callable: translate.(key) → localized string; key format: "scope.agent.message"
typically built by an I18n module: Playground::I18n.translator(locale: language)
options — per-guard static options set at registration time
meta — free-form Hash for user-defined data (timestamps, flags, …)
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#input ⇒ Object
Returns the value of attribute input.
-
#language ⇒ Object
Returns the value of attribute language.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#options ⇒ Object
Returns the value of attribute options.
-
#translate ⇒ Object
Returns the value of attribute translate.
Instance Method Summary collapse
-
#initialize(input:, context: {}, language: nil, translate: nil, options: {}, meta: {}) ⇒ Payload
constructor
A new instance of Payload.
Constructor Details
#initialize(input:, context: {}, language: nil, translate: nil, options: {}, meta: {}) ⇒ Payload
Returns a new instance of Payload.
38 39 40 41 42 43 44 45 |
# File 'lib/active_harness/payload.rb', line 38 def initialize(input:, context: {}, language: nil, translate: nil, options: {}, meta: {}) @input = input @context = context @language = language @translate = translate @options = @meta = end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
36 37 38 |
# File 'lib/active_harness/payload.rb', line 36 def context @context end |
#input ⇒ Object
Returns the value of attribute input.
36 37 38 |
# File 'lib/active_harness/payload.rb', line 36 def input @input end |
#language ⇒ Object
Returns the value of attribute language.
36 37 38 |
# File 'lib/active_harness/payload.rb', line 36 def language @language end |
#meta ⇒ Object
Returns the value of attribute meta.
36 37 38 |
# File 'lib/active_harness/payload.rb', line 36 def @meta end |
#options ⇒ Object
Returns the value of attribute options.
36 37 38 |
# File 'lib/active_harness/payload.rb', line 36 def @options end |
#translate ⇒ Object
Returns the value of attribute translate.
36 37 38 |
# File 'lib/active_harness/payload.rb', line 36 def translate @translate end |