Module: Kward::RPC::ToolMetadata
- Defined in:
- lib/kward/rpc/tool_metadata.rb
Overview
Builds compact metadata for RPC tool-call display.
Class Method Summary collapse
- .error_result?(text) ⇒ Boolean
- .extract_unified_diff(text) ⇒ Object
- .normalize_bash_args(args) ⇒ Object
- .normalize_edit_args(args) ⇒ Object
- .normalize_tool_args(name, args) ⇒ Object
- .normalize_tool_name(name) ⇒ Object
- .normalize_write_args(args) ⇒ Object
- .normalized_tool_fields(tool_call) ⇒ Object
Class Method Details
.error_result?(text) ⇒ Boolean
78 79 80 |
# File 'lib/kward/rpc/tool_metadata.rb', line 78 def error_result?(text) text.to_s.start_with?("Error:", "Declined:", "Cancelled.") end |
.extract_unified_diff(text) ⇒ Object
73 74 75 76 |
# File 'lib/kward/rpc/tool_metadata.rb', line 73 def extract_unified_diff(text) index = text.to_s.index(/^--- /) index ? text.to_s[index..] : nil end |
.normalize_bash_args(args) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/kward/rpc/tool_metadata.rb', line 64 def normalize_bash_args(args) result = {} command = ToolCall.value(args, :command) timeout = ToolCall.value(args, :timeout) || ToolCall.value(args, :timeout_seconds) || Workspace::DEFAULT_COMMAND_TIMEOUT_SECONDS result[:command] = command if command result[:timeout] = timeout if timeout result end |
.normalize_edit_args(args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/kward/rpc/tool_metadata.rb', line 39 def normalize_edit_args(args) result = {} path = ToolCall.value(args, :path) result[:path] = path if path edits = Array(ToolCall.value(args, :edits)).filter_map do |edit| next unless edit.is_a?(Hash) { oldText: ToolCall.value(edit, :oldText) || ToolCall.value(edit, :old_text), newText: ToolCall.value(edit, :newText) || ToolCall.value(edit, :new_text) }.compact end result[:edits] = edits if edits.any? result end |
.normalize_tool_args(name, args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kward/rpc/tool_metadata.rb', line 26 def normalize_tool_args(name, args) case name.to_s when "edit_file", "edit" normalize_edit_args(args) when "write_file", "write" normalize_write_args(args) when "run_shell_command", "bash" normalize_bash_args(args) else ToolCall.camelize_args(args) end end |
.normalize_tool_name(name) ⇒ Object
22 23 24 |
# File 'lib/kward/rpc/tool_metadata.rb', line 22 def normalize_tool_name(name) ToolCall.normalized_name(name) end |
.normalize_write_args(args) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/kward/rpc/tool_metadata.rb', line 55 def normalize_write_args(args) result = {} path = ToolCall.value(args, :path) content = ToolCall.value(args, :content) result[:path] = path if path result[:content] = content if content result end |
.normalized_tool_fields(tool_call) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/kward/rpc/tool_metadata.rb', line 12 def normalized_tool_fields(tool_call) raw_name = ToolCall.name(tool_call) args = ToolCall.arguments(tool_call) { toolCallId: ToolCall.id(tool_call), toolName: normalize_tool_name(raw_name) || raw_name, args: normalize_tool_args(raw_name, args) }.compact end |