Class: Kward::RPC::ToolEventNormalizer

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

Instance Method Summary collapse

Constructor Details

#initialize(tool_call, content: nil) ⇒ ToolEventNormalizer

Returns a new instance of ToolEventNormalizer.



7
8
9
10
11
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 7

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



13
14
15
16
17
18
19
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 13

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

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



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 28

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



21
22
23
24
25
26
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 21

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