ollama_chat 0.0.80 → 0.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +36 -0
  3. data/lib/ollama_chat/chat.rb +14 -2
  4. data/lib/ollama_chat/follow_chat.rb +6 -2
  5. data/lib/ollama_chat/http_handling.rb +63 -0
  6. data/lib/ollama_chat/information.rb +1 -0
  7. data/lib/ollama_chat/oc.rb +5 -0
  8. data/lib/ollama_chat/ollama_chat_config/default_config.yml +1 -0
  9. data/lib/ollama_chat/source_fetching.rb +1 -28
  10. data/lib/ollama_chat/tools/concern.rb +2 -0
  11. data/lib/ollama_chat/tools/copy_to_clipboard.rb +0 -1
  12. data/lib/ollama_chat/tools/directory_structure.rb +1 -1
  13. data/lib/ollama_chat/tools/execute_grep.rb +3 -3
  14. data/lib/ollama_chat/tools/file_context.rb +2 -2
  15. data/lib/ollama_chat/tools/generate_password.rb +2 -3
  16. data/lib/ollama_chat/tools/get_current_weather.rb +6 -11
  17. data/lib/ollama_chat/tools/get_cve.rb +9 -13
  18. data/lib/ollama_chat/tools/get_endoflife.rb +4 -4
  19. data/lib/ollama_chat/tools/get_jira_issue.rb +1 -1
  20. data/lib/ollama_chat/tools/get_rfc.rb +4 -4
  21. data/lib/ollama_chat/tools/get_url.rb +4 -7
  22. data/lib/ollama_chat/tools/paste_from_clipboard.rb +1 -1
  23. data/lib/ollama_chat/tools/patch_file.rb +3 -3
  24. data/lib/ollama_chat/tools/read_file.rb +2 -2
  25. data/lib/ollama_chat/tools/run_tests.rb +1 -1
  26. data/lib/ollama_chat/tools/search_web.rb +3 -3
  27. data/lib/ollama_chat/tools/write_file.rb +3 -3
  28. data/lib/ollama_chat/utils/path_completer.rb +62 -0
  29. data/lib/ollama_chat/utils.rb +1 -0
  30. data/lib/ollama_chat/version.rb +1 -1
  31. data/lib/ollama_chat/web_searching.rb +2 -10
  32. data/lib/ollama_chat.rb +1 -0
  33. data/ollama_chat.gemspec +5 -5
  34. data/spec/ollama_chat/chat_spec.rb +3 -0
  35. data/spec/ollama_chat/tools/browse_spec.rb +4 -8
  36. data/spec/ollama_chat/tools/copy_to_clipboard_spec.rb +0 -4
  37. data/spec/ollama_chat/tools/directory_structure_spec.rb +3 -7
  38. data/spec/ollama_chat/tools/execute_grep_spec.rb +7 -7
  39. data/spec/ollama_chat/tools/file_context_spec.rb +2 -6
  40. data/spec/ollama_chat/tools/generate_password_spec.rb +5 -9
  41. data/spec/ollama_chat/tools/get_current_weather_spec.rb +2 -2
  42. data/spec/ollama_chat/tools/get_cve_spec.rb +2 -2
  43. data/spec/ollama_chat/tools/get_endoflife_spec.rb +2 -2
  44. data/spec/ollama_chat/tools/get_rfc_spec.rb +2 -2
  45. data/spec/ollama_chat/tools/get_url_spec.rb +3 -7
  46. data/spec/ollama_chat/tools/open_file_in_editor_spec.rb +0 -4
  47. data/spec/ollama_chat/tools/paste_from_clipboard_spec.rb +0 -4
  48. data/spec/ollama_chat/tools/paste_into_editor_spec.rb +5 -9
  49. data/spec/ollama_chat/tools/patch_file_spec.rb +5 -9
  50. data/spec/ollama_chat/tools/read_file_spec.rb +3 -7
  51. data/spec/ollama_chat/tools/run_tests_spec.rb +4 -8
  52. data/spec/ollama_chat/tools/search_web_spec.rb +3 -7
  53. data/spec/ollama_chat/tools/write_file_spec.rb +5 -9
  54. data/spec/ollama_chat/utils/path_completer_spec.rb +34 -0
  55. metadata +7 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5116e552c78df5d85138b112ef43b4a80bbb7e2ce03fd5cbd5e58f7adbde948d
