Class: ActiveHarness::Payload

Inherits:
Object
  • Object
show all
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.meta[: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

Instance Method Summary collapse

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   = options
  @meta      = meta
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



36
37
38
# File 'lib/active_harness/payload.rb', line 36

def context
  @context
end

#inputObject

Returns the value of attribute input.



36
37
38
# File 'lib/active_harness/payload.rb', line 36

def input
  @input
end

#languageObject

Returns the value of attribute language.



36
37
38
# File 'lib/active_harness/payload.rb', line 36

def language
  @language
end

#metaObject

Returns the value of attribute meta.



36
37
38
# File 'lib/active_harness/payload.rb', line 36

def meta
  @meta
end

#optionsObject

Returns the value of attribute options.



36
37
38
# File 'lib/active_harness/payload.rb', line 36

def options
  @options
end

#translateObject

Returns the value of attribute translate.



36
37
38
# File 'lib/active_harness/payload.rb', line 36

def translate
  @translate
end