exa-ai 0.14.0 → 0.15.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 +516 -0
- data/README.md +40 -0
- data/exe/exa-ai-agent-run-cancel +14 -14
- data/exe/exa-ai-agent-run-create +10 -9
- data/exe/exa-ai-agent-run-delete +14 -14
- data/exe/exa-ai-agent-run-events +15 -15
- data/exe/exa-ai-agent-run-get +14 -14
- data/exe/exa-ai-agent-run-list +11 -11
- data/exe/exa-ai-agent-run-stop +14 -14
- data/exe/exa-ai-answer +8 -7
- data/exe/exa-ai-context +9 -8
- data/exe/exa-ai-find-similar +16 -12
- data/exe/exa-ai-get-contents +118 -159
- data/exe/exa-ai-search +21 -1
- data/exe/exa-ai-search-monitor-batch +13 -13
- data/exe/exa-ai-search-monitor-create +17 -17
- data/exe/exa-ai-search-monitor-delete +10 -10
- data/exe/exa-ai-search-monitor-get +10 -10
- data/exe/exa-ai-search-monitor-list +12 -12
- data/exe/exa-ai-search-monitor-runs-get +10 -10
- data/exe/exa-ai-search-monitor-runs-list +11 -11
- data/exe/exa-ai-search-monitor-trigger +10 -10
- data/exe/exa-ai-search-monitor-update +16 -16
- data/lib/exa/cli/base.rb +35 -7
- data/lib/exa/cli/contents_flags.rb +40 -40
- data/lib/exa/cli/get_contents.rb +59 -0
- data/lib/exa/cli/request_printer.rb +37 -0
- data/lib/exa/cli/search_parser.rb +112 -26
- data/lib/exa/version.rb +1 -1
- data/lib/exa.rb +1 -0
- metadata +4 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "faraday"
|
|
4
|
+
|
|
5
|
+
module Exa
|
|
6
|
+
module CLI
|
|
7
|
+
# Faraday request middleware for --print-request. It writes the request
|
|
8
|
+
# body to stderr as one line, then sends the request. It sits after
|
|
9
|
+
# Faraday's :json middleware, so the body is the JSON string that goes
|
|
10
|
+
# out on the wire. $stderr is read on each call, so a test that swaps
|
|
11
|
+
# $stderr sees the output.
|
|
12
|
+
class RequestPrinter < Faraday::Middleware
|
|
13
|
+
# Print the encoded body, when the request has one, then pass the
|
|
14
|
+
# request on to the rest of the stack.
|
|
15
|
+
def call(env)
|
|
16
|
+
$stderr.puts env.body if env.body
|
|
17
|
+
@app.call(env)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Client that prints each request body with RequestPrinter. It lives in
|
|
22
|
+
# the CLI namespace so that the printing is not part of the library's
|
|
23
|
+
# Ruby API. Exa::Client itself does not change.
|
|
24
|
+
class PrintingClient < Exa::Client
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
# Add RequestPrinter to the connection that Exa::Client builds. The
|
|
28
|
+
# memo stops a second insert on later calls, and the insert happens
|
|
29
|
+
# before the first request, while Faraday still lets the stack change.
|
|
30
|
+
def connection
|
|
31
|
+
@printing_connection ||= super.tap do |faraday_connection|
|
|
32
|
+
faraday_connection.builder.insert_after(Faraday::Request::Json, RequestPrinter)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -13,17 +13,85 @@ module Exa
|
|
|
13
13
|
"personal site", "people", "financial report"
|
|
14
14
|
].freeze
|
|
15
15
|
|
|
16
|
+
# Every flag exa-ai search accepts. Public API: wrappers read it here or
|
|
17
|
+
# through `exa-ai search --flags-json`, and the parser rejects any "--"
|
|
18
|
+
# argument that is not in it. api_field is the request body path the
|
|
19
|
+
# flag sets (nil when it sets none, an Array when it sets several), and
|
|
20
|
+
# replacement is what to type instead of a deprecated flag. reason says
|
|
21
|
+
# why a deprecated flag with no replacement is deprecated (nil for every
|
|
22
|
+
# other flag, and for a deprecated flag whose reason is not known). --help and
|
|
23
|
+
# --flags-json are in the list, but exe/exa-ai-search handles them before
|
|
24
|
+
# it calls the parser, which has no branch for them.
|
|
25
|
+
FLAGS = [
|
|
26
|
+
{ flag: "--num-results", api_field: "numResults", deprecated: false, replacement: nil, reason: nil },
|
|
27
|
+
{ flag: "--type", api_field: "type", deprecated: false, replacement: nil, reason: nil },
|
|
28
|
+
{ flag: "--category", api_field: "category", deprecated: false, replacement: nil, reason: nil },
|
|
29
|
+
{ flag: "--include-domains", api_field: "includeDomains", deprecated: false, replacement: nil, reason: nil },
|
|
30
|
+
{ flag: "--exclude-domains", api_field: "excludeDomains", deprecated: false, replacement: nil, reason: nil },
|
|
31
|
+
{ flag: "--start-published-date", api_field: "startPublishedDate", deprecated: false, replacement: nil, reason: nil },
|
|
32
|
+
{ flag: "--end-published-date", api_field: "endPublishedDate", deprecated: false, replacement: nil, reason: nil },
|
|
33
|
+
{ flag: "--start-crawl-date", api_field: "startCrawlDate", deprecated: true, replacement: nil,
|
|
34
|
+
reason: "the API ignores it and returns a warning" },
|
|
35
|
+
{ flag: "--end-crawl-date", api_field: "endCrawlDate", deprecated: true, replacement: nil,
|
|
36
|
+
reason: "the API ignores it and returns a warning" },
|
|
37
|
+
{ flag: "--include-text", api_field: "includeText", deprecated: true, replacement: nil, reason: nil },
|
|
38
|
+
{ flag: "--exclude-text", api_field: "excludeText", deprecated: true, replacement: nil, reason: nil },
|
|
39
|
+
{ flag: "--text", api_field: "contents.text", deprecated: false, replacement: nil, reason: nil },
|
|
40
|
+
{ flag: "--text-max-characters", api_field: "contents.text.maxCharacters", deprecated: false, replacement: nil, reason: nil },
|
|
41
|
+
{ flag: "--text-verbosity", api_field: "contents.text.verbosity", deprecated: false, replacement: nil, reason: nil },
|
|
42
|
+
{ flag: "--include-html-tags", api_field: "contents.text.includeHtmlTags", deprecated: false, replacement: nil, reason: nil },
|
|
43
|
+
{ flag: "--summary", api_field: "contents.summary", deprecated: false, replacement: nil, reason: nil },
|
|
44
|
+
{ flag: "--summary-query", api_field: "contents.summary.query", deprecated: false, replacement: nil, reason: nil },
|
|
45
|
+
{ flag: "--summary-schema", api_field: "contents.summary.schema", deprecated: false, replacement: nil, reason: nil },
|
|
46
|
+
{ flag: "--context", api_field: "contents.context", deprecated: true, replacement: "--highlights or --text", reason: nil },
|
|
47
|
+
{ flag: "--context-max-characters", api_field: "contents.context.maxCharacters", deprecated: true,
|
|
48
|
+
replacement: nil, reason: "it sets the length of --context, which is deprecated" },
|
|
49
|
+
{ flag: "--subpages", api_field: "contents.subpages", deprecated: true,
|
|
50
|
+
replacement: "exa-ai get-contents --subpages", reason: nil },
|
|
51
|
+
{ flag: "--subpage-target", api_field: "contents.subpageTarget", deprecated: true,
|
|
52
|
+
replacement: "exa-ai get-contents --subpage-target", reason: nil },
|
|
53
|
+
{ flag: "--links", api_field: "contents.extras.links", deprecated: false, replacement: nil, reason: nil },
|
|
54
|
+
{ flag: "--image-links", api_field: "contents.extras.imageLinks", deprecated: false, replacement: nil, reason: nil },
|
|
55
|
+
{ flag: "--highlights", api_field: "contents.highlights", deprecated: false, replacement: nil, reason: nil },
|
|
56
|
+
{ flag: "--highlights-max-characters", api_field: "contents.highlights.maxCharacters", deprecated: false,
|
|
57
|
+
replacement: nil, reason: nil },
|
|
58
|
+
{ flag: "--highlights-num-sentences", api_field: "contents.highlights.numSentences", deprecated: true,
|
|
59
|
+
replacement: "--highlights-max-characters", reason: nil },
|
|
60
|
+
{ flag: "--highlights-per-url", api_field: "contents.highlights.highlightsPerUrl", deprecated: true,
|
|
61
|
+
replacement: nil, reason: "the API ignores it" },
|
|
62
|
+
{ flag: "--highlights-query", api_field: "contents.highlights.query", deprecated: false, replacement: nil, reason: nil },
|
|
63
|
+
{ flag: "--livecrawl", api_field: ["contents.maxAgeHours", "contents.livecrawlTimeout"].freeze,
|
|
64
|
+
deprecated: true, replacement: "--max-age-hours 0 --livecrawl-timeout 5000", reason: nil },
|
|
65
|
+
{ flag: "--livecrawl-timeout", api_field: "contents.livecrawlTimeout", deprecated: false, replacement: nil, reason: nil },
|
|
66
|
+
{ flag: "--max-age-hours", api_field: "contents.maxAgeHours", deprecated: false, replacement: nil, reason: nil },
|
|
67
|
+
{ flag: "--snapshot-as-of", api_field: "contents.snapshotAsOf", deprecated: false, replacement: nil, reason: nil },
|
|
68
|
+
{ flag: "--additional-queries", api_field: "additionalQueries", deprecated: false, replacement: nil, reason: nil },
|
|
69
|
+
{ flag: "--output-schema", api_field: "outputSchema", deprecated: false, replacement: nil, reason: nil },
|
|
70
|
+
{ flag: "--user-location", api_field: "userLocation", deprecated: false, replacement: nil, reason: nil },
|
|
71
|
+
{ flag: "--objective", api_field: "objective", deprecated: false, replacement: nil, reason: nil },
|
|
72
|
+
{ flag: "--user-identifier", api_field: "userIdentifier", deprecated: false, replacement: nil, reason: nil },
|
|
73
|
+
{ flag: "--compliance", api_field: "compliance", deprecated: false, replacement: nil, reason: nil },
|
|
74
|
+
{ flag: "--system-prompt", api_field: "systemPrompt", deprecated: false, replacement: nil, reason: nil },
|
|
75
|
+
{ flag: "--moderation", api_field: "moderation", deprecated: false, replacement: nil, reason: nil },
|
|
76
|
+
{ flag: "--api-key", api_field: nil, deprecated: false, replacement: nil, reason: nil },
|
|
77
|
+
{ flag: "--output-format", api_field: nil, deprecated: false, replacement: nil, reason: nil },
|
|
78
|
+
{ flag: "--print-request", api_field: nil, deprecated: false, replacement: nil, reason: nil },
|
|
79
|
+
{ flag: "--strict", api_field: nil, deprecated: false, replacement: nil, reason: nil },
|
|
80
|
+
{ flag: "--flags-json", api_field: nil, deprecated: false, replacement: nil, reason: nil },
|
|
81
|
+
{ flag: "--help", api_field: nil, deprecated: false, replacement: nil, reason: nil }
|
|
82
|
+
].map(&:freeze).freeze
|
|
83
|
+
|
|
16
84
|
def self.parse(argv)
|
|
17
85
|
new(argv).parse
|
|
18
86
|
end
|
|
19
87
|
|
|
20
88
|
# A country code stays a string. An argument that starts with "{" is
|
|
21
89
|
# parsed as a JSON object, and one that starts with "@" is read as a
|
|
22
|
-
# JSON file, the way --output-schema works.
|
|
23
|
-
# so
|
|
24
|
-
# one error line that names
|
|
90
|
+
# JSON file, the way --output-schema works. Callers check for a missing
|
|
91
|
+
# value first with Base.text_value, so value is never nil. Bad JSON or
|
|
92
|
+
# an unreadable file exits 1 with one error line that names
|
|
93
|
+
# --user-location.
|
|
25
94
|
def self.parse_user_location(value)
|
|
26
|
-
return nil if value.nil?
|
|
27
95
|
return Base.parse_json_or_file("--user-location", value) if value.start_with?("@", "{")
|
|
28
96
|
|
|
29
97
|
value
|
|
@@ -33,7 +101,8 @@ module Exa
|
|
|
33
101
|
@argv = argv
|
|
34
102
|
@args = {
|
|
35
103
|
output_format: "json",
|
|
36
|
-
api_key: nil
|
|
104
|
+
api_key: nil,
|
|
105
|
+
deprecated_flags: []
|
|
37
106
|
}
|
|
38
107
|
end
|
|
39
108
|
|
|
@@ -51,6 +120,12 @@ module Exa
|
|
|
51
120
|
|
|
52
121
|
while i < @argv.length
|
|
53
122
|
arg = @argv[i]
|
|
123
|
+
if arg.start_with?("--")
|
|
124
|
+
entry = FLAGS.find { |candidate| candidate[:flag] == arg }
|
|
125
|
+
Exa::CLI::Base.reject_unknown_option(arg) unless entry
|
|
126
|
+
@args[:deprecated_flags] << entry if entry[:deprecated]
|
|
127
|
+
end
|
|
128
|
+
|
|
54
129
|
next_index = ContentsFlags.parse(@argv, i, @args)
|
|
55
130
|
if next_index
|
|
56
131
|
i = next_index
|
|
@@ -62,74 +137,80 @@ module Exa
|
|
|
62
137
|
@args[:num_results] = Exa::CLI::Base.parse_integer("--num-results", @argv[i + 1])
|
|
63
138
|
i += 2
|
|
64
139
|
when "--type"
|
|
65
|
-
search_type = @argv[i + 1]
|
|
140
|
+
search_type = Exa::CLI::Base.text_value("--type", @argv[i + 1])
|
|
66
141
|
validate_search_type(search_type)
|
|
67
142
|
@args[:type] = search_type
|
|
68
143
|
i += 2
|
|
69
144
|
when "--category"
|
|
70
|
-
category = @argv[i + 1]
|
|
145
|
+
category = Exa::CLI::Base.text_value("--category", @argv[i + 1])
|
|
71
146
|
validate_category(category)
|
|
72
147
|
@args[:category] = category
|
|
73
148
|
i += 2
|
|
74
149
|
when "--include-domains"
|
|
75
|
-
@args[:include_domains] = Exa::CLI::Base.
|
|
150
|
+
@args[:include_domains] = Exa::CLI::Base.text_value("--include-domains", @argv[i + 1]).split(",").map(&:strip)
|
|
76
151
|
i += 2
|
|
77
152
|
when "--exclude-domains"
|
|
78
|
-
@args[:exclude_domains] = Exa::CLI::Base.
|
|
153
|
+
@args[:exclude_domains] = Exa::CLI::Base.text_value("--exclude-domains", @argv[i + 1]).split(",").map(&:strip)
|
|
79
154
|
i += 2
|
|
80
155
|
when "--api-key"
|
|
81
|
-
@args[:api_key] = @argv[i + 1]
|
|
156
|
+
@args[:api_key] = Exa::CLI::Base.text_value("--api-key", @argv[i + 1])
|
|
82
157
|
i += 2
|
|
83
158
|
when "--output-format"
|
|
84
|
-
@args[:output_format] = @argv[i + 1]
|
|
159
|
+
@args[:output_format] = Exa::CLI::Base.text_value("--output-format", @argv[i + 1])
|
|
85
160
|
i += 2
|
|
86
161
|
when "--start-published-date"
|
|
87
|
-
@args[:start_published_date] = @argv[i + 1]
|
|
162
|
+
@args[:start_published_date] = Exa::CLI::Base.text_value("--start-published-date", @argv[i + 1])
|
|
88
163
|
i += 2
|
|
89
164
|
when "--end-published-date"
|
|
90
|
-
@args[:end_published_date] = @argv[i + 1]
|
|
165
|
+
@args[:end_published_date] = Exa::CLI::Base.text_value("--end-published-date", @argv[i + 1])
|
|
91
166
|
i += 2
|
|
92
167
|
when "--start-crawl-date"
|
|
93
|
-
@args[:start_crawl_date] = @argv[i + 1]
|
|
168
|
+
@args[:start_crawl_date] = Exa::CLI::Base.text_value("--start-crawl-date", @argv[i + 1])
|
|
94
169
|
i += 2
|
|
95
170
|
when "--end-crawl-date"
|
|
96
|
-
@args[:end_crawl_date] = @argv[i + 1]
|
|
171
|
+
@args[:end_crawl_date] = Exa::CLI::Base.text_value("--end-crawl-date", @argv[i + 1])
|
|
97
172
|
i += 2
|
|
98
173
|
when "--include-text"
|
|
99
174
|
@args[:include_text] ||= []
|
|
100
|
-
@args[:include_text] << @argv[i + 1]
|
|
175
|
+
@args[:include_text] << Exa::CLI::Base.text_value("--include-text", @argv[i + 1])
|
|
101
176
|
i += 2
|
|
102
177
|
when "--exclude-text"
|
|
103
178
|
@args[:exclude_text] ||= []
|
|
104
|
-
@args[:exclude_text] << @argv[i + 1]
|
|
179
|
+
@args[:exclude_text] << Exa::CLI::Base.text_value("--exclude-text", @argv[i + 1])
|
|
105
180
|
i += 2
|
|
106
181
|
when "--additional-queries"
|
|
107
182
|
@args[:additional_queries] ||= []
|
|
108
|
-
@args[:additional_queries] << @argv[i + 1]
|
|
183
|
+
@args[:additional_queries] << Exa::CLI::Base.text_value("--additional-queries", @argv[i + 1])
|
|
109
184
|
i += 2
|
|
110
185
|
when "--output-schema"
|
|
111
186
|
@args[:output_schema] = Exa::CLI::Base.parse_json_or_file("--output-schema", @argv[i + 1])
|
|
112
187
|
i += 2
|
|
113
188
|
when "--user-location"
|
|
114
|
-
@args[:user_location] = self.class.parse_user_location(@argv[i + 1])
|
|
189
|
+
@args[:user_location] = self.class.parse_user_location(Exa::CLI::Base.text_value("--user-location", @argv[i + 1]))
|
|
115
190
|
i += 2
|
|
116
191
|
when "--objective"
|
|
117
|
-
@args[:objective] = @argv[i + 1]
|
|
192
|
+
@args[:objective] = Exa::CLI::Base.text_value("--objective", @argv[i + 1])
|
|
118
193
|
i += 2
|
|
119
194
|
when "--user-identifier"
|
|
120
|
-
@args[:user_identifier] = @argv[i + 1]
|
|
195
|
+
@args[:user_identifier] = Exa::CLI::Base.text_value("--user-identifier", @argv[i + 1])
|
|
121
196
|
i += 2
|
|
122
197
|
when "--compliance"
|
|
123
|
-
compliance = @argv[i + 1]
|
|
198
|
+
compliance = Exa::CLI::Base.text_value("--compliance", @argv[i + 1])
|
|
124
199
|
validate_compliance(compliance)
|
|
125
200
|
@args[:compliance] = compliance
|
|
126
201
|
i += 2
|
|
127
202
|
when "--system-prompt"
|
|
128
|
-
@args[:system_prompt] = @argv[i + 1]
|
|
203
|
+
@args[:system_prompt] = Exa::CLI::Base.text_value("--system-prompt", @argv[i + 1])
|
|
129
204
|
i += 2
|
|
130
205
|
when "--moderation"
|
|
131
206
|
@args[:moderation] = true
|
|
132
207
|
i += 1
|
|
208
|
+
when "--print-request"
|
|
209
|
+
@args[:print_request] = true
|
|
210
|
+
i += 1
|
|
211
|
+
when "--strict"
|
|
212
|
+
@args[:strict] = true
|
|
213
|
+
i += 1
|
|
133
214
|
else
|
|
134
215
|
Exa::CLI::Base.reject_unknown_option(arg) if arg.start_with?("--")
|
|
135
216
|
|
|
@@ -145,23 +226,28 @@ module Exa
|
|
|
145
226
|
raise ArgumentError, "Query is required" if @args[:query].nil? || @args[:query].empty?
|
|
146
227
|
end
|
|
147
228
|
|
|
229
|
+
# Raises ArgumentError unless search_type is a value the API accepts.
|
|
230
|
+
# The message names the flag, so exa-ai search prints it as is.
|
|
148
231
|
def validate_search_type(search_type)
|
|
149
232
|
return if VALID_SEARCH_TYPES.include?(search_type)
|
|
150
233
|
|
|
151
|
-
raise ArgumentError, "
|
|
234
|
+
raise ArgumentError, "--type must be one of: #{VALID_SEARCH_TYPES.join(', ')}"
|
|
152
235
|
end
|
|
153
236
|
|
|
237
|
+
# Raises ArgumentError unless category is a value the API accepts.
|
|
238
|
+
# The message names the flag, so exa-ai search prints it as is.
|
|
154
239
|
def validate_category(category)
|
|
155
240
|
return if VALID_CATEGORIES.include?(category)
|
|
156
241
|
|
|
157
|
-
raise ArgumentError, "
|
|
242
|
+
raise ArgumentError, "--category must be one of: #{VALID_CATEGORIES.map { |c| "\"#{c}\"" }.join(', ')}"
|
|
158
243
|
end
|
|
159
244
|
|
|
160
245
|
# Raises ArgumentError unless compliance is a value the API accepts.
|
|
246
|
+
# The message names the flag, so exa-ai search prints it as is.
|
|
161
247
|
def validate_compliance(compliance)
|
|
162
248
|
return if VALID_COMPLIANCE.include?(compliance)
|
|
163
249
|
|
|
164
|
-
raise ArgumentError, "
|
|
250
|
+
raise ArgumentError, "--compliance must be one of: #{VALID_COMPLIANCE.join(', ')}"
|
|
165
251
|
end
|
|
166
252
|
end
|
|
167
253
|
end
|
data/lib/exa/version.rb
CHANGED
data/lib/exa.rb
CHANGED
|
@@ -46,6 +46,7 @@ require_relative "exa/services/search_stream"
|
|
|
46
46
|
require_relative "exa/services/context"
|
|
47
47
|
require_relative "exa/client"
|
|
48
48
|
require_relative "exa/cli/base"
|
|
49
|
+
require_relative "exa/cli/request_printer"
|
|
49
50
|
require_relative "exa/cli/polling"
|
|
50
51
|
require_relative "exa/cli/error_handler"
|
|
51
52
|
require_relative "exa/cli/formatters/search_formatter"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: exa-ai
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Benjamin Jackson
|
|
@@ -143,6 +143,7 @@ executables:
|
|
|
143
143
|
extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
|
145
145
|
files:
|
|
146
|
+
- CHANGELOG.md
|
|
146
147
|
- LICENSE
|
|
147
148
|
- README.md
|
|
148
149
|
- exe/exa-ai
|
|
@@ -178,7 +179,9 @@ files:
|
|
|
178
179
|
- lib/exa/cli/formatters/context_formatter.rb
|
|
179
180
|
- lib/exa/cli/formatters/search_formatter.rb
|
|
180
181
|
- lib/exa/cli/formatters/search_monitor_formatter.rb
|
|
182
|
+
- lib/exa/cli/get_contents.rb
|
|
181
183
|
- lib/exa/cli/polling.rb
|
|
184
|
+
- lib/exa/cli/request_printer.rb
|
|
182
185
|
- lib/exa/cli/search_parser.rb
|
|
183
186
|
- lib/exa/client.rb
|
|
184
187
|
- lib/exa/connection.rb
|