Module: Kward::RPC::ToolMetadata
- Defined in:
- lib/kward/rpc/tool_metadata.rb
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
75 76 77 |
# File 'lib/kward/rpc/tool_metadata.rb', line 75 def error_result?(text) text.to_s.start_with?("Error:", "Declined:", "Cancelled.") end |
.extract_unified_diff(text) ⇒ Object
70 71 72 73 |
# File 'lib/kward/rpc/tool_metadata.rb', line 70 def extract_unified_diff(text) index = text.to_s.index(/^--- /) index ? text.to_s[index..] : nil end |
.normalize_bash_args(args) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/kward/rpc/tool_metadata.rb', line 61 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kward/rpc/tool_metadata.rb', line 36 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
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kward/rpc/tool_metadata.rb', line 23 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
19 20 21 |
# File 'lib/kward/rpc/tool_metadata.rb', line 19 def normalize_tool_name(name) ToolCall.normalized_name(name) end |
.normalize_write_args(args) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/kward/rpc/tool_metadata.rb', line 52 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
9 10 11 12 13 14 15 16 17 |
# File 'lib/kward/rpc/tool_metadata.rb', line 9 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 |