4
- data.tar.gz: 22ff0f77807fa3560ce394a0e840ea367770596f2a261cddb650c24eaf362d01
3
+ metadata.gz: 5fb8acfbab42d7afd6b6bf67dfe087cfb3c12a61719834713c9cd2f095dd7ce8
4
+ data.tar.gz: efdba3f26df1ae84df62f2aa2a2f48e914baf2a5dd1430691e55be9f01a23774
5
5
  SHA512:
6
- metadata.gz: ad573ad4cfdd39455f2720e2283e4487afaae6d17dbb451580289afdfef77b433fb426bb2cc516225db514365d788b8441efeb11ab9b0f2916accc5817d619a1
7
- data.tar.gz: 583cb266287eaad72e28543e34003da6b72f072f1c45b751327b6218b9ed842c35639759d8f37a0fd8051167fcbd735a3c32c4b0c9443a5c4cf2074ace755a03
6
+ metadata.gz: b5042b32617e390e4cad869c2356dc0a12c5a8cc55a57c6f3d6f84fa20f2342a91afcddeb24898947b9a3d73d083b3b4ce666b13cab1e339a37ba76ecb3ec961
7
+ data.tar.gz: c3ada9646a5580fe07c463c62348e972a50f69cc563ae240b0000e18db917af160adc9e3234e4bbdbfda68907421f3445e18c61db1b25ccba393f670652938b9
data/CHANGES.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-20 v0.0.81
4
+
5
+ - Added `http_handling.rb` and `path_completer.rb` to gemspec
6
+ `s.extra_rdoc_files`, `s.files`, and `s.test_files` lists, ensuring these
7
+ modules are documented and packaged.
8
+ - Updated `http_options` to build SSL and proxy settings.
9
+ - Completed `get_url` to merge headers, pass cache, debug, and reraise flags.
10
+ - Updated YARD comments with parameter and return details.
11
+ - Fixed `config.request_headers` usage and added `merge`.
12
+ - Declared `proxy` variable in options hash.
13
+ - Added `debug` flag from `config` to fetcher call.
14
+ - Added `PathCompleter` utility in `lib/ollama_chat/utils/path_completer.rb`
15
+ that expands `./` and `~/` paths using `Dir.glob` and `File.expand_path`.
16
+ - Updated `lib/ollama_chat/utils.rb` to require the new helper.
17
+ - Replaced inline path completion logic in `lib/ollama_chat/chat.rb` with
18
+ `OllamaChat::Utils::PathCompleter.new(pre, input).complete`.
19
+ - Added tests for `PathCompleter` in
20
+ `spec/ollama_chat/utils/path_completer_spec.rb`, stubbing `expand_path` for
21
+ home‑directory case.
22
+ - Added duration metric to tool call results: recorded `start = Time.now`
23
+ before each tool call, stored `tools_used[name]` as a hash with `size` and
24
+ `duration` keys, calculated `duration` with `Time.now - start` and formatted
25
+ as `Tins::Duration.new(...).to_s`, kept size formatting using
26
+ `Tins::Unit.format(..., unit: ?B, prefix: 1024, format: '%.1f %U')`.
27
+ - Added `./` file path completion to Reline: updated
28
+ `OllamaChat::Chat#enable_command_completion` to add `./` path completion,
29
+ replaced old `RELINE` completion proc with a new `case before` block that
30
+ checks for `^/` and `./` patterns, ensuring file path completions are only
31
+ offered when the user starts with `./`.
32
+ - Added user name to runtime info and prompts: added `OC::USER` config variable
33
+ with default from `ENV['USER']`, included `user` in the hash returned by
34
+ `runtime_information_values`, extended default prompts in
35
+ `lib/ollama_chat/ollama_chat_config/default_config.yml` to show “Name of the
36
+ chat user: %{user}”, updated tests in `spec/ollama_chat/chat_spec.rb` to set
37
+ `OC::PAGER` to `nil` for cleaner output.
38
+
3
39
  ## 2026-03-18 v0.0.80
