Class: Kward::RPC::ToolEventNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/rpc/tool_event_normalizer.rb

Overview

Converts tool calls and results into RPC event payloads.

Instance Method Summary collapse

Constructor Details

#initialize(tool_call, content: nil) ⇒ ToolEventNormalizer

Returns a new instance of ToolEventNormalizer.



10
11
12
13
14
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 10

def initialize(tool_call, content: nil)
  @tool_call = tool_call
  @content = content
  @fields = ToolMetadata.normalized_tool_fields(@tool_call)
end

Instance Method Details

#call_payloadObject



16
17
18
19
20
21
22
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 16

def call_payload
  {
    toolCallId: @fields[:toolCallId],
    toolName: @fields[:toolName],
    args: @fields[:args]
  }.compact
end

#execution_record(timestamp: Time.now.utc.iso8601(3)) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 31

def execution_record(timestamp: Time.now.utc.iso8601(3))
  result = normalized_result
  {
    type: "tool_execution_end",
    timestamp: timestamp,
    toolCallId: @fields[:toolCallId],
    toolName: @fields[:toolName],
    args: @fields[:args],
    result: result,
    isError: result[:isError]
  }
end

#result_payloadObject



24
25
26
27
28
29
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 24

def result_payload
  call_payload.merge(
    content: @content,
    result: normalized_result
  )
end