exa-ai 0.3.0 → 0.4.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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +94 -591
  3. data/exe/exa-ai +112 -9
  4. data/exe/exa-ai-answer +1 -5
  5. data/exe/exa-ai-context +1 -4
  6. data/exe/exa-ai-enrichment-cancel +107 -0
  7. data/exe/exa-ai-enrichment-create +235 -0
  8. data/exe/exa-ai-enrichment-delete +121 -0
  9. data/exe/exa-ai-enrichment-get +103 -0
  10. data/exe/exa-ai-enrichment-list +98 -0
  11. data/exe/exa-ai-enrichment-update +170 -0
  12. data/exe/exa-ai-find-similar +240 -0
  13. data/exe/exa-ai-get-contents +1 -4
  14. data/exe/exa-ai-research-get +1 -2
  15. data/exe/exa-ai-research-list +1 -2
  16. data/exe/exa-ai-research-start +1 -3
  17. data/exe/exa-ai-search +1 -3
  18. data/exe/exa-ai-webset-cancel +96 -0
  19. data/exe/exa-ai-webset-create +192 -0
  20. data/exe/exa-ai-webset-delete +110 -0
  21. data/exe/exa-ai-webset-get +92 -0
  22. data/exe/exa-ai-webset-item-delete +111 -0
  23. data/exe/exa-ai-webset-item-get +104 -0
  24. data/exe/exa-ai-webset-item-list +93 -0
  25. data/exe/exa-ai-webset-list +90 -0
  26. data/exe/exa-ai-webset-search-cancel +103 -0
  27. data/exe/exa-ai-webset-search-create +233 -0
  28. data/exe/exa-ai-webset-search-get +104 -0
  29. data/exe/exa-ai-webset-update +139 -0
  30. data/lib/exa/cli/base.rb +3 -3
  31. data/lib/exa/cli/formatters/enrichment_formatter.rb +69 -0
  32. data/lib/exa/cli/formatters/webset_formatter.rb +68 -0
  33. data/lib/exa/cli/formatters/webset_item_formatter.rb +69 -0
  34. data/lib/exa/client.rb +172 -0
  35. data/lib/exa/connection.rb +8 -1
  36. data/lib/exa/resources/webset.rb +74 -0
  37. data/lib/exa/resources/webset_collection.rb +33 -0
  38. data/lib/exa/resources/webset_enrichment.rb +71 -0
  39. data/lib/exa/resources/webset_enrichment_collection.rb +28 -0
  40. data/lib/exa/resources/webset_search.rb +112 -0
  41. data/lib/exa/services/parameter_converter.rb +1 -0
  42. data/lib/exa/services/websets/cancel.rb +36 -0
  43. data/lib/exa/services/websets/cancel_enrichment.rb +35 -0
  44. data/lib/exa/services/websets/cancel_search.rb +44 -0
  45. data/lib/exa/services/websets/create.rb +45 -0
  46. data/lib/exa/services/websets/create_enrichment.rb +35 -0
  47. data/lib/exa/services/websets/create_search.rb +48 -0
  48. data/lib/exa/services/websets/create_search_validator.rb +128 -0
  49. data/lib/exa/services/websets/create_validator.rb +189 -0
  50. data/lib/exa/services/websets/delete.rb +36 -0
  51. data/lib/exa/services/websets/delete_enrichment.rb +35 -0
  52. data/lib/exa/services/websets/delete_item.rb +20 -0
  53. data/lib/exa/services/websets/get_item.rb +20 -0
  54. data/lib/exa/services/websets/get_search.rb +43 -0
  55. data/lib/exa/services/websets/list.rb +25 -0
  56. data/lib/exa/services/websets/list_items.rb +20 -0
  57. data/lib/exa/services/websets/retrieve.rb +47 -0
  58. data/lib/exa/services/websets/retrieve_enrichment.rb +35 -0
  59. data/lib/exa/services/websets/update.rb +37 -0
  60. data/lib/exa/services/websets/update_enrichment.rb +36 -0
  61. data/lib/exa/services/websets_parameter_converter.rb +45 -0
  62. data/lib/exa/version.rb +1 -1
  63. data/lib/exa-ai.rb +5 -0
  64. data/lib/exa.rb +26 -0
  65. metadata +65 -3
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "exa-ai"
5
+
6
+ # Parse arguments
7
+ webset_id = nil
8
+ enrichment_id = nil
9
+ api_key = nil
10
+ output_format = "json"
11
+
12
+ args = ARGV.dup
13
+ while args.any?
14
+ arg = args.shift
15
+ case arg
16
+ when "--api-key"
17
+ api_key = args.shift
18
+ when "--output-format"
19
+ output_format = args.shift
20
+ when "--help", "-h"
21
+ puts <<~HELP
22
+ Usage: exa-ai enrichment-get <webset_id> <enrichment_id> [OPTIONS]
23
+
24
+ Retrieve details for an enrichment
25
+
26
+ Arguments:
27
+ webset_id ID of the webset (required)
28
+ enrichment_id ID of the enrichment to retrieve (required)
29
+
30
+ Options:
31
+ --api-key KEY Exa API key (or set EXA_API_KEY env var)
32
+ --output-format FMT Output format: json, pretty, or text (default: json)
33
+ --help, -h Show this help message
34
+
35
+ Examples:
36
+ exa-ai enrichment-get ws_123 enr_456
37
+ exa-ai enrichment-get ws_123 enr_456 --output-format pretty
38
+ HELP
39
+ exit 0
40
+ else
41
+ # First positional argument is webset_id, second is enrichment_id
42
+ if webset_id.nil?
43
+ webset_id = arg
44
+ elsif enrichment_id.nil?
45
+ enrichment_id = arg
46
+ else
47
+ $stderr.puts "Unknown option: #{arg}"
48
+ exit 1
49
+ end
50
+ end
51
+ end
52
+
53
+ # Validate
54
+ if webset_id.nil?
55
+ $stderr.puts "Error: webset_id argument is required"
56
+ $stderr.puts "Usage: exa-ai enrichment-get <webset_id> <enrichment_id> [OPTIONS]"
57
+ $stderr.puts "Try 'exa-ai enrichment-get --help' for more information"
58
+ exit 1
59
+ end
60
+
61
+ if enrichment_id.nil?
62
+ $stderr.puts "Error: enrichment_id argument is required"
63
+ $stderr.puts "Usage: exa-ai enrichment-get <webset_id> <enrichment_id> [OPTIONS]"
64
+ $stderr.puts "Try 'exa-ai enrichment-get --help' for more information"
65
+ exit 1
66
+ end
67
+
68
+ begin
69
+ # Resolve API key and format
70
+ api_key = Exa::CLI::Base.resolve_api_key(api_key)
71
+ output_format = Exa::CLI::Base.resolve_output_format(output_format)
72
+
73
+ # Build client
74
+ client = Exa::CLI::Base.build_client(api_key)
75
+
76
+ # Get enrichment
77
+ enrichment = client.get_enrichment(webset_id: webset_id, id: enrichment_id)
78
+
79
+ # Format and output
80
+ output = Exa::CLI::Formatters::EnrichmentFormatter.format(enrichment, output_format)
81
+ puts output
82
+
83
+ rescue Exa::NotFound => e
84
+ $stderr.puts "Enrichment not found: #{e.message}"
85
+ exit 1
86
+ rescue Exa::Unauthorized => e
87
+ $stderr.puts "Authentication error: #{e.message}"
88
+ $stderr.puts "Check your API key (set EXA_API_KEY or use --api-key)"
89
+ exit 1
90
+ rescue Exa::ClientError => e
91
+ $stderr.puts "Client error: #{e.message}"
92
+ exit 1
93
+ rescue Exa::ServerError => e
94
+ $stderr.puts "Server error: #{e.message}"
95
+ exit 1
96
+ rescue Exa::Error => e
97
+ $stderr.puts "Error: #{e.message}"
98
+ exit 1
99
+ rescue StandardError => e
100
+ $stderr.puts "Unexpected error: #{e.message}"
101
+ $stderr.puts e.backtrace.first(5) if ENV["DEBUG"]
102
+ exit 1
103
+ end
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "exa-ai"
5
+
6
+ # Parse arguments
7
+ webset_id = nil
8
+ api_key = nil
9
+ output_format = "json"
10
+
11
+ args = ARGV.dup
12
+ while args.any?
13
+ arg = args.shift
14
+ case arg
15
+ when "--api-key"
16
+ api_key = args.shift
17
+ when "--output-format"
18
+ output_format = args.shift
19
+ when "--help", "-h"
20
+ puts <<~HELP
21
+ Usage: exa-ai enrichment-list <webset_id> [OPTIONS]
22
+
23
+ List all enrichments for a webset
24
+
25
+ Arguments:
26
+ webset_id ID of the webset (required)
27
+
28
+ Options:
29
+ --api-key KEY Exa API key (or set EXA_API_KEY env var)
30
+ --output-format FMT Output format: json, pretty, or text (default: json)
31
+ --help, -h Show this help message
32
+
33
+ Examples:
34
+ exa-ai enrichment-list ws_123
35
+ exa-ai enrichment-list ws_123 --output-format text
36
+ HELP
37
+ exit 0
38
+ else
39
+ # First positional argument is webset_id
40
+ if webset_id.nil?
41
+ webset_id = arg
42
+ else
43
+ $stderr.puts "Unknown option: #{arg}"
44
+ exit 1
45
+ end
46
+ end
47
+ end
48
+
49
+ # Validate
50
+ if webset_id.nil?
51
+ $stderr.puts "Error: webset_id argument is required"
52
+ $stderr.puts "Usage: exa-ai enrichment-list <webset_id> [OPTIONS]"
53
+ $stderr.puts "Try 'exa-ai enrichment-list --help' for more information"
54
+ exit 1
55
+ end
56
+
57
+ begin
58
+ # Resolve API key and format
59
+ api_key = Exa::CLI::Base.resolve_api_key(api_key)
60
+ output_format = Exa::CLI::Base.resolve_output_format(output_format)
61
+
62
+ # Build client
63
+ client = Exa::CLI::Base.build_client(api_key)
64
+
65
+ # Get webset to retrieve enrichments
66
+ webset = client.get_webset(webset_id)
67
+
68
+ # Extract enrichments array (or empty array if none)
69
+ enrichments_data = webset.enrichments || []
70
+
71
+ # Create collection
72
+ collection = Exa::Resources::WebsetEnrichmentCollection.new(data: enrichments_data)
73
+
74
+ # Format and output
75
+ output = Exa::CLI::Formatters::EnrichmentFormatter.format_collection(collection, output_format)
76
+ puts output
77
+
78
+ rescue Exa::NotFound => e
79
+ $stderr.puts "Webset not found: #{e.message}"
80
+ exit 1
81
+ rescue Exa::Unauthorized => e
82
+ $stderr.puts "Authentication error: #{e.message}"
83
+ $stderr.puts "Check your API key (set EXA_API_KEY or use --api-key)"
84
+ exit 1
85
+ rescue Exa::ClientError => e
86
+ $stderr.puts "Client error: #{e.message}"
87
+ exit 1
88
+ rescue Exa::ServerError => e
89
+ $stderr.puts "Server error: #{e.message}"
90
+ exit 1
91
+ rescue Exa::Error => e
92
+ $stderr.puts "Error: #{e.message}"
93
+ exit 1
94
+ rescue StandardError => e
95
+ $stderr.puts "Unexpected error: #{e.message}"
96
+ $stderr.puts e.backtrace.first(5) if ENV["DEBUG"]
97
+ exit 1
98
+ end
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "exa-ai"
5
+ require "json"
6
+
7
+ # Recursively convert hash keys from strings to symbols
8
+ def deep_symbolize_keys(obj)
9
+ case obj
10
+ when Hash
11
+ obj.each_with_object({}) do |(key, value), result|
12
+ result[key.to_sym] = deep_symbolize_keys(value)
13
+ end
14
+ when Array
15
+ obj.map { |item| deep_symbolize_keys(item) }
16
+ else
17
+ obj
18
+ end
19
+ end
20
+
21
+ # Helper to parse JSON string or load from file
22
+ def parse_json_or_file(value)
23
+ json_data = if value.start_with?("@")
24
+ file_path = value[1..]
25
+ JSON.parse(File.read(file_path))
26
+ else
27
+ JSON.parse(value)
28
+ end
29
+ deep_symbolize_keys(json_data)
30
+ rescue JSON::ParserError => e
31
+ $stderr.puts "Error: Invalid JSON: #{e.message}"
32
+ exit 1
33
+ rescue Errno::ENOENT => e
34
+ $stderr.puts "Error: File not found: #{e.message}"
35
+ exit 1
36
+ end
37
+
38
+ # Parse arguments
39
+ webset_id = nil
40
+ enrichment_id = nil
41
+ description = nil
42
+ format = nil
43
+ options = nil
44
+ metadata = nil
45
+ api_key = nil
46
+ output_format = "json"
47
+
48
+ args = ARGV.dup
49
+ while args.any?
50
+ arg = args.shift
51
+ case arg
52
+ when "--description"
53
+ description = args.shift
54
+ when "--format"
55
+ format = args.shift
56
+ when "--options"
57
+ options = parse_json_or_file(args.shift)
58
+ when "--metadata"
59
+ metadata = parse_json_or_file(args.shift)
60
+ when "--api-key"
61
+ api_key = args.shift
62
+ when "--output-format"
63
+ output_format = args.shift
64
+ when "--help", "-h"
65
+ puts <<~HELP
66
+ Usage: exa-ai enrichment-update <webset_id> <enrichment_id> [OPTIONS]
67
+
68
+ Update an enrichment's properties
69
+
70
+ Arguments:
71
+ webset_id ID of the webset (required)
72
+ enrichment_id ID of the enrichment to update (required)
73
+
74
+ Options:
75
+ --description TEXT What to extract
76
+ --format TYPE One of: text, url, options
77
+ --options JSON Array of {label: "..."} (supports @file.json)
78
+ --metadata JSON Custom metadata (supports @file.json)
79
+ --api-key KEY Exa API key (or set EXA_API_KEY env var)
80
+ --output-format FMT Output format: json, pretty, or text (default: json)
81
+ --help, -h Show this help message
82
+
83
+ Examples:
84
+ exa-ai enrichment-update ws_123 enr_456 --description "New description"
85
+ exa-ai enrichment-update ws_123 enr_456 --metadata '{"priority":"high"}'
86
+ exa-ai enrichment-update ws_123 enr_456 --options options.json --format options
87
+ HELP
88
+ exit 0
89
+ else
90
+ # First positional argument is webset_id, second is enrichment_id
91
+ if webset_id.nil?
92
+ webset_id = arg
93
+ elsif enrichment_id.nil?
94
+ enrichment_id = arg
95
+ else
96
+ $stderr.puts "Unknown option: #{arg}"
97
+ exit 1
98
+ end
99
+ end
100
+ end
101
+
102
+ # Validate required arguments
103
+ if webset_id.nil?
104
+ $stderr.puts "Error: webset_id argument is required"
105
+ $stderr.puts "Usage: exa-ai enrichment-update <webset_id> <enrichment_id> [OPTIONS]"
106
+ $stderr.puts "Try 'exa-ai enrichment-update --help' for more information"
107
+ exit 1
108
+ end
109
+
110
+ if enrichment_id.nil?
111
+ $stderr.puts "Error: enrichment_id argument is required"
112
+ $stderr.puts "Usage: exa-ai enrichment-update <webset_id> <enrichment_id> [OPTIONS]"
113
+ $stderr.puts "Try 'exa-ai enrichment-update --help' for more information"
114
+ exit 1
115
+ end
116
+
117
+ # Check that at least one update field is provided
118
+ if description.nil? && format.nil? && options.nil? && metadata.nil?
119
+ $stderr.puts "Error: at least one update field is required (--description, --format, --options, or --metadata)"
120
+ $stderr.puts "Try 'exa-ai enrichment-update --help' for more information"
121
+ exit 1
122
+ end
123
+
124
+ begin
125
+ # Resolve API key and format
126
+ api_key = Exa::CLI::Base.resolve_api_key(api_key)
127
+ output_format = Exa::CLI::Base.resolve_output_format(output_format)
128
+
129
+ # Build client
130
+ client = Exa::CLI::Base.build_client(api_key)
131
+
132
+ # Build update params (only include provided fields)
133
+ update_params = {}
134
+ update_params[:description] = description if description
135
+ update_params[:format] = format if format
136
+ update_params[:options] = options if options
137
+ update_params[:metadata] = metadata if metadata
138
+
139
+ # Update enrichment
140
+ enrichment = client.update_enrichment(webset_id: webset_id, id: enrichment_id, **update_params)
141
+
142
+ # Format and output
143
+ output = Exa::CLI::Formatters::EnrichmentFormatter.format(enrichment, output_format)
144
+ puts output
145
+
146
+ rescue Exa::NotFound => e
147
+ $stderr.puts "Enrichment not found: #{e.message}"
148
+ exit 1
149
+ rescue Exa::ConfigurationError => e
150
+ $stderr.puts "Configuration error: #{e.message}"
151
+ exit 1
152
+ rescue Exa::Unauthorized => e
153
+ $stderr.puts "Authentication error: #{e.message}"
154
+ $stderr.puts "Check your API key (set EXA_API_KEY or use --api-key)"
155
+ exit 1
156
+ rescue Exa::ClientError => e
157
+ $stderr.puts "Client error: #{e.message}"
158
+ exit 1
159
+ rescue Exa::ServerError => e
160
+ $stderr.puts "Server error: #{e.message}"
161
+ $stderr.puts "The Exa API may be experiencing issues. Please try again later."
162
+ exit 1
163
+ rescue Exa::Error => e
164
+ $stderr.puts "Error: #{e.message}"
165
+ exit 1
166
+ rescue StandardError => e
167
+ $stderr.puts "Unexpected error: #{e.message}"
168
+ $stderr.puts e.backtrace.first(5) if ENV["DEBUG"]
169
+ exit 1
170
+ end
@@ -0,0 +1,240 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "exa-ai"
5
+
6
+ # Parse command-line arguments
7
+ def parse_args(argv)
8
+ args = {
9
+ output_format: "json",
10
+ api_key: nil
11
+ }
12
+
13
+ # Extract URL (first non-flag argument)
14
+ url_found = false
15
+ i = 0
16
+ while i < argv.length
17
+ arg = argv[i]
18
+ case arg
19
+ when "--num-results"
20
+ args[:num_results] = argv[i + 1].to_i
21
+ i += 2
22
+ when "--exclude-source-domain"
23
+ args[:exclude_source_domain] = true
24
+ i += 1
25
+ when "--category"
26
+ category = argv[i + 1]
27
+ valid_categories = ["company", "research paper", "news", "pdf", "github", "tweet", "personal site", "linkedin profile", "financial report"]
28
+ unless valid_categories.include?(category)
29
+ $stderr.puts "Error: Category must be one of: #{valid_categories.map { |c| "\"#{c}\"" }.join(', ')}"
30
+ exit 1
31
+ end
32
+ args[:category] = category
33
+ i += 2
34
+ when "--include-domains"
35
+ args[:include_domains] = argv[i + 1].split(",").map(&:strip)
36
+ i += 2
37
+ when "--exclude-domains"
38
+ args[:exclude_domains] = argv[i + 1].split(",").map(&:strip)
39
+ i += 2
40
+ when "--start-published-date"
41
+ args[:start_published_date] = argv[i + 1]
42
+ i += 2
43
+ when "--end-published-date"
44
+ args[:end_published_date] = argv[i + 1]
45
+ i += 2
46
+ when "--start-crawl-date"
47
+ args[:start_crawl_date] = argv[i + 1]
48
+ i += 2
49
+ when "--end-crawl-date"
50
+ args[:end_crawl_date] = argv[i + 1]
51
+ i += 2
52
+ when "--include-text"
53
+ args[:include_text] ||= []
54
+ args[:include_text] << argv[i + 1]
55
+ i += 2
56
+ when "--exclude-text"
57
+ args[:exclude_text] ||= []
58
+ args[:exclude_text] << argv[i + 1]
59
+ i += 2
60
+ when "--text"
61
+ args[:text] = true
62
+ i += 1
63
+ when "--text-max-characters"
64
+ args[:text_max_characters] = argv[i + 1].to_i
65
+ i += 2
66
+ when "--include-html-tags"
67
+ args[:include_html_tags] = true
68
+ i += 1
69
+ when "--summary"
70
+ args[:summary] = true
71
+ i += 1
72
+ when "--summary-query"
73
+ args[:summary_query] = argv[i + 1]
74
+ i += 2
75
+ when "--summary-schema"
76
+ schema_arg = argv[i + 1]
77
+ args[:summary_schema] = if schema_arg.start_with?("@")
78
+ JSON.parse(File.read(schema_arg[1..]))
79
+ else
80
+ JSON.parse(schema_arg)
81
+ end
82
+ i += 2
83
+ when "--api-key"
84
+ args[:api_key] = argv[i + 1]
85
+ i += 2
86
+ when "--output-format"
87
+ args[:output_format] = argv[i + 1]
88
+ i += 2
89
+ when "--help", "-h"
90
+ puts <<~HELP
91
+ Usage: exa-ai find-similar URL [OPTIONS]
92
+
93
+ Find content similar to a given URL
94
+
95
+ Arguments:
96
+ URL URL to find similar content for (required)
97
+
98
+ Options:
99
+ --num-results N Number of results to return (default: 10)
100
+ --exclude-source-domain Exclude results from the source URL's domain
101
+ --category CAT Focus on specific data category
102
+ Options: "company", "research paper", "news", "pdf",
103
+ "github", "tweet", "personal site", "linkedin profile",
104
+ "financial report"
105
+ --include-domains D Comma-separated list of domains to include
106
+ --exclude-domains D Comma-separated list of domains to exclude
107
+ --start-published-date DATE Filter by published date (ISO 8601 format)
108
+ --end-published-date DATE Filter by published date (ISO 8601 format)
109
+ --start-crawl-date DATE Filter by crawl date (ISO 8601 format)
110
+ --end-crawl-date DATE Filter by crawl date (ISO 8601 format)
111
+ --include-text PHRASE Include results with exact phrase (repeatable)
112
+ --exclude-text PHRASE Exclude results with exact phrase (repeatable)
113
+
114
+ Content Extraction:
115
+ --text Include full webpage text
116
+ --text-max-characters N Max characters for webpage text
117
+ --include-html-tags Include HTML tags in text extraction
118
+ --summary Include AI-generated summary
119
+ --summary-query PROMPT Custom prompt for summary generation
120
+ --summary-schema FILE JSON schema for summary structure (@file syntax)
121
+
122
+ General Options:
123
+ --api-key KEY Exa API key (or set EXA_API_KEY env var)
124
+ --output-format FMT Output format: json, pretty, or text (default: json)
125
+ --help, -h Show this help message
126
+
127
+ Examples:
128
+ exa-ai find-similar "https://example.com/article"
129
+ exa-ai find-similar "https://techcrunch.com/ai-startup" --num-results 5
130
+ exa-ai find-similar "https://arxiv.org/paper" --category "research paper"
131
+ exa-ai find-similar "https://example.com" --exclude-source-domain
132
+ exa-ai find-similar "https://example.com" --output-format pretty
133
+ HELP
134
+ exit 0
135
+ else
136
+ unless url_found
137
+ args[:url] = arg
138
+ url_found = true
139
+ end
140
+ i += 1
141
+ end
142
+ end
143
+
144
+ args
145
+ end
146
+
147
+ # Build contents parameter from extracted flags
148
+ def build_contents(args)
149
+ contents = {}
150
+
151
+ # Text options
152
+ if args[:text]
153
+ if args[:text_max_characters] || args[:include_html_tags]
154
+ contents[:text] = {}
155
+ contents[:text][:max_characters] = args[:text_max_characters] if args[:text_max_characters]
156
+ contents[:text][:include_html_tags] = args[:include_html_tags] if args[:include_html_tags]
157
+ else
158
+ contents[:text] = true
159
+ end
160
+ end
161
+
162
+ # Summary options
163
+ if args[:summary]
164
+ if args[:summary_query] || args[:summary_schema]
165
+ contents[:summary] = {}
166
+ contents[:summary][:query] = args[:summary_query] if args[:summary_query]
167
+ contents[:summary][:schema] = args[:summary_schema] if args[:summary_schema]
168
+ else
169
+ contents[:summary] = true
170
+ end
171
+ end
172
+
173
+ contents.empty? ? nil : contents
174
+ end
175
+
176
+ # Main execution
177
+ begin
178
+ args = parse_args(ARGV)
179
+
180
+ # Validate URL
181
+ if args[:url].nil? || args[:url].empty?
182
+ $stderr.puts "Error: URL is required"
183
+ $stderr.puts "Run 'exa-ai find-similar --help' for usage information"
184
+ exit 1
185
+ end
186
+
187
+ # Resolve API key
188
+ api_key = Exa::CLI::Base.resolve_api_key(args[:api_key])
189
+
190
+ # Resolve output format
191
+ output_format = Exa::CLI::Base.resolve_output_format(args[:output_format])
192
+
193
+ # Build client
194
+ client = Exa::CLI::Base.build_client(api_key)
195
+
196
+ # Prepare parameters
197
+ params = {}
198
+ params[:numResults] = args[:num_results] if args[:num_results]
199
+ params[:excludeSourceDomain] = args[:exclude_source_domain] if args[:exclude_source_domain]
200
+ params[:category] = args[:category] if args[:category]
201
+ params[:includeDomains] = args[:include_domains] if args[:include_domains]
202
+ params[:excludeDomains] = args[:exclude_domains] if args[:exclude_domains]
203
+ params[:start_published_date] = args[:start_published_date] if args[:start_published_date]
204
+ params[:end_published_date] = args[:end_published_date] if args[:end_published_date]
205
+ params[:start_crawl_date] = args[:start_crawl_date] if args[:start_crawl_date]
206
+ params[:end_crawl_date] = args[:end_crawl_date] if args[:end_crawl_date]
207
+ params[:include_text] = args[:include_text] if args[:include_text]
208
+ params[:exclude_text] = args[:exclude_text] if args[:exclude_text]
209
+ contents = build_contents(args)
210
+ params.merge!(contents) if contents
211
+
212
+ # Execute find_similar
213
+ result = client.find_similar(args[:url], **params)
214
+
215
+ # Format and output result
216
+ output = Exa::CLI::Formatters::SearchFormatter.format(result, output_format)
217
+ puts output
218
+
219
+ rescue Exa::ConfigurationError => e
220
+ $stderr.puts "Configuration error: #{e.message}"
221
+ exit 1
222
+ rescue Exa::Unauthorized => e
223
+ $stderr.puts "Authentication error: #{e.message}"
224
+ $stderr.puts "Check your API key (set EXA_API_KEY or use --api-key)"
225
+ exit 1
226
+ rescue Exa::ClientError => e
227
+ $stderr.puts "Client error: #{e.message}"
228
+ exit 1
229
+ rescue Exa::ServerError => e
230
+ $stderr.puts "Server error: #{e.message}"
231
+ $stderr.puts "The Exa API may be experiencing issues. Please try again later."
232
+ exit 1
233
+ rescue Exa::Error => e
234
+ $stderr.puts "Error: #{e.message}"
235
+ exit 1
236
+ rescue StandardError => e
237
+ $stderr.puts "Unexpected error: #{e.message}"
238
+ $stderr.puts e.backtrace.first(5) if ENV["DEBUG"]
239
+ exit 1
240
+ end
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "exa"
6
- require "exa/cli/base"
7
- require "exa/cli/formatters/contents_formatter"
4
+ require "exa-ai"
8
5
 
9
6
  # Parse command line arguments
10
7
  def parse_args(args)
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "exa"
4
+ require "exa-ai"
6
5
 
7
6
  # Parse command-line arguments
8
7
  api_key = nil
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "exa"
4
+ require "exa-ai"
6
5
 
7
6
  # Parse command-line arguments
8
7
  api_key = nil
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # Set up load paths
5
- require "bundler/setup"
6
- require "exa"
4
+ require "exa-ai"
7
5
 
8
6
  # Parse command-line arguments
9
7
  def parse_args(argv)
data/exe/exa-ai-search CHANGED
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # Set up load paths
5
- require "bundler/setup"
6
- require "exa"
4
+ require "exa-ai"
7
5
 
8
6
  # Parse command-line arguments
9
7
  def parse_args(argv)