4
40
 
5
41
  ### Output & Paging
@@ -33,6 +33,7 @@ require 'context_spook'
33
33
  class OllamaChat::Chat
34
34
  include Tins::GO
35
35
  include Term::ANSIColor
36
+ include OllamaChat::HTTPHandling
36
37
  include OllamaChat::CommandConcern
37
38
  include OllamaChat::Logging
38
39
  include OllamaChat::DocumentCache
@@ -157,6 +158,11 @@ class OllamaChat::Chat
157
158
  # messages associated with this instance
158
159
  attr_reader :messages
159
160
 
161
+ # Provides read-only access to the cache instance used by the object
162
+ #
163
+ # @attr_reader [Cache] the cache instance
164
+ attr_reader :cache
165
+
160
166
  # The start method initializes the chat session by displaying information,
161
167
  # then prompts the user for input to begin interacting with the chat.
162
168
  def start
@@ -1248,8 +1254,14 @@ class OllamaChat::Chat
1248
1254
  old = Reline.completion_proc
1249
1255
  Reline.autocompletion = true
1250
1256
  Reline.completion_proc = -> input, pre {
1251
- start = [ pre, input ].join(' ').strip.gsub(/\s+/, ' ')
1252
- command_completions.select { _1.start_with?(start) }
1257
+ before = [ pre, input ].join
1258
+ case before
1259
+ when %r(^/)
1260
+ start = [ pre, input ].join(' ').strip.gsub(/\s+/, ' ')
1261
+ command_completions.select { _1.start_with?(start) }
1262
+ when %r((./\S*))
1263
+ OllamaChat::Utils::PathCompleter.new(pre, input).complete
1264
+ end
1253
1265
  }
1254
1266
  block.()
1255
1267
  ensure
@@ -138,6 +138,7 @@ class OllamaChat::FollowChat
138
138
  italic { function },
139
139
  ]
140
140
  end
141
+ start = Time.now
141
142
  result = nil
142
143
  case confirmed
143
144
  when :denied
@@ -155,7 +156,7 @@ class OllamaChat::FollowChat
155
156
  "\n%s Execution of tool %s confirmed.\n\n", symbol, bold { name }
156
157
  )
157
158
  result = OllamaChat::Tools.registered[name].
158
- execute(tool_call, chat: @chat, config: @chat.config)
159
+ execute(tool_call, chat: @chat)
159
160
  if confirmed == :explicit
160
161
  @chat.log(:info, "Execution of tool %s was explicitly confirmed." % name)
161
162
  else
@@ -169,7 +170,10 @@ class OllamaChat::FollowChat
169
170
  @chat.log(:info, result)
170
171
  end
171
172
  @chat.tool_call_results[name] = result
172
- tools_used[name] = Tins::Unit.format(result.to_s.size, unit: ?B, prefix: 1024, format: '%.1f %U')
173
+ tools_used[name] = {
174
+ 'size' => Tins::Unit.format(result.to_s.size, unit: ?B, prefix: 1024, format: '%.1f %U'),
175
+ 'duration' => Tins::Duration.new(Time.now - start).to_s,
176
+ }
173
177
  end
174
178
 
175
179
  if tools_used.full?
