Class: Kward::RPC::ToolEventNormalizer
- Inherits:
-
Object
- Object
- Kward::RPC::ToolEventNormalizer
- Defined in:
- lib/kward/rpc/tool_event_normalizer.rb
Overview
Converts tool calls and results into RPC event payloads.
Instance Method Summary collapse
- #call_payload ⇒ Object
- #execution_record(timestamp: Time.now.utc.iso8601(3)) ⇒ Object
-
#initialize(tool_call, content: nil, tool_registry: nil) ⇒ ToolEventNormalizer
constructor
A new instance of ToolEventNormalizer.
- #result_payload ⇒ Object
- #update_payload(elapsed_ms: nil) ⇒ Object
Constructor Details
#initialize(tool_call, content: nil, tool_registry: nil) ⇒ ToolEventNormalizer
Returns a new instance of ToolEventNormalizer.
10 11 12 13 14 15 |
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 10 def initialize(tool_call, content: nil, tool_registry: nil) @tool_call = tool_call @content = content @tool_registry = tool_registry @fields = ToolMetadata.normalized_tool_fields(@tool_call) end |
Instance Method Details
#call_payload ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 17 def call_payload { toolCallId: @fields[:toolCallId], toolName: @fields[:toolName], args: @fields[:args], metadata: }.compact end |
#execution_record(timestamp: Time.now.utc.iso8601(3)) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 39 def execution_record(timestamp: Time.now.utc.iso8601(3)) result = normalized_result { type: "tool_execution_end", timestamp: , toolCallId: @fields[:toolCallId], toolName: @fields[:toolName], args: @fields[:args], result: result, isError: result[:isError] } end |
#result_payload ⇒ Object
32 33 34 35 36 37 |
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 32 def result_payload call_payload.merge( content: @content, result: normalized_result ) end |
#update_payload(elapsed_ms: nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/kward/rpc/tool_event_normalizer.rb', line 26 def update_payload(elapsed_ms: nil) payload = call_payload.merge(delta: { content: @content.to_s }) payload[:elapsedMs] = elapsed_ms if elapsed_ms payload end |