exa-ai 0.15.0 → 0.16.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/CHANGELOG.md +31 -0
- data/README.md +72 -1
- data/exe/exa-ai +139 -1
- data/exe/exa-ai-enrichment-cancel +108 -0
- data/exe/exa-ai-enrichment-create +188 -0
- data/exe/exa-ai-enrichment-delete +122 -0
- data/exe/exa-ai-enrichment-get +104 -0
- data/exe/exa-ai-enrichment-list +99 -0
- data/exe/exa-ai-enrichment-update +140 -0
- data/exe/exa-ai-import-create +224 -0
- data/exe/exa-ai-import-delete +92 -0
- data/exe/exa-ai-import-get +92 -0
- data/exe/exa-ai-import-list +71 -0
- data/exe/exa-ai-import-update +130 -0
- data/exe/exa-ai-monitor-create +180 -0
- data/exe/exa-ai-monitor-delete +101 -0
- data/exe/exa-ai-monitor-get +92 -0
- data/exe/exa-ai-monitor-list +89 -0
- data/exe/exa-ai-monitor-runs-get +103 -0
- data/exe/exa-ai-monitor-runs-list +110 -0
- data/exe/exa-ai-monitor-update +192 -0
- data/exe/exa-ai-search +10 -0
- data/exe/exa-ai-search-monitor-create +1 -1
- data/exe/exa-ai-search-monitor-delete +1 -1
- data/exe/exa-ai-search-monitor-get +1 -1
- data/exe/exa-ai-search-monitor-list +1 -1
- data/exe/exa-ai-search-monitor-trigger +1 -1
- data/exe/exa-ai-webset-cancel +97 -0
- data/exe/exa-ai-webset-create +220 -0
- data/exe/exa-ai-webset-delete +111 -0
- data/exe/exa-ai-webset-get +93 -0
- data/exe/exa-ai-webset-item-delete +111 -0
- data/exe/exa-ai-webset-item-get +105 -0
- data/exe/exa-ai-webset-item-list +108 -0
- data/exe/exa-ai-webset-list +96 -0
- data/exe/exa-ai-webset-search-cancel +104 -0
- data/exe/exa-ai-webset-search-create +231 -0
- data/exe/exa-ai-webset-search-get +105 -0
- data/exe/exa-ai-webset-update +116 -0
- data/lib/exa/cli/formatters/enrichment_formatter.rb +125 -0
- data/lib/exa/cli/formatters/import_formatter.rb +153 -0
- data/lib/exa/cli/formatters/monitor_formatter.rb +144 -0
- data/lib/exa/cli/formatters/monitor_run_formatter.rb +126 -0
- data/lib/exa/cli/formatters/search_formatter.rb +22 -1
- data/lib/exa/cli/formatters/search_monitor_formatter.rb +1 -1
- data/lib/exa/cli/formatters/webset_formatter.rb +134 -0
- data/lib/exa/cli/formatters/webset_item_formatter.rb +132 -0
- data/lib/exa/cli/formatters/webset_search_formatter.rb +57 -0
- data/lib/exa/cli/search_parser.rb +4 -0
- data/lib/exa/client.rb +313 -1
- data/lib/exa/constants/websets.rb +19 -0
- data/lib/exa/resources/import.rb +111 -0
- data/lib/exa/resources/import_collection.rb +33 -0
- data/lib/exa/resources/monitor.rb +72 -0
- data/lib/exa/resources/monitor_collection.rb +30 -0
- data/lib/exa/resources/monitor_run.rb +82 -0
- data/lib/exa/resources/monitor_run_collection.rb +30 -0
- data/lib/exa/resources/search_monitor.rb +1 -0
- data/lib/exa/resources/search_result.rb +5 -1
- data/lib/exa/resources/webset.rb +106 -0
- data/lib/exa/resources/webset_collection.rb +33 -0
- data/lib/exa/resources/webset_enrichment.rb +71 -0
- data/lib/exa/resources/webset_enrichment_collection.rb +28 -0
- data/lib/exa/resources/webset_item.rb +63 -0
- data/lib/exa/resources/webset_item_collection.rb +33 -0
- data/lib/exa/resources/webset_search.rb +140 -0
- data/lib/exa/services/parameter_converter.rb +3 -2
- data/lib/exa/services/search.rb +2 -1
- data/lib/exa/services/websets/cancel.rb +19 -0
- data/lib/exa/services/websets/cancel_enrichment.rb +35 -0
- data/lib/exa/services/websets/cancel_search.rb +23 -0
- data/lib/exa/services/websets/create.rb +28 -0
- data/lib/exa/services/websets/create_enrichment.rb +35 -0
- data/lib/exa/services/websets/create_search.rb +28 -0
- data/lib/exa/services/websets/create_search_validator.rb +135 -0
- data/lib/exa/services/websets/create_validator.rb +214 -0
- data/lib/exa/services/websets/delete.rb +19 -0
- data/lib/exa/services/websets/delete_enrichment.rb +35 -0
- data/lib/exa/services/websets/delete_item.rb +20 -0
- data/lib/exa/services/websets/get_item.rb +20 -0
- data/lib/exa/services/websets/get_search.rb +22 -0
- data/lib/exa/services/websets/import_create.rb +22 -0
- data/lib/exa/services/websets/import_delete.rb +19 -0
- data/lib/exa/services/websets/import_get.rb +19 -0
- data/lib/exa/services/websets/import_list.rb +25 -0
- data/lib/exa/services/websets/import_update.rb +20 -0
- data/lib/exa/services/websets/import_upload.rb +59 -0
- data/lib/exa/services/websets/list.rb +25 -0
- data/lib/exa/services/websets/list_items.rb +26 -0
- data/lib/exa/services/websets/monitors/create.rb +31 -0
- data/lib/exa/services/websets/monitors/delete.rb +21 -0
- data/lib/exa/services/websets/monitors/get.rb +22 -0
- data/lib/exa/services/websets/monitors/list.rb +27 -0
- data/lib/exa/services/websets/monitors/runs/get.rb +25 -0
- data/lib/exa/services/websets/monitors/runs/list.rb +30 -0
- data/lib/exa/services/websets/monitors/update.rb +28 -0
- data/lib/exa/services/websets/retrieve.rb +30 -0
- data/lib/exa/services/websets/retrieve_enrichment.rb +35 -0
- data/lib/exa/services/websets/update.rb +40 -0
- data/lib/exa/services/websets/update_enrichment.rb +36 -0
- data/lib/exa/services/websets_parameter_converter.rb +51 -0
- data/lib/exa/version.rb +1 -1
- data/lib/exa.rb +51 -0
- metadata +331 -227
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Exa
|
|
4
|
+
module CLI
|
|
5
|
+
module Formatters
|
|
6
|
+
class MonitorRunFormatter
|
|
7
|
+
def self.format(monitor_run, output_format)
|
|
8
|
+
case output_format
|
|
9
|
+
when "json"
|
|
10
|
+
JSON.generate(monitor_run.to_h)
|
|
11
|
+
when "pretty"
|
|
12
|
+
format_as_pretty(monitor_run)
|
|
13
|
+
when "text"
|
|
14
|
+
format_as_text(monitor_run)
|
|
15
|
+
when "toon"
|
|
16
|
+
Exa::CLI::Base.encode_as_toon(monitor_run.to_h)
|
|
17
|
+
else
|
|
18
|
+
raise ArgumentError, "Unknown output format: #{output_format}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.format_collection(collection, output_format)
|
|
23
|
+
case output_format
|
|
24
|
+
when "json"
|
|
25
|
+
JSON.generate(collection.to_h)
|
|
26
|
+
when "pretty"
|
|
27
|
+
format_collection_as_pretty(collection)
|
|
28
|
+
when "text"
|
|
29
|
+
format_collection_as_text(collection)
|
|
30
|
+
when "toon"
|
|
31
|
+
Exa::CLI::Base.encode_as_toon(collection.to_h)
|
|
32
|
+
else
|
|
33
|
+
raise ArgumentError, "Unknown output format: #{output_format}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.format_as_pretty(monitor_run)
|
|
38
|
+
lines = []
|
|
39
|
+
lines << "Monitor Run ID: #{monitor_run.id}"
|
|
40
|
+
lines << "Monitor ID: #{monitor_run.monitor_id}" if monitor_run.monitor_id
|
|
41
|
+
lines << "Status: #{monitor_run.status}"
|
|
42
|
+
|
|
43
|
+
lines << ""
|
|
44
|
+
lines << "Created: #{monitor_run.created_at}" if monitor_run.created_at
|
|
45
|
+
lines << "Updated: #{monitor_run.updated_at}" if monitor_run.updated_at
|
|
46
|
+
lines << "Completed: #{monitor_run.completed_at}" if monitor_run.completed_at
|
|
47
|
+
|
|
48
|
+
if monitor_run.failed?
|
|
49
|
+
lines << ""
|
|
50
|
+
lines << "Failed: #{monitor_run.failed_at}" if monitor_run.failed_at
|
|
51
|
+
lines << "Reason: #{monitor_run.failed_reason}" if monitor_run.failed_reason
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
lines.join("\n")
|
|
55
|
+
end
|
|
56
|
+
private_class_method :format_as_pretty
|
|
57
|
+
|
|
58
|
+
def self.format_as_text(monitor_run)
|
|
59
|
+
lines = []
|
|
60
|
+
lines << "Monitor Run: #{monitor_run.id}"
|
|
61
|
+
lines << "Monitor: #{monitor_run.monitor_id}" if monitor_run.monitor_id
|
|
62
|
+
lines << "Status: #{monitor_run.status}"
|
|
63
|
+
|
|
64
|
+
lines << "\nCreated: #{monitor_run.created_at}" if monitor_run.created_at
|
|
65
|
+
lines << "Updated: #{monitor_run.updated_at}" if monitor_run.updated_at
|
|
66
|
+
lines << "Completed: #{monitor_run.completed_at}" if monitor_run.completed_at
|
|
67
|
+
|
|
68
|
+
if monitor_run.failed?
|
|
69
|
+
lines << "Failed: #{monitor_run.failed_at}" if monitor_run.failed_at
|
|
70
|
+
lines << "Reason: #{monitor_run.failed_reason}" if monitor_run.failed_reason
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
lines.join("\n")
|
|
74
|
+
end
|
|
75
|
+
private_class_method :format_as_text
|
|
76
|
+
|
|
77
|
+
def self.format_collection_as_pretty(collection)
|
|
78
|
+
lines = []
|
|
79
|
+
lines << "Monitor Runs (#{collection.data.length} items)"
|
|
80
|
+
lines << ""
|
|
81
|
+
|
|
82
|
+
collection.data.each_with_index do |run, idx|
|
|
83
|
+
lines << "" if idx > 0 # Blank line between runs
|
|
84
|
+
|
|
85
|
+
lines << "Monitor Run ID: #{run.id}"
|
|
86
|
+
lines << "Monitor ID: #{run.monitor_id}" if run.monitor_id
|
|
87
|
+
lines << "Status: #{run.status}"
|
|
88
|
+
lines << "Created: #{run.created_at}" if run.created_at
|
|
89
|
+
lines << "Updated: #{run.updated_at}" if run.updated_at
|
|
90
|
+
lines << "Completed: #{run.completed_at}" if run.completed_at
|
|
91
|
+
|
|
92
|
+
if run.failed?
|
|
93
|
+
lines << "Failed: #{run.failed_at}" if run.failed_at
|
|
94
|
+
lines << "Reason: #{run.failed_reason}" if run.failed_reason
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
if collection.has_more
|
|
99
|
+
lines << ""
|
|
100
|
+
lines << "Next Cursor: #{collection.next_cursor}"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
lines.join("\n")
|
|
104
|
+
end
|
|
105
|
+
private_class_method :format_collection_as_pretty
|
|
106
|
+
|
|
107
|
+
def self.format_collection_as_text(collection)
|
|
108
|
+
lines = ["Monitor Runs (#{collection.data.length} items):"]
|
|
109
|
+
collection.data.each do |run|
|
|
110
|
+
lines << "\n #{run.id}"
|
|
111
|
+
lines << " Status: #{run.status}"
|
|
112
|
+
lines << " Completed: #{run.completed_at}" if run.completed_at
|
|
113
|
+
lines << " Failed: #{run.failed_reason}" if run.failed_reason
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
if collection.has_more
|
|
117
|
+
lines << "\nMore available (cursor: #{collection.next_cursor})"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
lines.join("\n")
|
|
121
|
+
end
|
|
122
|
+
private_class_method :format_collection_as_text
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -36,8 +36,27 @@ module Exa
|
|
|
36
36
|
(result.notices || []).map { |notice| "Notice: #{notice['message']}" }
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
# One line per search decision answer under a "Decisions:" header,
|
|
40
|
+
# or none when the search asked no questions. An answer type this
|
|
41
|
+
# gem does not know is shown by its type name.
|
|
42
|
+
def self.decision_lines(result)
|
|
43
|
+
answers = result.decisions&.dig("answers") || {}
|
|
44
|
+
return [] if answers.empty?
|
|
45
|
+
|
|
46
|
+
lines = answers.map do |name, answer|
|
|
47
|
+
value = case answer["type"]
|
|
48
|
+
when "noul" then "noul #{answer['noul']}"
|
|
49
|
+
when "choice" then "#{answer['choice']} (confidence #{answer['confidence']})"
|
|
50
|
+
when "score" then "score #{answer['score']} (confidence #{answer['confidence']})"
|
|
51
|
+
else answer["type"]
|
|
52
|
+
end
|
|
53
|
+
" #{name}: #{value}"
|
|
54
|
+
end
|
|
55
|
+
["Decisions:", *lines]
|
|
56
|
+
end
|
|
57
|
+
|
|
39
58
|
def self.format_pretty(result)
|
|
40
|
-
output = notice_lines(result)
|
|
59
|
+
output = notice_lines(result) + decision_lines(result)
|
|
41
60
|
output << "" if output.any?
|
|
42
61
|
result.results.each_with_index do |item, idx|
|
|
43
62
|
output << "--- Result #{idx + 1} ---"
|
|
@@ -51,6 +70,8 @@ module Exa
|
|
|
51
70
|
|
|
52
71
|
def self.format_text(result)
|
|
53
72
|
output = notice_lines(result)
|
|
73
|
+
decisions = decision_lines(result)
|
|
74
|
+
output << decisions.join("\n") if decisions.any?
|
|
54
75
|
result.results.each do |item|
|
|
55
76
|
output << "#{item['title']}\n#{item['url']}"
|
|
56
77
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Exa
|
|
2
2
|
module CLI
|
|
3
3
|
module Formatters
|
|
4
|
-
# Output for the exa-ai search-monitor-* commands (the /monitors API).
|
|
4
|
+
# Output for the exa-ai search-monitor-* commands (the /monitors API, not Websets monitors).
|
|
5
5
|
class SearchMonitorFormatter
|
|
6
6
|
# Format any search monitor result: a monitor, a run, a list of either,
|
|
7
7
|
# a batch result or a trigger result.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Exa
|
|
4
|
+
module CLI
|
|
5
|
+
module Formatters
|
|
6
|
+
class WebsetFormatter
|
|
7
|
+
def self.format(webset, output_format)
|
|
8
|
+
case output_format
|
|
9
|
+
when "json"
|
|
10
|
+
JSON.generate(webset.to_h)
|
|
11
|
+
when "pretty"
|
|
12
|
+
JSON.pretty_generate(webset.to_h)
|
|
13
|
+
when "text"
|
|
14
|
+
format_as_text(webset)
|
|
15
|
+
when "toon"
|
|
16
|
+
Exa::CLI::Base.encode_as_toon(webset.to_h)
|
|
17
|
+
else
|
|
18
|
+
raise ArgumentError, "Unknown output format: #{output_format}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.format_collection(collection, output_format)
|
|
23
|
+
case output_format
|
|
24
|
+
when "json"
|
|
25
|
+
JSON.generate(collection.to_h)
|
|
26
|
+
when "pretty"
|
|
27
|
+
format_collection_as_pretty(collection)
|
|
28
|
+
when "text"
|
|
29
|
+
format_collection_as_text(collection)
|
|
30
|
+
when "toon"
|
|
31
|
+
Exa::CLI::Base.encode_as_toon(collection.to_h)
|
|
32
|
+
else
|
|
33
|
+
raise ArgumentError, "Unknown output format: #{output_format}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.format_as_text(webset)
|
|
38
|
+
lines = []
|
|
39
|
+
lines << "Webset: #{webset.id}"
|
|
40
|
+
lines << "Status: #{webset.status}"
|
|
41
|
+
lines << "Title: #{webset.title}" if webset.title
|
|
42
|
+
lines << "Created: #{webset.created_at}" if webset.created_at
|
|
43
|
+
lines << "Updated: #{webset.updated_at}" if webset.updated_at
|
|
44
|
+
|
|
45
|
+
if webset.searches && !webset.searches.empty?
|
|
46
|
+
lines << "\nSearches:"
|
|
47
|
+
webset.searches.each do |search|
|
|
48
|
+
lines << " - #{search['query']}" if search['query']
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if webset.enrichments && !webset.enrichments.empty?
|
|
53
|
+
lines << "\nEnrichments: #{webset.enrichments.length}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
lines.join("\n")
|
|
57
|
+
end
|
|
58
|
+
private_class_method :format_as_text
|
|
59
|
+
|
|
60
|
+
def self.format_collection_as_text(collection)
|
|
61
|
+
lines = ["Websets (#{collection.data.length} items):"]
|
|
62
|
+
collection.data.each do |ws|
|
|
63
|
+
lines << "\n #{ws.id}"
|
|
64
|
+
lines << " Status: #{ws.status}"
|
|
65
|
+
lines << " Title: #{ws.title}" if ws.title
|
|
66
|
+
lines << " Created: #{ws.created_at}" if ws.created_at
|
|
67
|
+
end
|
|
68
|
+
lines.join("\n")
|
|
69
|
+
end
|
|
70
|
+
private_class_method :format_collection_as_text
|
|
71
|
+
|
|
72
|
+
def self.format_collection_as_pretty(collection)
|
|
73
|
+
lines = []
|
|
74
|
+
|
|
75
|
+
# Header with count and pagination info
|
|
76
|
+
header = "Websets (#{collection.data.length} items)"
|
|
77
|
+
header += " - Page #{collection.has_more ? '1 of many' : '1 of 1'}" if collection.data.any?
|
|
78
|
+
lines << header
|
|
79
|
+
|
|
80
|
+
if collection.has_more
|
|
81
|
+
lines << "Next Cursor: #{collection.next_cursor}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
lines << ""
|
|
85
|
+
|
|
86
|
+
# Format each webset
|
|
87
|
+
collection.data.each_with_index do |ws, idx|
|
|
88
|
+
lines << "" if idx > 0 # Blank line between websets
|
|
89
|
+
|
|
90
|
+
lines << "Webset ID: #{ws.id}"
|
|
91
|
+
lines << "Status: #{ws.status}"
|
|
92
|
+
lines << "Title: #{ws.title}" if ws.title
|
|
93
|
+
lines << "External ID: #{ws.external_id}" if ws.external_id
|
|
94
|
+
lines << "Created: #{ws.created_at}" if ws.created_at
|
|
95
|
+
lines << "Updated: #{ws.updated_at}" if ws.updated_at
|
|
96
|
+
|
|
97
|
+
# Searches
|
|
98
|
+
if ws.searches && !ws.searches.empty?
|
|
99
|
+
lines << ""
|
|
100
|
+
lines << "Searches (#{ws.searches.length}):"
|
|
101
|
+
ws.searches.each do |search|
|
|
102
|
+
status_indicator = case search['status']
|
|
103
|
+
when 'completed' then '✓'
|
|
104
|
+
when 'running' then '→'
|
|
105
|
+
when 'failed' then '✗'
|
|
106
|
+
else '•'
|
|
107
|
+
end
|
|
108
|
+
lines << " #{status_indicator} #{search['query']} (#{search['status']})" if search['query']
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Enrichments
|
|
113
|
+
if ws.enrichments && !ws.enrichments.empty?
|
|
114
|
+
lines << "Enrichments: #{ws.enrichments.length}"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Monitors
|
|
118
|
+
if ws.monitors && !ws.monitors.empty?
|
|
119
|
+
lines << "Monitors: #{ws.monitors.length}"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Imports
|
|
123
|
+
if ws.imports && !ws.imports.empty?
|
|
124
|
+
lines << "Imports: #{ws.imports.length}"
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
lines.join("\n")
|
|
129
|
+
end
|
|
130
|
+
private_class_method :format_collection_as_pretty
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Exa
|
|
4
|
+
module CLI
|
|
5
|
+
module Formatters
|
|
6
|
+
class WebsetItemFormatter
|
|
7
|
+
# Where each item type keeps its title inside properties: type => [key, field]
|
|
8
|
+
TITLE_PATHS = {
|
|
9
|
+
"company" => ["company", "name"],
|
|
10
|
+
"person" => ["person", "name"],
|
|
11
|
+
"article" => ["article", "title"],
|
|
12
|
+
"research_paper" => ["researchPaper", "title"],
|
|
13
|
+
"custom" => ["custom", "title"]
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
def self.format(item, output_format)
|
|
17
|
+
case output_format
|
|
18
|
+
when "json"
|
|
19
|
+
JSON.generate(item.to_h)
|
|
20
|
+
when "pretty"
|
|
21
|
+
format_as_pretty(item)
|
|
22
|
+
when "text"
|
|
23
|
+
format_as_text(item)
|
|
24
|
+
when "toon"
|
|
25
|
+
Exa::CLI::Base.encode_as_toon(item.to_h)
|
|
26
|
+
else
|
|
27
|
+
raise ArgumentError, "Unknown output format: #{output_format}"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.format_collection(collection, output_format)
|
|
32
|
+
case output_format
|
|
33
|
+
when "json"
|
|
34
|
+
JSON.generate(collection.to_h)
|
|
35
|
+
when "pretty"
|
|
36
|
+
format_collection_as_pretty(collection)
|
|
37
|
+
when "text"
|
|
38
|
+
format_collection_as_text(collection)
|
|
39
|
+
when "toon"
|
|
40
|
+
Exa::CLI::Base.encode_as_toon(collection.to_h)
|
|
41
|
+
else
|
|
42
|
+
raise ArgumentError, "Unknown output format: #{output_format}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Reads the title from the type-specific part of properties; nil when absent.
|
|
47
|
+
def self.title(item)
|
|
48
|
+
properties = item.properties || {}
|
|
49
|
+
key, field = TITLE_PATHS[properties["type"]]
|
|
50
|
+
return nil unless key
|
|
51
|
+
|
|
52
|
+
properties.dig(key, field)
|
|
53
|
+
end
|
|
54
|
+
private_class_method :title
|
|
55
|
+
|
|
56
|
+
def self.format_as_pretty(item)
|
|
57
|
+
properties = item.properties || {}
|
|
58
|
+
lines = []
|
|
59
|
+
lines << "Item ID: #{item.id}"
|
|
60
|
+
lines << "Type: #{properties['type']}" if properties["type"]
|
|
61
|
+
lines << "URL: #{properties['url']}" if properties["url"]
|
|
62
|
+
lines << "Title: #{title(item)}" if title(item)
|
|
63
|
+
lines << "Description: #{properties['description']}" if properties["description"]
|
|
64
|
+
lines << "Created: #{item.created_at}" if item.created_at
|
|
65
|
+
lines << "Updated: #{item.updated_at}" if item.updated_at
|
|
66
|
+
lines.join("\n")
|
|
67
|
+
end
|
|
68
|
+
private_class_method :format_as_pretty
|
|
69
|
+
|
|
70
|
+
def self.format_as_text(item)
|
|
71
|
+
properties = item.properties || {}
|
|
72
|
+
lines = []
|
|
73
|
+
lines << "Item: #{item.id}"
|
|
74
|
+
lines << "Type: #{properties['type']}" if properties["type"]
|
|
75
|
+
lines << "URL: #{properties['url']}" if properties["url"]
|
|
76
|
+
lines << "Title: #{title(item)}" if title(item)
|
|
77
|
+
lines << "Description: #{properties['description']}" if properties["description"]
|
|
78
|
+
lines << "Created: #{item.created_at}" if item.created_at
|
|
79
|
+
lines << "Updated: #{item.updated_at}" if item.updated_at
|
|
80
|
+
lines.join("\n")
|
|
81
|
+
end
|
|
82
|
+
private_class_method :format_as_text
|
|
83
|
+
|
|
84
|
+
def self.format_collection_as_pretty(collection)
|
|
85
|
+
lines = []
|
|
86
|
+
lines << "Webset Items (#{collection.data.length} items)"
|
|
87
|
+
|
|
88
|
+
if collection.has_more
|
|
89
|
+
lines << "Next Cursor: #{collection.next_cursor}"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
lines << ""
|
|
93
|
+
|
|
94
|
+
collection.data.each_with_index do |item, idx|
|
|
95
|
+
lines << "" if idx > 0 # Blank line between items
|
|
96
|
+
|
|
97
|
+
properties = item.properties || {}
|
|
98
|
+
lines << "Item ID: #{item.id}"
|
|
99
|
+
lines << "Type: #{properties['type']}" if properties["type"]
|
|
100
|
+
lines << "URL: #{properties['url']}" if properties["url"]
|
|
101
|
+
lines << "Title: #{title(item)}" if title(item)
|
|
102
|
+
lines << "Created: #{item.created_at}" if item.created_at
|
|
103
|
+
lines << "Updated: #{item.updated_at}" if item.updated_at
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
lines.join("\n")
|
|
107
|
+
end
|
|
108
|
+
private_class_method :format_collection_as_pretty
|
|
109
|
+
|
|
110
|
+
def self.format_collection_as_text(collection)
|
|
111
|
+
lines = ["Webset Items (#{collection.data.length} items):"]
|
|
112
|
+
collection.data.each_with_index do |item, idx|
|
|
113
|
+
properties = item.properties || {}
|
|
114
|
+
lines << "\n#{idx + 1}. #{item.id}"
|
|
115
|
+
lines << " Type: #{properties['type']}" if properties["type"]
|
|
116
|
+
lines << " URL: #{properties['url']}" if properties["url"]
|
|
117
|
+
lines << " Title: #{title(item)}" if title(item)
|
|
118
|
+
lines << " Created: #{item.created_at}" if item.created_at
|
|
119
|
+
lines << " Updated: #{item.updated_at}" if item.updated_at
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
if collection.has_more
|
|
123
|
+
lines << "\nMore available (cursor: #{collection.next_cursor})"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
lines.join("\n")
|
|
127
|
+
end
|
|
128
|
+
private_class_method :format_collection_as_text
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Exa
|
|
4
|
+
module CLI
|
|
5
|
+
module Formatters
|
|
6
|
+
class WebsetSearchFormatter
|
|
7
|
+
def self.format(search, format)
|
|
8
|
+
case format
|
|
9
|
+
when "json"
|
|
10
|
+
JSON.pretty_generate(search.to_h)
|
|
11
|
+
when "pretty"
|
|
12
|
+
format_pretty(search)
|
|
13
|
+
when "text"
|
|
14
|
+
format_text(search)
|
|
15
|
+
when "toon"
|
|
16
|
+
Exa::CLI::Base.encode_as_toon(search.to_h)
|
|
17
|
+
else
|
|
18
|
+
JSON.pretty_generate(search.to_h)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def self.format_pretty(search)
|
|
25
|
+
output = []
|
|
26
|
+
output << "Search ID: #{search.id}"
|
|
27
|
+
output << "Status: #{search.status}"
|
|
28
|
+
output << "Query: #{search.query}"
|
|
29
|
+
output << "Entity Type: #{search.entity&.[]('type') || 'N/A'}" if search.entity
|
|
30
|
+
output << "Count: #{search.count}" if search.count
|
|
31
|
+
output << "Behavior: #{search.behavior}"
|
|
32
|
+
output << "Recall: #{search.recall}" if search.recall
|
|
33
|
+
output << "Created: #{search.created_at}"
|
|
34
|
+
output << "Updated: #{search.updated_at}"
|
|
35
|
+
output << "Progress: #{search.progress}" if search.progress
|
|
36
|
+
output << ""
|
|
37
|
+
|
|
38
|
+
if search.canceled?
|
|
39
|
+
output << "Canceled: #{search.canceled_at}"
|
|
40
|
+
output << "Cancel Reason: #{search.canceled_reason}" if search.canceled_reason
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
output.join("\n")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.format_text(search)
|
|
47
|
+
[
|
|
48
|
+
"ID: #{search.id}",
|
|
49
|
+
"Status: #{search.status}",
|
|
50
|
+
"Query: #{search.query}",
|
|
51
|
+
"Behavior: #{search.behavior}"
|
|
52
|
+
].join("\n")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -67,6 +67,7 @@ module Exa
|
|
|
67
67
|
{ flag: "--snapshot-as-of", api_field: "contents.snapshotAsOf", deprecated: false, replacement: nil, reason: nil },
|
|
68
68
|
{ flag: "--additional-queries", api_field: "additionalQueries", deprecated: false, replacement: nil, reason: nil },
|
|
69
69
|
{ flag: "--output-schema", api_field: "outputSchema", deprecated: false, replacement: nil, reason: nil },
|
|
70
|
+
{ flag: "--decisions", api_field: "decisions", deprecated: false, replacement: nil, reason: nil },
|
|
70
71
|
{ flag: "--user-location", api_field: "userLocation", deprecated: false, replacement: nil, reason: nil },
|
|
71
72
|
{ flag: "--objective", api_field: "objective", deprecated: false, replacement: nil, reason: nil },
|
|
72
73
|
{ flag: "--user-identifier", api_field: "userIdentifier", deprecated: false, replacement: nil, reason: nil },
|
|
@@ -185,6 +186,9 @@ module Exa
|
|
|
185
186
|
when "--output-schema"
|
|
186
187
|
@args[:output_schema] = Exa::CLI::Base.parse_json_or_file("--output-schema", @argv[i + 1])
|
|
187
188
|
i += 2
|
|
189
|
+
when "--decisions"
|
|
190
|
+
@args[:decisions] = Exa::CLI::Base.parse_json_or_file("--decisions", @argv[i + 1])
|
|
191
|
+
i += 2
|
|
188
192
|
when "--user-location"
|
|
189
193
|
@args[:user_location] = self.class.parse_user_location(Exa::CLI::Base.text_value("--user-location", @argv[i + 1]))
|
|
190
194
|
i += 2
|