@@ -0,0 +1,63 @@
1
+ # Provides helper methods for HTTP interactions used by the OllamaChat
2
+ # library. The module is mixed into various classes (e.g. `OllamaChat::Chat`)
3
+ # to give them access to a convenient, configuration‑aware HTTP client.
4
+ #
5
+ # The primary responsibilities are:
6
+ #
7
+ # * Build a hash of HTTP options (e.g. SSL verification and proxy
8
+ # settings) based on the current configuration.
9
+ # * Perform a GET request with those options, optionally using a cache
10
+ # and debugging information.
11
+ #
12
+ # The module is deliberately lightweight – it delegates the actual network
13
+ # call to `OllamaChat::Utils::Fetcher`.
14
+ module OllamaChat::HTTPHandling
15
+ # Returns a hash of HTTP options suitable for `Net::HTTP` or a
16
+ # compatible client.
17
+ #
18
+ # The options include:
19
+ # * `:ssl_verify_peer` – a boolean that disables peer verification for
20
+ # hostnames listed in the configuration’s `ssl_no_verify` set.
21
+ # * `:proxy` – the proxy URL if one is configured.
22
+ #
23
+ # @param url [String] the URL for which the options should be
24
+ # generated.
25
+ # @return [Hash] a hash containing the HTTP options.
26
+ def http_options(url)
27
+ options = {}
28
+ if ssl_no_verify = config.ssl_no_verify?
29
+ hostname = URI.parse(url).hostname
30
+ options |= { ssl_verify_peer: !ssl_no_verify.include?(hostname) }
31
+ end
32
+ if proxy = config.proxy?
33
+ options |= { proxy: }
34
+ end
35
+ options
36
+ end
37
+
38
+ # Performs an HTTP GET request.
39
+ #
40
+ # The method merges the caller‑supplied headers with the headers
41
+ # configured in `config.request_headers?`. It then delegates to
42
+ # `OllamaChat::Utils::Fetcher.get`, passing along any cache or debug
43
+ # flags and the HTTP options generated by `http_options`.
44
+ #
45
+ # @param url [String] the target URL.
46
+ # @param headers [Hash] optional additional headers.
47
+ # @param reraise [Boolean] whether to re‑raise errors from the fetcher.
48
+ # @param cache [Object] optional cache object to use.
49
+ # @yield [IO] yields a temporary file handle for the caller to consume.
50
+ # @return [Object] the result of the block or the fetcher.
51
+ def get_url(url, headers: nil, reraise: false, cache: nil, &block)
52
+ headers = config.request_headers?.to_h | headers
53
+ OllamaChat::Utils::Fetcher.get(
54
+ url,
55
+ headers: ,
56
+ cache: ,
57
+ debug: ,
58
+ reraise: ,
59
+ http_options: http_options(OllamaChat::Utils::Fetcher.normalize_url(url)),
60
+ &block
61
+ )
62
+ end
63
+ end
@@ -203,6 +203,7 @@ module OllamaChat::Information
203
203
  # @return [Hash] a hash containing runtime information values.
204
204
  def runtime_information_values
