Class: RobotLab::Audit::Hook

Inherits:
Hook
  • Object
show all
Defined in:
lib/robot_lab/audit/hook.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.event_logObject

Returns the value of attribute event_log.



12
13
14
# File 'lib/robot_lab/audit/hook.rb', line 12

def event_log
  @event_log
end

Class Method Details

.after_network_run(ctx) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/robot_lab/audit/hook.rb', line 21

def after_network_run(ctx)
  return unless event_log && current_run_id

  event_log.record_network_run(
    run_id:       current_run_id,
    network_name: ctx.network&.name,
    input:        extract_network_input(ctx.context),
    result:       extract_network_result(ctx.result),
    **error_fields(ctx.error),
    **timing(current_network_started_at)
  )
ensure
  clear_run_id
  clear_network_started_at
end

.after_run(ctx) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/robot_lab/audit/hook.rb', line 41

def after_run(ctx)
  return unless event_log

  record_audit_event(
    'robot_run', ctx, ctx.local.started_at,
    nil, safe_json(ctx.request), safe_json(ctx.response), ctx.error
  )
end

.after_tool_call(ctx) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/robot_lab/audit/hook.rb', line 54

def after_tool_call(ctx)
  return unless event_log

  record_audit_event(
    'tool_call', ctx, ctx.local.started_at,
    ctx.tool_name, safe_json(ctx.tool_args), safe_json(ctx.tool_result), ctx.tool_error
  )
end

.before_network_run(_ctx) ⇒ Object



14
15
16
17
18
19
# File 'lib/robot_lab/audit/hook.rb', line 14

def before_network_run(_ctx)
  return unless event_log

  set_run_id(SecureRandom.uuid)
  set_network_started_at(Time.now.utc)
end

.before_run(ctx) ⇒ Object



37
38
39
# File 'lib/robot_lab/audit/hook.rb', line 37

def before_run(ctx)
  ctx.local.started_at = Time.now.utc
end

.before_tool_call(ctx) ⇒ Object



50
51
52
# File 'lib/robot_lab/audit/hook.rb', line 50

def before_tool_call(ctx)
  ctx.local.started_at = Time.now.utc
end