omniai-tools 0.6.2 → 0.7.0
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.
- checksums.yaml +4 -4
- data/lib/omniai/tools/browser/base_driver.rb +2 -16
- data/lib/omniai/tools/browser/{element_click_tool.rb → click_tool.rb} +12 -5
- data/lib/omniai/tools/browser/watir_driver.rb +16 -106
- data/lib/omniai/tools/browser_tool.rb +50 -72
- data/lib/omniai/tools/disk_tool.rb +103 -0
- data/lib/omniai/tools/version.rb +1 -1
- metadata +3 -4
- data/lib/omniai/tools/browser/button_click_tool.rb +0 -27
- data/lib/omniai/tools/browser/link_click_tool.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc6ea7c9ceed0c7ea84e3dbd8870e649d3c9890cc776663ca81134e5bd40b5da
|
4
|
+
data.tar.gz: c619e234101b74e420a44a4536565fac17ce9f36a00205875fc89aa7e79df415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 249c297b5d8ee3e69c24e6fa2e594b02766ebd6862f95a52a4491b114d17d5494f06efe98ca602921d76be2937a7e7c57d1864ba323016d50927d58c7cf74b0e
|
7
|
+
data.tar.gz: 2d0583047e63b56ca62dbc9f6073b12fa5513dc769a770effb5f534f2e485d2c40cbcc4fd52ec9bd19639b9f087f140bbbf1a88e0fb73c4dc69752a944d922c0
|
@@ -52,24 +52,10 @@ module OmniAI
|
|
52
52
|
raise NotImplementedError, "#{self.class.name}#{__method__} undefined"
|
53
53
|
end
|
54
54
|
|
55
|
-
# @param selector [String]
|
56
|
-
#
|
57
|
-
# @return [Hash]
|
58
|
-
def button_click(selector:)
|
59
|
-
raise NotImplementedError, "#{self.class.name}#{__method__} undefined"
|
60
|
-
end
|
61
|
-
|
62
|
-
# @param selector [String]
|
63
|
-
#
|
64
|
-
# @return [Hash]
|
65
|
-
def link_click(selector:)
|
66
|
-
raise NotImplementedError, "#{self.class.name}#{__method__} undefined"
|
67
|
-
end
|
68
|
-
|
69
|
-
# @param selector [String]
|
55
|
+
# @param selector [String] e.g. "button[type='submit']", "div#parent > span.child", etc
|
70
56
|
#
|
71
57
|
# @return [Hash]
|
72
|
-
def
|
58
|
+
def click(selector:)
|
73
59
|
raise NotImplementedError, "#{self.class.name}#{__method__} undefined"
|
74
60
|
end
|
75
61
|
end
|
@@ -5,16 +5,23 @@ module OmniAI
|
|
5
5
|
module Browser
|
6
6
|
# @example
|
7
7
|
# browser = Watir::Browser.new(:chrome)
|
8
|
-
# tool = OmniAI::Tools::Browser::
|
8
|
+
# tool = OmniAI::Tools::Browser::ClickTool.new(browser:)
|
9
9
|
# tool.execute(selector: "#some-id")
|
10
10
|
# tool.execute(selector: ".some-class")
|
11
11
|
# tool.execute(selector: "some text")
|
12
12
|
# tool.execute(selector: "//div[@role='button']")
|
13
|
-
class
|
13
|
+
class ClickTool < BaseTool
|
14
14
|
description "A browser automation tool for clicking any clickable element."
|
15
15
|
|
16
|
-
parameter :selector, :string,
|
17
|
-
|
16
|
+
parameter :selector, :string, description: <<~TEXT
|
17
|
+
A CSS selector to locate or interact with an element on the page:
|
18
|
+
|
19
|
+
* 'form button[type="submit"]': selects a button with type submit
|
20
|
+
* '.example': selects elements with the foo and bar classes
|
21
|
+
* '#example': selects an element by ID
|
22
|
+
* 'div#parent > span.child': selects span elements that are direct children of div elements
|
23
|
+
* 'a[href="/login"]': selects an anchor tag with a specific href attribute
|
24
|
+
TEXT
|
18
25
|
|
19
26
|
required %i[selector]
|
20
27
|
|
@@ -22,7 +29,7 @@ module OmniAI
|
|
22
29
|
def execute(selector:)
|
23
30
|
@logger.info("#{self.class.name}##{__method__} selector=#{selector.inspect}")
|
24
31
|
|
25
|
-
@driver.
|
32
|
+
@driver.click(selector:)
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
@@ -65,36 +65,10 @@ module OmniAI
|
|
65
65
|
{ status: :ok }
|
66
66
|
end
|
67
67
|
|
68
|
-
# @param selector [String]
|
68
|
+
# @param selector [String] e.g. "button[type='submit']", "div#parent > span.child", etc
|
69
69
|
#
|
70
70
|
# @return [Hash]
|
71
|
-
def
|
72
|
-
element = find_button(selector)
|
73
|
-
|
74
|
-
return { status: error, message: "unknown selector=#{selector.inspect}" } if element.nil?
|
75
|
-
|
76
|
-
element.click
|
77
|
-
|
78
|
-
{ status: :ok }
|
79
|
-
end
|
80
|
-
|
81
|
-
# @param selector [String]
|
82
|
-
#
|
83
|
-
# @return [Hash]
|
84
|
-
def link_click(selector:)
|
85
|
-
element = find_link(selector)
|
86
|
-
|
87
|
-
return { status: :error, message: "unknown selector=#{selector.inspect}" } if element.nil?
|
88
|
-
|
89
|
-
element.click
|
90
|
-
|
91
|
-
{ status: :ok }
|
92
|
-
end
|
93
|
-
|
94
|
-
# @param selector [String]
|
95
|
-
#
|
96
|
-
# @return [Hash]
|
97
|
-
def element_click(selector:)
|
71
|
+
def click(selector:)
|
98
72
|
element = find_element(selector)
|
99
73
|
|
100
74
|
return { status: :error, message: "unknown selector=#{selector.inspect}" } if element.nil?
|
@@ -102,117 +76,53 @@ module OmniAI
|
|
102
76
|
element.click
|
103
77
|
|
104
78
|
{ status: :ok }
|
105
|
-
rescue TimeoutError => e
|
106
|
-
{ status: :error, message: e.message }
|
107
79
|
end
|
108
80
|
|
109
81
|
protected
|
110
82
|
|
111
|
-
def wait_for_element
|
112
|
-
Watir::Wait.until(timeout: TIMEOUT)
|
113
|
-
element = yield
|
114
|
-
element if element&.visible?
|
115
|
-
end
|
83
|
+
def wait_for_element(&)
|
84
|
+
Watir::Wait.until(timeout: TIMEOUT, &)
|
116
85
|
rescue Watir::Wait::TimeoutError
|
117
86
|
nil
|
118
87
|
end
|
119
88
|
|
120
89
|
# @param selector [String]
|
121
90
|
#
|
122
|
-
# @return [Watir::
|
91
|
+
# @return [Watir::Input, Watir::TextArea, nil]
|
123
92
|
def find_field(selector)
|
124
|
-
wait_for_element
|
125
|
-
find_text_area_or_field_by(id: selector) ||
|
126
|
-
find_text_area_or_field_by(name: selector) ||
|
127
|
-
find_text_area_or_field_by(placeholder: selector) ||
|
128
|
-
find_text_area_or_field_by(class: selector) ||
|
129
|
-
find_text_area_or_field_by(css: selector)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# @param selector [String]
|
134
|
-
#
|
135
|
-
# @return [Watir::TextArea, Watir::TextField, nil]
|
136
|
-
def find_text_area_or_field_by(selector)
|
137
|
-
find_text_field_by(selector) || find_text_area_by(selector)
|
138
|
-
end
|
139
|
-
|
140
|
-
# @param selector [String]
|
141
|
-
#
|
142
|
-
# @return [Watir::Button, nil]
|
143
|
-
def find_button(selector)
|
144
|
-
wait_for_element do
|
145
|
-
find_button_by(text: selector) || find_button_by(id: selector)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# @param selector [String]
|
150
|
-
#
|
151
|
-
# @return [Watir::Button, nil]
|
152
|
-
def find_link(selector)
|
153
|
-
wait_for_element do
|
154
|
-
find_link_by(text: selector) || find_link_by(href: selector) || find_link_by(id: selector)
|
155
|
-
end
|
93
|
+
wait_for_element { find_input_by(css: selector) || find_textarea_by(css: selector) }
|
156
94
|
end
|
157
95
|
|
158
96
|
# @param selector [Hash] A hash with one of the following
|
159
97
|
#
|
160
98
|
# @return [Watir::Element, nil]
|
161
99
|
def find_element(selector)
|
162
|
-
wait_for_element
|
163
|
-
find_element_by(css: selector) ||
|
164
|
-
find_element_by(text: selector) ||
|
165
|
-
find_element_by(id: selector) ||
|
166
|
-
find_element_by(xpath: selector)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
# @param selector [Hash]
|
171
|
-
#
|
172
|
-
# @return [Watir::TextArea, nil]
|
173
|
-
def find_text_area_by(selector)
|
174
|
-
element = @browser.textarea(selector)
|
175
|
-
return unless element.respond_to?(:exists?)
|
176
|
-
|
177
|
-
element if element.exists?
|
100
|
+
wait_for_element { find_element_by(css: selector) }
|
178
101
|
end
|
179
102
|
|
180
|
-
# @param selector [Hash]
|
181
|
-
#
|
182
|
-
# @return [Watir::TextField, nil]
|
183
|
-
def find_text_field_by(selector)
|
184
|
-
element = @browser.text_field(selector)
|
185
|
-
return unless element.respond_to?(:exists?)
|
186
|
-
|
187
|
-
element if element.exists?
|
188
|
-
end
|
189
|
-
|
190
|
-
# @param selector [String] CSS selector to find the element
|
191
|
-
#
|
192
|
-
# @return [Watir::Element, nil]
|
193
103
|
def find_element_by(selector)
|
194
104
|
element = @browser.element(selector)
|
195
|
-
return
|
105
|
+
return unless element.respond_to?(:exists?)
|
196
106
|
|
197
107
|
element if element.exists?
|
198
108
|
end
|
199
109
|
|
200
110
|
# @param selector [Hash]
|
201
111
|
#
|
202
|
-
# @return [Watir::
|
203
|
-
def
|
204
|
-
element = @browser.
|
205
|
-
return unless element
|
112
|
+
# @return [Watir::TextArea, nil]
|
113
|
+
def find_textarea_by(selector)
|
114
|
+
element = @browser.textarea(selector)
|
115
|
+
return unless element
|
206
116
|
|
207
117
|
element if element.exists?
|
208
118
|
end
|
209
119
|
|
210
120
|
# @param selector [Hash]
|
211
121
|
#
|
212
|
-
# @return [Watir::
|
213
|
-
def
|
214
|
-
element = @browser.
|
215
|
-
return unless element
|
122
|
+
# @return [Watir::Input, nil]
|
123
|
+
def find_input_by(selector)
|
124
|
+
element = @browser.input(selector)
|
125
|
+
return unless element
|
216
126
|
|
217
127
|
element if element.exists?
|
218
128
|
end
|
@@ -9,9 +9,7 @@ module OmniAI
|
|
9
9
|
PAGE_INSPECT = "page_inspect"
|
10
10
|
UI_INSPECT = "ui_inspect"
|
11
11
|
SELECTOR_INSPECT = "selector_inspect"
|
12
|
-
|
13
|
-
LINK_CLICK = "link_click"
|
14
|
-
ELEMENT_CLICK = "element_click"
|
12
|
+
CLICK = "click"
|
15
13
|
TEXT_FIELD_SET = "text_field_set"
|
16
14
|
SCREENSHOT = "screenshot"
|
17
15
|
end
|
@@ -21,49 +19,42 @@ module OmniAI
|
|
21
19
|
Action::PAGE_INSPECT,
|
22
20
|
Action::UI_INSPECT,
|
23
21
|
Action::SELECTOR_INSPECT,
|
24
|
-
Action::
|
25
|
-
Action::LINK_CLICK,
|
26
|
-
Action::ELEMENT_CLICK,
|
22
|
+
Action::CLICK,
|
27
23
|
Action::TEXT_FIELD_SET,
|
28
24
|
Action::SCREENSHOT,
|
29
25
|
].freeze
|
30
26
|
|
31
27
|
description <<~TEXT
|
32
|
-
|
28
|
+
Automates a web browser to perform various actions like visiting web pages, clicking elements, etc:
|
33
29
|
|
34
|
-
|
35
|
-
|
30
|
+
1. `#{Action::VISIT}` - Navigate to a website
|
31
|
+
Required: "action": "visit", "url": "[website URL]"
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
2. `#{Action::PAGE_INSPECT} - Get page HTML or summary
|
34
|
+
Required: "action": "page_inspect"
|
35
|
+
Optional: "full_html": true/false (get full HTML vs summary, default: summary)
|
40
36
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
3. `#{Action::UI_INSPECT}` - Find elements by text content
|
38
|
+
Required: "action": "ui_inspect", "text_content": "[text to search for]"
|
39
|
+
Optional:
|
40
|
+
- "selector": "[CSS selector]" (search within specific container)
|
41
|
+
- "context_size": [number] (parent elements to show, default: 2)
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
4. `#{Action::SELECTOR_INSPECT} - Find elements by CSS selector
|
44
|
+
Required: "action": "selector_inspect", "selector": "[CSS selector]"
|
45
|
+
Optional: "context_size": [number] (parent elements to show, default: 2)
|
50
46
|
|
51
|
-
|
52
|
-
|
47
|
+
5. `#{Action::CLICK}` - Click an element by CSS selector
|
48
|
+
Required: "action": "click", "selector": "[CSS selector]"
|
53
49
|
|
54
|
-
|
55
|
-
|
50
|
+
8. `#{Action::TEXT_FIELD_SET}` - Enter text in input fields/text areas
|
51
|
+
Required: "action": "text_field_set", "selector": "[field CSS selector]", "value": "[text to enter]"
|
56
52
|
|
57
|
-
|
58
|
-
|
53
|
+
9. `#{Action::SCREENSHOT}` - Take a screenshot of the page or specific element
|
54
|
+
Required: "action": "screenshot"
|
59
55
|
|
60
|
-
|
61
|
-
Required: "action": "text_field_set", "selector": "[field CSS selector]", "value": "[text to enter]"
|
56
|
+
## Examples:
|
62
57
|
|
63
|
-
9. `#{Action::SCREENSHOT}` - Take a screenshot of the page or specific element
|
64
|
-
Required: "action": "screenshot"
|
65
|
-
|
66
|
-
Examples:
|
67
58
|
Visit a website
|
68
59
|
{"action": "#{Action::VISIT}", "url": "https://example.com"}
|
69
60
|
Get page summary
|
@@ -78,16 +69,14 @@ module OmniAI
|
|
78
69
|
{"action": "#{Action::SELECTOR_INSPECT}", "selector": ".button"}
|
79
70
|
Find selector with context
|
80
71
|
{"action": "#{Action::SELECTOR_INSPECT}", "selector": "h1", "context_size": 2}
|
81
|
-
Click a button
|
82
|
-
{"action": "#{Action::
|
83
|
-
Click a link
|
84
|
-
{"action": "#{Action::
|
85
|
-
Click element by CSS selector
|
86
|
-
{"action": "#{Action::
|
87
|
-
Click element by
|
88
|
-
{"action": "#{Action::
|
89
|
-
Click element by text content
|
90
|
-
{"action": "#{Action::ELEMENT_CLICK}", "selector": "Medical Evaluation Management"}
|
72
|
+
Click a button by CSS selector
|
73
|
+
{"action": "#{Action::CLICK}", "selector": "button[type='Submit']"}
|
74
|
+
Click a link by CSS Selector
|
75
|
+
{"action": "#{Action::CLICK}", "selector": "a[href='/login']"}
|
76
|
+
Click an element by CSS selector
|
77
|
+
{"action": "#{Action::CLICK}", "selector": "div.panel > span.toggle"}
|
78
|
+
Click an element by CSS selector:
|
79
|
+
{"action": "#{Action::CLICK}", "selector": "[role='listitem']"}
|
91
80
|
Set text in an input field
|
92
81
|
{"action": "#{Action::TEXT_FIELD_SET}", "selector": "#search", "value": "search query"}
|
93
82
|
Take a full page screenshot
|
@@ -100,9 +89,7 @@ module OmniAI
|
|
100
89
|
* `#{Action::PAGE_INSPECT}`: Get full HTML or summarized page information
|
101
90
|
* `#{Action::UI_INSPECT}`: Find elements containing specific text
|
102
91
|
* `#{Action::SELECTOR_INSPECT}`: Find elements matching CSS selectors
|
103
|
-
* `#{Action::
|
104
|
-
* `#{Action::LINK_CLICK}`: Click a link element
|
105
|
-
* `#{Action::ELEMENT_CLICK}`: Click any clickable element
|
92
|
+
* `#{Action::CLICK}`: Click an element by CSS selector
|
106
93
|
* `#{Action::TEXT_FIELD_SET}`: Enter text in input fields or text areas
|
107
94
|
* `#{Action::SCREENSHOT}`: Take a screenshot of the current page
|
108
95
|
TEXT
|
@@ -113,12 +100,19 @@ module OmniAI
|
|
113
100
|
TEXT
|
114
101
|
|
115
102
|
parameter :selector, :string, description: <<~TEXT
|
116
|
-
CSS selector
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
103
|
+
A CSS selector to locate an element:
|
104
|
+
|
105
|
+
* 'form button[type="submit"]': selects a button with type submit
|
106
|
+
* '.example': selects elements with the foo and bar classes
|
107
|
+
* '#example': selects an element by ID
|
108
|
+
* 'div#parent > span.child': selects span elements that are direct children of div elements
|
109
|
+
* 'a[href="/login"]': selects an anchor tag with a specific href attribute
|
110
|
+
* 'button[aria-label="Close"]': selects an element by ARIA label
|
111
|
+
|
112
|
+
Required for the following actions:
|
113
|
+
* `#{Action::CLICK}`
|
121
114
|
* `#{Action::TEXT_FIELD_SET}`
|
115
|
+
* `#{Action::SELECTOR_INSPECT}`
|
122
116
|
|
123
117
|
Optional for the following actions:
|
124
118
|
* `#{Action::UI_INSPECT}` (search within specific container)
|
@@ -161,7 +155,7 @@ module OmniAI
|
|
161
155
|
|
162
156
|
# @param action [String]
|
163
157
|
# @param url [String, nil]
|
164
|
-
# @param selector [String, nil]
|
158
|
+
# @param selector [String, nil] e.g. "button[type='submit']", "div#parent > span.child", etc
|
165
159
|
# @param value [String, nil]
|
166
160
|
# @param context_size [Integer]
|
167
161
|
# @param full_html [Boolean]
|
@@ -185,15 +179,9 @@ module OmniAI
|
|
185
179
|
when Action::SELECTOR_INSPECT
|
186
180
|
require_param!(:selector, selector)
|
187
181
|
selector_inspect_tool.execute(selector:, context_size:)
|
188
|
-
when Action::
|
189
|
-
require_param!(:selector, selector)
|
190
|
-
button_click_tool.execute(selector:)
|
191
|
-
when Action::LINK_CLICK
|
182
|
+
when Action::CLICK
|
192
183
|
require_param!(:selector, selector)
|
193
|
-
|
194
|
-
when Action::ELEMENT_CLICK
|
195
|
-
require_param!(:selector, selector)
|
196
|
-
element_click_tool.execute(selector:)
|
184
|
+
click_tool.execute(selector:)
|
197
185
|
when Action::TEXT_FIELD_SET
|
198
186
|
require_param!(:selector, selector)
|
199
187
|
require_param!(:value, value)
|
@@ -236,19 +224,9 @@ module OmniAI
|
|
236
224
|
Browser::SelectorInspectTool.new(driver: @driver, logger: @logger)
|
237
225
|
end
|
238
226
|
|
239
|
-
# @return [Browser::
|
240
|
-
def
|
241
|
-
Browser::
|
242
|
-
end
|
243
|
-
|
244
|
-
# @return [Browser::LinkClickTool]
|
245
|
-
def link_click_tool
|
246
|
-
Browser::LinkClickTool.new(driver: @driver, logger: @logger)
|
247
|
-
end
|
248
|
-
|
249
|
-
# @return [Browser::ElementClickTool]
|
250
|
-
def element_click_tool
|
251
|
-
Browser::ElementClickTool.new(driver: @driver, logger: @logger)
|
227
|
+
# @return [Browser::ClickTool]
|
228
|
+
def click_tool
|
229
|
+
Browser::ClickTool.new(driver: @driver, logger: @logger)
|
252
230
|
end
|
253
231
|
|
254
232
|
# @return [Browser::TextFieldAreaSetTool]
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
module Tools
|
5
|
+
# A tool for interacting with a computer. Be careful with using as it can perform actions on your computer!
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# computer = OmniAI::Tools::Computer::MacTool.new
|
9
|
+
# computer.display # { "width": 2560, "height": 1440, "scale": 1 }
|
10
|
+
# computer.screenshot
|
11
|
+
class ComputerTool < OmniAI::Tool
|
12
|
+
description "A tool for interacting with a computer."
|
13
|
+
|
14
|
+
module Action
|
15
|
+
DIRECTORY_CREATE = "directory_create"
|
16
|
+
DIRECTORY_DELETE = "directory_delete"
|
17
|
+
DIRECTORY_MOVE = "directory_move"
|
18
|
+
DIRECTORY_LIST = "directory_list"
|
19
|
+
FILE_CREATE = "file_create"
|
20
|
+
FILE_DELETE = "file_delete"
|
21
|
+
FILE_MOVE = "file_move"
|
22
|
+
FILE_READ = "file_read"
|
23
|
+
FILE_WRITE = "file_write"
|
24
|
+
FILE_REPLACE = "file_replace"
|
25
|
+
end
|
26
|
+
|
27
|
+
ACTIONS = [
|
28
|
+
Action::DIRECTORY_CREATE,
|
29
|
+
Action::DIRECTORY_DELETE,
|
30
|
+
Action::DIRECTORY_MOVE,
|
31
|
+
Action::DIRECTORY_LIST,
|
32
|
+
Action::FILE_CREATE,
|
33
|
+
Action::FILE_DELETE,
|
34
|
+
Action::FILE_MOVE,
|
35
|
+
Action::FILE_READ,
|
36
|
+
Action::FILE_WRITE,
|
37
|
+
Action::FILE_REPLACE,
|
38
|
+
].freeze
|
39
|
+
|
40
|
+
parameter :action, :string, enum: ACTIONS, description: <<~TEXT
|
41
|
+
Options:
|
42
|
+
* `#{Action::DIRECTORY_CREATE}`: creates a directory at a specific path
|
43
|
+
* `#{Action::DIRECTORY_DELETE}`: deletes a directory at a specific path
|
44
|
+
* `#{Action::DIRECTORY_MOVE}`: moves a directory from one path to another
|
45
|
+
* `#{Action::DIRECTORY_LIST}`: lists the contents of a directory at a specific path
|
46
|
+
* `#{Action::FILE_CREATE}`: creates a file at a specific path
|
47
|
+
* `#{Action::FILE_DELETE}`: deletes a file at a specific path
|
48
|
+
* `#{Action::FILE_MOVE}`: moves a file from one path to another
|
49
|
+
* `#{Action::FILE_READ}`: reads the contents of a file at a specific path
|
50
|
+
* `#{Action::FILE_WRITE}`: writes the contents of a file at a specific path
|
51
|
+
* `#{Action::FILE_REPLACE}`: replaces the contents of a file at a specific path
|
52
|
+
TEXT
|
53
|
+
|
54
|
+
parameter :path, :string, description: <<~TEXT
|
55
|
+
A file or directory path that is required for the following actions:
|
56
|
+
* `#{Action::DIRECTORY_CREATE}`
|
57
|
+
* `#{Action::DIRECTORY_DELETE}`
|
58
|
+
* `#{Action::DIRECTORY_MOVE}`
|
59
|
+
* `#{Action::DIRECTORY_LIST}`
|
60
|
+
* `#{Action::FILE_DELETE}`
|
61
|
+
* `#{Action::FILE_READ}`
|
62
|
+
* `#{Action::FILE_WRITE}`
|
63
|
+
* `#{Action::FILE_REPLACE}`
|
64
|
+
TEXT
|
65
|
+
|
66
|
+
paramter :to, :string, description: <<~TEXT
|
67
|
+
A file or directory path that is required for the following actions:
|
68
|
+
* `#{Action::DIRECTORY_MOVE}`
|
69
|
+
* `#{Action::FILE_MOVE}`
|
70
|
+
TEXT
|
71
|
+
|
72
|
+
# @param driver [Computer::Driver]
|
73
|
+
def initialize(logger: Logger.new(IO::NULL))
|
74
|
+
@logger = logger
|
75
|
+
super()
|
76
|
+
end
|
77
|
+
|
78
|
+
# @param action [String]
|
79
|
+
# @param path [String]
|
80
|
+
# @param to [String]
|
81
|
+
def execute(action:, path: nil, to: nil)
|
82
|
+
@logger.info({
|
83
|
+
action:,
|
84
|
+
path:,
|
85
|
+
to:,
|
86
|
+
}.compact.map { |key, value| "#{key}=#{value.inspect}" }.join(" "))
|
87
|
+
|
88
|
+
case action
|
89
|
+
when Action::DIRECTORY_CREATE then Disk::DirectoryCreateTool.new(logger: @logger).execute(path:)
|
90
|
+
when Action::DIRECTORY_DELETE then Disk::DirectoryDeleteTool.new(logger: @logger).execute(path:)
|
91
|
+
when Action::DIRECTORY_MOVE then Disk::DirectoryMoveTool.new(logger: @logger).execute(path:, to:)
|
92
|
+
when Action::DIRECTORY_LIST then Disk::DirectoryListTool.new(logger: @logger).execute(path:)
|
93
|
+
when Action::FILE_CREATE then Disk::FileCreateTool.new(logger: @logger).execute(path:)
|
94
|
+
when Action::FILE_DELETE then Disk::FileDeleteTool.new(logger: @logger).execute(path:)
|
95
|
+
when Action::FILE_MOVE then Disk::FileMoveTool.new(logger: @logger).execute(path:, to:)
|
96
|
+
when Action::FILE_READ then Disk::FileReadTool.new(logger: @logger).execute(path:)
|
97
|
+
when Action::FILE_WRITE then Disk::FileWriteTool.new(logger: @logger).execute(path:)
|
98
|
+
when Action::FILE_REPLACE then Disk::FileReplaceTool.new(logger: @logger).execute(path:)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/omniai/tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniai-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
@@ -51,8 +51,7 @@ files:
|
|
51
51
|
- lib/omniai/tools.rb
|
52
52
|
- lib/omniai/tools/browser/base_driver.rb
|
53
53
|
- lib/omniai/tools/browser/base_tool.rb
|
54
|
-
- lib/omniai/tools/browser/
|
55
|
-
- lib/omniai/tools/browser/element_click_tool.rb
|
54
|
+
- lib/omniai/tools/browser/click_tool.rb
|
56
55
|
- lib/omniai/tools/browser/elements/element_grouper.rb
|
57
56
|
- lib/omniai/tools/browser/elements/nearby_element_detector.rb
|
58
57
|
- lib/omniai/tools/browser/formatters/action_formatter.rb
|
@@ -61,7 +60,6 @@ files:
|
|
61
60
|
- lib/omniai/tools/browser/formatters/input_formatter.rb
|
62
61
|
- lib/omniai/tools/browser/inspect_tool.rb
|
63
62
|
- lib/omniai/tools/browser/inspect_utils.rb
|
64
|
-
- lib/omniai/tools/browser/link_click_tool.rb
|
65
63
|
- lib/omniai/tools/browser/page_inspect/button_summarizer.rb
|
66
64
|
- lib/omniai/tools/browser/page_inspect/form_summarizer.rb
|
67
65
|
- lib/omniai/tools/browser/page_inspect/html_summarizer.rb
|
@@ -94,6 +92,7 @@ files:
|
|
94
92
|
- lib/omniai/tools/disk/file_replace_tool.rb
|
95
93
|
- lib/omniai/tools/disk/file_write_tool.rb
|
96
94
|
- lib/omniai/tools/disk/summary_tool.rb
|
95
|
+
- lib/omniai/tools/disk_tool.rb
|
97
96
|
- lib/omniai/tools/docker/base_tool.rb
|
98
97
|
- lib/omniai/tools/docker/compose_run_tool.rb
|
99
98
|
- lib/omniai/tools/version.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "sqlite3"
|
4
|
-
|
5
|
-
module OmniAI
|
6
|
-
module Tools
|
7
|
-
module Browser
|
8
|
-
# @example
|
9
|
-
# browser = Watir::Browser.new(:chrome)
|
10
|
-
# tool = OmniAI::Tools::Browser::VisitTool.new(browser:)
|
11
|
-
# tool.click_link(selector: "link_id")
|
12
|
-
class ButtonClickTool < BaseTool
|
13
|
-
description "A browser automation tool for clicking a specific button."
|
14
|
-
|
15
|
-
parameter :selector, :string, description: "The ID or text of the button to interact with."
|
16
|
-
|
17
|
-
required %i[selector]
|
18
|
-
|
19
|
-
def execute(selector:)
|
20
|
-
@logger.info("#{self.class.name}##{__method__} selector=#{selector.inspect}")
|
21
|
-
|
22
|
-
@driver.button_click(selector:)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "sqlite3"
|
4
|
-
|
5
|
-
module OmniAI
|
6
|
-
module Tools
|
7
|
-
module Browser
|
8
|
-
# @example
|
9
|
-
# browser = Watir::Browser.new(:chrome)
|
10
|
-
# tool = OmniAI::Tools::Browser::VisitTool.new(browser:)
|
11
|
-
# tool.click_link(selector: "link_id")
|
12
|
-
class LinkClickTool < BaseTool
|
13
|
-
description "A browser automation tool for clicking a specific link."
|
14
|
-
|
15
|
-
parameter :selector, :string, description: "The ID or text of the link to interact with."
|
16
|
-
|
17
|
-
# @param selector [String] The ID or text of the link to interact with.
|
18
|
-
def execute(selector:)
|
19
|
-
@logger.info("#{self.class.name}##{__method__} selector=#{selector.inspect}")
|
20
|
-
|
21
|
-
@driver.link_click(selector:)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|