205
205
  {
206
+ user: OC::OLLAMA::CHAT::USER || 'n/a',
206
207
  languages: config.languages * ', ',
207
208
  time: Time.now.iso8601,
208
209
  location: location.on?.full? { location_description } || 'n/a',
@@ -147,6 +147,11 @@ module OC
147
147
  default XDG_STATE_HOME + 'chat.log'
148
148
  end
149
149
 
150
+ USER = set do
151
+ description '(Full) Name of the chat user'
152
+ default { ENV['USER'] }
153
+ end
154
+
150
155
  module TOOLS
151
156
  description 'Tool specific configuration settings'
152
157
 
@@ -39,6 +39,7 @@ prompts:
39
39
  There is usually no reason to mention this information to the user unless
40
40
  asked about it.
41
41
 
42
+ - Name of the chat user: %{user}
42
43
  - Languages the user prefers: %{languages}
43
44
  - Current time is %{time}
44
45
  - Location: %{location}
@@ -24,27 +24,6 @@
24
24
  # # Process the command output
25
25
  # end
26
26
  module OllamaChat::SourceFetching
27
- # The http_options method prepares HTTP options for requests based on
28
- # configuration settings.
29
- # It determines whether SSL peer verification should be disabled for a given
30
- # URL and whether a proxy should be used, then returns a hash of options.
31
- #
32
- # @param url [ String ] the URL for which HTTP options are being prepared
33
- #
34
- # @return [ Hash ] a hash containing HTTP options such as ssl_verify_peer and
35
- # proxy settings
36
- def http_options(url)
37
- options = {}
38
- if ssl_no_verify = config.ssl_no_verify?
39
- hostname = URI.parse(url).hostname
40
- options |= { ssl_verify_peer: !ssl_no_verify.include?(hostname) }
41
- end
42
- if proxy = config.proxy?
43
- options |= { proxy: }
44
- end
45
- options
46
- end
47
-
48
27
  # The fetch_source method retrieves content from various source types
49
28
  # including commands, URLs, and file paths. It processes the source based on
50
29
  # its type and yields a temporary file handle for further processing.
@@ -63,13 +42,7 @@ module OllamaChat::SourceFetching
63
42
  end
64
43
  when %r{\Ahttps?://\S+}
65
44
  links.add(source.to_s)
66
- OllamaChat::Utils::Fetcher.get(
67
- source,
68
- headers: config.request_headers?.to_h,
69
- cache: @cache,
70
- debug: ,
71
- http_options: http_options(OllamaChat::Utils::Fetcher.normalize_url(source))
72
- ) do |tmp|
45
+ get_url(source, cache:) do |tmp|
73
46
  block.(tmp)
74
47
  end
75
48
  when %r{\Afile://([^\s#]+)}
@@ -11,6 +11,8 @@ module OllamaChat::Tools::Concern
11
11
  include Ollama
12
12
 
13
13
  implement :tool, :submodule
14
+
15
+ implement :execute, :submodule
14
16
  end
15
17
 
16
18
  class_methods do
@@ -42,7 +42,6 @@ class OllamaChat::Tools::CopyToClipboard
42
42
  #
43
43
  # @param _tool_call [OllamaChat::Tool::Call] the tool call object (unused)
44
44
  # @param opts [Hash] additional options
45
- # @option opts [ComplexConfig::Settings] :config the configuration object
46
45
  # @option opts [OllamaChat::Chat] :chat the chat instance
47
46
  # @return [String] JSON payload indicating success or failure
48
47
  def execute(tool_call, **opts)
@@ -68,7 +68,7 @@ class OllamaChat::Tools::DirectoryStructure
68
68
  # @raise [StandardError] if there's an issue with directory traversal or JSON
69
69
  # serialization
70
70
  def execute(tool_call, **opts)
71
- config = opts[:config]
71
+ config = opts[:chat].config
72
72
  path = Pathname.new(tool_call.function.arguments.path || '.')
73
73
  suffix = tool_call.function.arguments.suffix.full?
74
74
  max_depth = tool_call.function.arguments.max_depth.full?
@@ -70,14 +70,14 @@ class OllamaChat::Tools::ExecuteGrep
70
70
  # OllamaChat::Utils::Fetcher to execute the command.
71
71
  #
72
72
  # @example
73
- # result = grep_tool.execute(tool_call, config:, chat:)
73
+ # result = grep_tool.execute(tool_call, chat:)
74
74
  #
75
75
  # @param tool_call [OllamaChat::Tool::Call] The tool call with arguments
76
76
  # @param opts [Hash] Additional options
77
- # @option opts [Hash] :config Configuration options including tool settings
77
+ # @option opts [Hash] :chat chat instance
78
78
  # @return [String] The execution result with command and output as JSON string
79
79
  def execute(tool_call, **opts)
80
- config = opts[:config]
80
+ config = opts[:chat].config
81
81
  args = tool_call.function.arguments
82
82
  pattern = Shellwords.escape(args.pattern)
83
83
  path = Shellwords.escape(Pathname.new(args.path || '.').expand_path)
@@ -59,12 +59,12 @@ class OllamaChat::Tools::FileContext
59
59
  #
60
60
  # @param tool_call [Ollama::Tool::Call] the tool call containing function details
61
61
  # @param opts [Hash] additional options
62
- # @option opts [ComplexConfig::Settings] :config the configuration object
62
+ # @option opts [ComplexConfig::Settings] :chat the configuration object
63
63
  #
64
64
  # @return [String] the generated context data in the configured format (JSON by default)
65
65
  # @return [String] a JSON string containing error information if the operation fails
66
66
  def execute(tool_call, **opts)
67
- config = opts[:config]
67
+ config = opts[:chat].config
68
68
  pattern = tool_call.function.arguments.pattern
69
69
  format = config.context.format
70
70
 
@@ -106,11 +106,10 @@ class OllamaChat::Tools::GeneratePassword
106
106
  #
107
107
  # @param tool_call [Ollama::Tool::Call] the tool call object containing function details
108
108
  # @param opts [Hash] additional options
109
- # @option opts [ComplexConfig::Settings] :config the configuration object
109
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
110
110
  # @return [String] the generated password as a JSON string
111
111
  def execute(tool_call, **opts)
112
- config = opts[:config]
113
- args = tool_call.function.arguments
112
+ args = tool_call.function.arguments
114
113
 
115
114
  # Parse and validate parameters
116
115
  length = args.length
@@ -44,16 +44,17 @@ class OllamaChat::Tools::GetCurrentWeather
44
44
  # @param tool_call [Object] the tool call object containing function
45
45
  # details
46
46
  # @param opts [Hash] additional options
47
- # @option opts [ComplexConfig::Settings] :config the configuration object
47
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
48
48
  #
49
49
  # @return [String] a JSON string containing the retrieved weather data
50
50
  # @return [String] an error message if the weather data could not be
51
51
  # retrieved
52
52
  def execute(tool_call, **opts)
53
- config = opts[:config]
53
+ chat = opts[:chat]
54
+ config = chat.config
54
55
  units = config.location.units =~ /SI/ ? 'si' : 'us'
55
56
  data = { current_time: Time.now, units: } |
56
- JSON(get_weather_data(config, units)).deep_symbolize_keys
57
+ JSON(get_weather_data(chat, config, units)).deep_symbolize_keys
57
58
  data.to_json
58
59
  rescue => e
59
60
  {
@@ -81,7 +82,7 @@ class OllamaChat::Tools::GetCurrentWeather
81
82
  #
82
83
  # @raise [OllamaChat::ConfigMissingError] if the required Pirate Weather API
83
84
  # key is missing
84
- def get_weather_data(config, units)
85
+ def get_weather_data(chat, config, units)
85
86
  api_key = OC::OLLAMA::CHAT::TOOLS::PIRATEWEATHER_API_KEY? or
86
87
  raise OllamaChat::ConfigMissingError, 'require env var OLLAMA_CHAT_TOOLS_PIRATEWEATHER_API_KEY'
87
88
  lat, lon = config.location.decimal_degrees
@@ -93,13 +94,7 @@ class OllamaChat::Tools::GetCurrentWeather
93
94
  'User-Agent' => OllamaChat::Chat.user_agent,
94
95
  'apikey' => api_key,
95
96
  }
96
- OllamaChat::Utils::Fetcher.get(
97
- url,
98
- headers:,
99
- debug: OC::OLLAMA::CHAT::DEBUG,
100
- reraise: true,
101
- &valid_json?
102
- )
97
+ chat.get_url(url, headers:, reraise: true, &valid_json?)
103
98
  end
104
99
 
105
100
  self
@@ -47,21 +47,17 @@ class OllamaChat::Tools::GetCVE
47
47
  #
48
48
  # @param tool_call [Ollama::Tool::Call] the tool call object containing function details
49
49
  # @param opts [Hash] additional options
50
- # @option opts [ComplexConfig::Settings] :config the configuration object
50
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
51
51
  # @return [String] the parsed CVE data or an error message as JSON string
52
52
  def execute(tool_call, **opts)
53
- config = opts[:config]
54
- cve_id = tool_call.function.arguments.cve_id
55
- url = config.tools.functions.get_cve.url % { cve_id: }
56
- OllamaChat::Utils::Fetcher.get(
57
- url,
58
- headers: {
59
- 'Accept' => 'application/json',
60
- },
61
- debug: OC::OLLAMA::CHAT::DEBUG,
62
- reraise: true,
63
- &valid_json?
64
- )
53
+ chat = opts[:chat]
54
+ config = chat.config
55
+ cve_id = tool_call.function.arguments.cve_id
56
+ url = config.tools.functions.get_cve.url % { cve_id: }
57
+ headers = {
58
+ 'Accept' => 'application/json',
59
+ }
60
+ chat.get_url(url, headers:, reraise: true, &valid_json?)
65
61
  rescue => e
66
62
  { error: e.class, message: e.message }.to_json
67
63
  end
@@ -48,23 +48,23 @@ class OllamaChat::Tools::GetEndoflife
48
48
  #
49
49
  # @param tool_call [Ollama::Tool::Call] the tool call object containing function details
50
50
  # @param opts [Hash] additional options
51
- # @option opts [ComplexConfig::Settings] :config the configuration object
51
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
52
52
  # @return [String] the parsed endoflife data or an error as a JSON string
53
53
  def execute(tool_call, **opts)
54
- config = opts[:config]
54
+ chat = opts[:chat]
55
+ config = chat.config
55
56
  product = tool_call.function.arguments.product
56
57
 
57
58
  # Construct the URL for the endoflife API
58
59
  url = config.tools.functions.get_endoflife.url % { product: }
59
60
 
60
61
  # Fetch the data from endoflife.date API
61
- OllamaChat::Utils::Fetcher.get(
62
+ chat.get_url(
62
63
  url,
63
64
  headers: {
64
65
  'Accept' => 'application/json',
65
66
  'User-Agent' => OllamaChat::Chat.user_agent
66
67
  },
67
- debug: OC::OLLAMA::CHAT::DEBUG,
68
68
  reraise: true,
69
69
  &valid_json?
70
70
  )
@@ -44,7 +44,7 @@ class OllamaChat::Tools::GetJiraIssue
44
44
  #
45
45
  # @param tool_call [Ollama::Tool::Call] the tool call object containing function details
46
46
  # @param opts [Hash] additional options
47
- # @option opts [ComplexConfig::Settings] :config the configuration object
47
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
48
48
  # @return [String] the parsed JIRA issue data or an error message as JSON string
49
49
  def execute(tool_call, **opts)
50
50
  issue_key = tool_call.function.arguments.issue_key
@@ -46,18 +46,18 @@ class OllamaChat::Tools::GetRFC
46
46
  #
47
47
  # @param tool_call [Ollama::Tool::Call] the tool call object containing function details
48
48
  # @param opts [Hash] additional options
49
- # @option opts [ComplexConfig::Settings] :config the configuration object
49
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
50
50
  # @return [String] the parsed RFC text or an error message as JSON string
51
51
  def execute(tool_call, **opts)
52
- config = opts[:config]
52
+ chat = opts[:chat]
53
+ config = chat.config
53
54
  rfc_id = tool_call.function.arguments.rfc_id
54
55
  url = config.tools.functions.get_rfc.url % { rfc_id: }
55
- content = OllamaChat::Utils::Fetcher.get(
56
+ content = chat.get_url(
56
57
  url,
57
58
  headers: {
58
59
  'Accept' => 'text/plain',
59
60
  },
60
- debug: OC::OLLAMA::CHAT::DEBUG,
61
61
  reraise: true,
62
62
  &:read
63
63
  )
@@ -52,11 +52,12 @@ class OllamaChat::Tools::GetURL
52
52
  #
53
53
  # @param tool_call [Ollama::Tool::Call] the tool call object containing function details
54
54
  # @param opts [Hash] additional options
55
- # @option opts [ComplexConfig::Settings] :config the configuration object
55
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
56
56
  # @return [String] the fetched content as a JSON string
57
57
  # @raise [StandardError] if there's an issue with the HTTP request or content fetching
58
58
  def execute(tool_call, **opts)
59
- config = opts[:config]
59
+ chat = opts[:chat]
60
+ config = chat.config
60
61
  args = tool_call.function.arguments
61
62
  url = args.url.to_s
62
63
 
@@ -68,11 +69,7 @@ class OllamaChat::Tools::GetURL
68
69
  "(allowed: #{allowed_schemes.join(', ')})"
69
70
  end
70
71
 
71
- OllamaChat::Utils::Fetcher.get(
72
- url,
73
- debug: OC::OLLAMA::CHAT::DEBUG,
74
- reraise: true,
75
- &:read)
72
+ chat.get_url(url, reraise: true, &:read)
76
73
  rescue => e
77
74
  { error: e.class, message: e.message, url: }.to_json
78
75
  end
@@ -35,7 +35,7 @@ class OllamaChat::Tools::PasteFromClipboard
35
35
  #
36
36
  # @param _tool_call [OllamaChat::Tool::Call] the tool call object (unused)
37
37
  # @param opts [Hash] additional options
38
- # @option opts [ComplexConfig::Settings] :config the configuration object
38
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
39
39
  # @option opts [OllamaChat::Chat] :chat the chat instance
40
40
  # @return [String] JSON payload indicating success or failure
41
41
  def execute(_tool_call, **opts)
@@ -53,13 +53,13 @@ class OllamaChat::Tools::PatchFile
53
53
  #
54
54
  # @param tool_call [Ollama::Tool::Call] the tool call containing function details
55
55
  # @param opts [Hash] additional options
56
- # @option opts [ComplexConfig::Settings] :config the configuration object
56
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
57
57
  #
58
58
  # @return [String] the result of the patch operation as a JSON string
59
59
  # @return [String] a JSON string containing error information if the operation fails
60
60
  def execute(tool_call, **opts)
61
- config = opts[:config]
62
- args = tool_call.function.arguments
61
+ config = opts[:chat].config
62
+ args = tool_call.function.arguments
63
63
 
64
64
  diff_content = args.diff_content.full? or
65
65
  raise ArgumentError, 'require diff_content to patch with'
@@ -52,13 +52,13 @@ class OllamaChat::Tools::ReadFile
52
52
  #
53
53
  # @param tool_call [OllamaChat::Tool::Call] the tool call object containing function details
54
54
  # @param opts [Hash] additional options
55
- # @option opts [ComplexConfig::Settings] :config the configuration object
55
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
56
56
  #
57
57
  # @return [String] the file content as a JSON string containing `path` and `content` keys
58
58
  # @return [String] an error message as a JSON string if the operation fails
59
59
  # @raise [JSON::ParserError] if the result cannot be serialized to JSON
60
60
  def execute(tool_call, **opts)
61
- config = opts[:config]
61
+ config = opts[:chat].config
62
62
  args = tool_call.function.arguments
63
63
 
64
64
  path = assert_valid_path(args.path, config.tools.functions.read_file.allowed?, check_file: true)
@@ -48,7 +48,7 @@ class OllamaChat::Tools::RunTests
48
48
  # @param opts [Hash] additional options (currently unused)
49
49
  # @return [String] JSON containing ``success``, ``path``, ``output`` and ``status``
50
50
  def execute(tool_call, **opts)
51
- config = opts[:config]
51
+ config = opts[:chat].config
52
52
  path = tool_call.function.arguments.path
53
53
  coverage = tool_call.function.arguments.coverage || false
54
54
  check_path(path, config)
@@ -53,14 +53,14 @@ class OllamaChat::Tools::SearchWeb
53
53
  #
54
54
  # @param tool_call [Ollama::Tool::Call] the tool call object containing function details
55
55
  # @param opts [Hash] additional options
56
- # @option opts [ComplexConfig::Settings] :config the configuration object
56
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
57
57
  # @option opts [OllamaChat::Chat] :chat the chat instance for location context
58
58
  # @return [String] the search results as a JSON string
59
59
  # @raise [StandardError] if there's an issue with the search operation
60
60
  def execute(tool_call, **opts)
61
61
  chat = opts[:chat]
62
- config = opts[:config]
63
- args = tool_call.function.arguments
62
+ config = chat.config
63
+ args = tool_call.function.arguments
64
64
 
65
65
  query = args.query
66
66
  max_results = config.tools.functions.search_web?.max_results? || 10
@@ -58,14 +58,14 @@ class OllamaChat::Tools::WriteFile
58
58
  # @param tool_call [Ollama::Tool::Call] the tool call containing function
59
59
  # details
60
60
  # @param opts [Hash] additional options
61
- # @option opts [ComplexConfig::Settings] :config the configuration object
61
+ # @option opts [ComplexConfig::Settings] :chat the chat instance
62
62
  #
63
63
  # @return [String] the result of the file write operation as a JSON string
64
64
  # @return [String] a JSON string containing error information if the
65
65
  # operation fails
66
66
  def execute(tool_call, **opts)
67
- config = opts[:config]
68
- args = tool_call.function.arguments
67
+ config = opts[:chat].config
68
+ args = tool_call.function.arguments
69
69
 
70
70
  target_path = assert_valid_path(args.path, config.tools.functions.write_file.allowed?)
71
71