valyu-js 1.0.6 → 2.0.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.
package/README.md CHANGED
@@ -1,40 +1,319 @@
1
- # Valyu SDK for Node.js
1
+ # Valyu SDK
2
2
 
3
- Connect your AI applications to high-quality proprietary data with Valyu, an AI context engine built by AI Engineers for AI Engineers.
3
+ **DeepSearch API for AI**
4
4
 
5
- ## Why Valyu?
5
+ Valyu's Deepsearch API gives AI the context it needs. Integrate trusted, high-quality public and proprietary sources, with full-text multimodal retrieval.
6
6
 
7
- - **Ready-to-use RAG Data**: All data is returned in Markdown format, optimized for AI consumption.
8
- - **Multimodal Support**: Retrieve text, images, and other data types for comprehensive answers.
9
- - **Pay-per-use**: Transparent pricing—you only pay for what you use.
10
- - **Hybrid Search**: Combine proprietary dataset access with web search capabilities.
11
- - **Built for AI**: Designed specifically for Retrieval-Augmented Generation (RAG) applications.
7
+ Get **$10 free credits** for the Valyu API when you sign up at [Valyu](https://platform.valyu.network)!
8
+
9
+ *No credit card required.*
10
+
11
+ ## How does it work?
12
+
13
+ We do all the heavy lifting for you - through a single API we provide:
14
+
15
+ - **Academic & Research Content** - Access millions of scholarly papers and textbooks
16
+ - **Real-time Web Search** - Get the latest information from across the internet
17
+ - **Structured Financial Data** - Stock prices, market data, and financial metrics
18
+ - **Intelligent Reranking** - Results across all sources are automatically sorted by relevance
19
+ - **Transparent Pricing** - Pay only for what you use with clear CPM pricing
12
20
 
13
21
  ## Installation
14
22
 
15
- Install the Valyu SDK via npm:
23
+ Install the Valyu SDK using npm:
16
24
 
17
25
  ```bash
18
26
  npm install valyu
19
27
  ```
20
28
 
21
- Quick Start
22
- ```js
29
+ ## Quick Start
30
+
31
+ Here's what it looks like, make your first query in just 4 lines of code:
32
+
33
+ ```javascript
34
+ const { Valyu } = require('valyu');
35
+
36
+ const valyu = new Valyu("your-api-key-here");
37
+
38
+ const response = await valyu.search(
39
+ "Implementation details of agentic search-enhanced large reasoning models"
40
+ );
41
+
42
+ console.log(response);
43
+
44
+ // Feed the results to your AI agent as you would with other search APIs
45
+ ```
46
+
47
+ ## API Reference
48
+
49
+ ### Search Method
50
+
51
+ The `search()` method is the core of the Valyu SDK. It accepts a query string as the first parameter, followed by optional configuration parameters.
52
+
53
+ ```javascript
54
+ valyu.search(
55
+ query, // Your search query
56
+ {
57
+ searchType: "all", // "all", "web", or "proprietary"
58
+ maxNumResults: 10, // Maximum results to return (1-20)
59
+ isToolCall: true, // Whether this is an AI tool call
60
+ relevanceThreshold: 0.5, // Minimum relevance score (0-1)
61
+ maxPrice: 30, // Maximum price per thousand queries (CPM)
62
+ includedSources: [], // Specific sources to search
63
+ category: null, // Category filter
64
+ startDate: null, // Start date (YYYY-MM-DD)
65
+ endDate: null // End date (YYYY-MM-DD)
66
+ }
67
+ )
68
+ ```
69
+
70
+ ### Parameters
71
+
72
+ | Parameter | Type | Default | Description |
73
+ |-----------|------|---------|-------------|
74
+ | `query` | `string` | *required* | The search query string |
75
+ | `searchType` | `string` | `"all"` | Search scope: `"all"`, `"web"`, or `"proprietary"` |
76
+ | `maxNumResults` | `number` | `10` | Maximum number of results to return (1-20) |
77
+ | `isToolCall` | `boolean` | `true` | Whether this is an AI tool call (affects processing) |
78
+ | `relevanceThreshold` | `number` | `0.5` | Minimum relevance score for results (0.0-1.0) |
79
+ | `maxPrice` | `number` | `30` | Maximum price per thousand queries in CPM |
80
+ | `includedSources` | `string[]` | `[]` | Specific data sources or URLs to search |
81
+ | `category` | `string` | `null` | Category filter for results |
82
+ | `startDate` | `string` | `null` | Start date filter in YYYY-MM-DD format |
83
+ | `endDate` | `string` | `null` | End date filter in YYYY-MM-DD format |
84
+
85
+ ### Response Format
86
+
87
+ The search method returns a `SearchResponse` object with the following structure:
88
+
89
+ ```javascript
90
+ {
91
+ success: boolean, // Whether the search was successful
92
+ error: string | null, // Error message if any
93
+ tx_id: string, // Transaction ID for feedback
94
+ query: string, // The original query
95
+ results: SearchResult[], // List of search results
96
+ results_by_source: { // Count of results by source type
97
+ web: number,
98
+ proprietary: number
99
+ },
100
+ total_deduction_pcm: number, // Cost in CPM
101
+ total_deduction_dollars: number, // Cost in dollars
102
+ total_characters: number // Total characters returned
103
+ }
104
+ ```
105
+
106
+ Each `SearchResult` contains:
107
+
108
+ ```javascript
109
+ {
110
+ title: string, // Result title
111
+ url: string, // Source URL
112
+ content: string, // Full content
113
+ description?: string, // Brief description
114
+ source: string, // Source identifier
115
+ price: number, // Cost for this result
116
+ length: number, // Content length in characters
117
+ image_url?: Record<string, string>, // Associated images
118
+ relevance_score: number, // Relevance score (0-1)
119
+ data_type?: string // "structured" or "unstructured"
120
+ }
121
+ ```
122
+
123
+ ## Examples
124
+
125
+ ### Basic Search
126
+
127
+ ```javascript
23
128
  const { Valyu } = require('valyu');
24
129
 
25
- // Initialize the Valyu client (provide your API key)
26
130
  const valyu = new Valyu("your-api-key");
27
131
 
28
- // Get relevant context for your query
29
- (async () => {
30
- const response = await valyu.context(
31
- "Tell me about ancient civilizations", // query
32
- "proprietary", // search_type ("proprietary" or "web")
33
- 5, // num_query: number of queries to generate
34
- 3, // num_results: number of results per query
35
- 10 // max_price: maximum price per thousand queries
36
- );
37
- console.log(response);
38
- })();
132
+ // Simple search across all sources
133
+ const response = await valyu.search("What is machine learning?");
134
+ console.log(`Found ${response.results.length} results`);
135
+ ```
136
+
137
+ ### Academic Research
138
+
139
+ ```javascript
140
+ // Search academic papers on arXiv
141
+ const response = await valyu.search(
142
+ "agentic search-enhanced large reasoning models",
143
+ {
144
+ searchType: "proprietary",
145
+ maxNumResults: 10,
146
+ relevanceThreshold: 0.6,
147
+ includedSources: ["valyu/valyu-arxiv"],
148
+ startDate: "2024-05-01"
149
+ }
150
+ );
151
+ ```
152
+
153
+ ### Web Search with Date Filtering
154
+
155
+ ```javascript
156
+ // Search recent web content
157
+ const response = await valyu.search(
158
+ "what is claude 4 opus model",
159
+ {
160
+ searchType: "web",
161
+ maxNumResults: 7,
162
+ relevanceThreshold: 0.5,
163
+ startDate: "2024-01-01",
164
+ endDate: "2024-12-31"
165
+ }
166
+ );
167
+ ```
168
+
169
+ ### Hybrid Search
170
+
171
+ ```javascript
172
+ // Search both web and proprietary sources
173
+ const response = await valyu.search(
174
+ "quantum computing breakthroughs",
175
+ {
176
+ searchType: "all",
177
+ category: "technology",
178
+ relevanceThreshold: 0.6,
179
+ maxPrice: 50
180
+ }
181
+ );
182
+ ```
183
+
184
+ ### Processing Results
185
+
186
+ ```javascript
187
+ const response = await valyu.search("climate change solutions");
188
+
189
+ if (response.success) {
190
+ console.log(`Search cost: $${response.total_deduction_dollars.toFixed(4)}`);
191
+ console.log(`Sources: Web=${response.results_by_source.web}, Proprietary=${response.results_by_source.proprietary}`);
192
+
193
+ response.results.forEach((result, i) => {
194
+ console.log(`\n${i + 1}. ${result.title}`);
195
+ console.log(` Source: ${result.source}`);
196
+ console.log(` Relevance: ${result.relevance_score.toFixed(2)}`);
197
+ console.log(` Content: ${result.content.substring(0, 200)}...`);
198
+ });
199
+ } else {
200
+ console.log(`Search failed: ${response.error}`);
201
+ }
202
+ ```
203
+
204
+ ## Authentication
205
+
206
+ Set your API key in one of these ways:
207
+
208
+ 1. **Environment variable** (recommended):
209
+ ```bash
210
+ export VALYU_API_KEY="your-api-key-here"
211
+ ```
212
+
213
+ 2. **Direct initialization**:
214
+ ```javascript
215
+ const valyu = new Valyu("your-api-key-here");
216
+ ```
217
+
218
+ 3. **Custom base URL** (for staging/testing):
219
+ ```javascript
220
+ const valyu = new Valyu(
221
+ "your-api-key-here",
222
+ "https://stage.api.valyu.network/v1"
223
+ );
224
+ ```
225
+
226
+ ## Error Handling
227
+
228
+ The SDK handles errors gracefully and returns structured error responses:
229
+
230
+ ```javascript
231
+ const response = await valyu.search("test query");
232
+
233
+ if (!response.success) {
234
+ console.log(`Error: ${response.error}`);
235
+ console.log(`Transaction ID: ${response.tx_id}`);
236
+ } else {
237
+ // Process successful results
238
+ response.results.forEach(result => {
239
+ console.log(result.title);
240
+ });
241
+ }
242
+ ```
243
+
244
+ ## TypeScript Support
245
+
246
+ The SDK includes full TypeScript support:
247
+
248
+ ```typescript
249
+ import { Valyu, SearchOptions, SearchResponse } from 'valyu';
250
+
251
+ const valyu = new Valyu("your-api-key");
252
+
253
+ const options: SearchOptions = {
254
+ searchType: "proprietary",
255
+ maxNumResults: 10,
256
+ relevanceThreshold: 0.6
257
+ };
258
+
259
+ const response: SearchResponse = await valyu.search("machine learning", options);
39
260
  ```
40
261
 
262
+ ## Backward Compatibility
263
+
264
+ The legacy `context()` method is still supported but deprecated:
265
+
266
+ ```javascript
267
+ // Legacy method (deprecated)
268
+ const response = await valyu.context(
269
+ "neural networks basics",
270
+ {
271
+ searchType: "all",
272
+ maxNumResults: 5,
273
+ queryRewrite: true,
274
+ similarityThreshold: 0.5,
275
+ dataSources: ["valyu/valyu-arxiv"]
276
+ }
277
+ );
278
+ ```
279
+
280
+ **Migration from v1 to v2:**
281
+ - `context()` → `search()`
282
+ - `similarityThreshold` → `relevanceThreshold`
283
+ - `dataSources` → `includedSources`
284
+ - `queryRewrite` → `isToolCall`
285
+ - Default `relevanceThreshold` changed from `0.4` to `0.5`
286
+ - Default `maxPrice` changed from `1` to `30`
287
+
288
+ ## Getting Started
289
+
290
+ 1. Sign up for a free account at [Valyu](https://exchange.valyu.network)
291
+ 2. Get your API key from the dashboard
292
+ 3. Install the SDK: `npm install valyu`
293
+ 4. Start building with the examples above
294
+
295
+ ## Testing
296
+
297
+ Run the integration tests:
298
+
299
+ ```bash
300
+ npm run test:integration
301
+ ```
302
+
303
+ Run the v2 API examples:
304
+
305
+ ```bash
306
+ node examples/v2-api-examples.js
307
+ ```
308
+
309
+ ## Support
310
+
311
+ - **Documentation**: [docs.valyu.network](https://docs.valyu.network)
312
+ - **API Reference**: Full parameter documentation above
313
+ - **Examples**: Check the `examples/` directory in this repository
314
+ - **Issues**: Report bugs on GitHub
315
+
316
+ ## License
317
+
318
+ This project is licensed under the MIT License.
319
+
package/dist/index.d.mts CHANGED
@@ -12,6 +12,17 @@ interface SearchResult {
12
12
  relevance_score: number;
13
13
  data_type?: DataType;
14
14
  }
15
+ interface SearchOptions {
16
+ searchType?: SearchType;
17
+ maxNumResults?: number;
18
+ maxPrice?: number;
19
+ isToolCall?: boolean;
20
+ relevanceThreshold?: number;
21
+ includedSources?: string[];
22
+ category?: string;
23
+ startDate?: string;
24
+ endDate?: string;
25
+ }
15
26
  interface SearchResponse {
16
27
  success: boolean;
17
28
  error?: string;
@@ -35,19 +46,14 @@ declare class Valyu {
35
46
  private baseUrl;
36
47
  private headers;
37
48
  constructor(apiKey?: string, baseUrl?: string);
38
- context(query: string, options?: {
39
- searchType: SearchType;
40
- maxNumResults?: number;
41
- queryRewrite?: boolean;
42
- similarityThreshold?: number;
43
- maxPrice?: number;
44
- dataSources?: string[];
45
- }): Promise<SearchResponse>;
46
- feedback({ tx_id, feedback, sentiment }: {
47
- tx_id: string;
48
- feedback: string;
49
- sentiment: FeedbackSentiment;
50
- }): Promise<FeedbackResponse>;
49
+ /**
50
+ * Validates date format (YYYY-MM-DD)
51
+ */
52
+ private validateDateFormat;
53
+ /**
54
+ * Search for information using the Valyu API v2
55
+ */
56
+ search(query: string, options?: SearchOptions): Promise<SearchResponse>;
51
57
  }
52
58
 
53
- export { type FeedbackResponse, type FeedbackSentiment, type SearchResponse, type SearchType, Valyu };
59
+ export { type FeedbackResponse, type FeedbackSentiment, type SearchOptions, type SearchResponse, type SearchType, Valyu };
package/dist/index.d.ts CHANGED
@@ -12,6 +12,17 @@ interface SearchResult {
12
12
  relevance_score: number;
13
13
  data_type?: DataType;
14
14
  }
15
+ interface SearchOptions {
16
+ searchType?: SearchType;
17
+ maxNumResults?: number;
18
+ maxPrice?: number;
19
+ isToolCall?: boolean;
20
+ relevanceThreshold?: number;
21
+ includedSources?: string[];
22
+ category?: string;
23
+ startDate?: string;
24
+ endDate?: string;
25
+ }
15
26
  interface SearchResponse {
16
27
  success: boolean;
17
28
  error?: string;
@@ -35,19 +46,14 @@ declare class Valyu {
35
46
  private baseUrl;
36
47
  private headers;
37
48
  constructor(apiKey?: string, baseUrl?: string);
38
- context(query: string, options?: {
39
- searchType: SearchType;
40
- maxNumResults?: number;
41
- queryRewrite?: boolean;
42
- similarityThreshold?: number;
43
- maxPrice?: number;
44
- dataSources?: string[];
45
- }): Promise<SearchResponse>;
46
- feedback({ tx_id, feedback, sentiment }: {
47
- tx_id: string;
48
- feedback: string;
49
- sentiment: FeedbackSentiment;
50
- }): Promise<FeedbackResponse>;
49
+ /**
50
+ * Validates date format (YYYY-MM-DD)
51
+ */
52
+ private validateDateFormat;
53
+ /**
54
+ * Search for information using the Valyu API v2
55
+ */
56
+ search(query: string, options?: SearchOptions): Promise<SearchResponse>;
51
57
  }
52
58
 
53
- export { type FeedbackResponse, type FeedbackSentiment, type SearchResponse, type SearchType, Valyu };
59
+ export { type FeedbackResponse, type FeedbackSentiment, type SearchOptions, type SearchResponse, type SearchType, Valyu };
package/dist/index.js CHANGED
@@ -48,35 +48,106 @@ var Valyu = class {
48
48
  "x-api-key": apiKey
49
49
  };
50
50
  }
51
- async context(query, options = {
52
- searchType: "all",
53
- maxNumResults: 10,
54
- queryRewrite: true,
55
- similarityThreshold: 0.4,
56
- maxPrice: 1
57
- }) {
51
+ /**
52
+ * Validates date format (YYYY-MM-DD)
53
+ */
54
+ validateDateFormat(date) {
55
+ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
56
+ if (!dateRegex.test(date)) {
57
+ return false;
58
+ }
59
+ const parsedDate = new Date(date);
60
+ return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
61
+ }
62
+ /**
63
+ * Search for information using the Valyu API v2
64
+ */
65
+ async search(query, options = {}) {
58
66
  try {
59
- const {
60
- searchType,
61
- maxNumResults = 10,
62
- queryRewrite = true,
63
- similarityThreshold = 0.4,
64
- maxPrice = 1,
65
- dataSources
66
- } = options;
67
+ const defaultSearchType = "all";
68
+ const defaultMaxNumResults = 10;
69
+ const defaultIsToolCall = true;
70
+ const defaultRelevanceThreshold = 0.5;
71
+ const defaultMaxPrice = 30;
72
+ let finalSearchType = defaultSearchType;
73
+ const providedSearchTypeString = options.searchType?.toLowerCase();
74
+ if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all") {
75
+ finalSearchType = providedSearchTypeString;
76
+ } else if (options.searchType !== void 0) {
77
+ return {
78
+ success: false,
79
+ error: "Invalid searchType provided. Must be one of: all, web, proprietary",
80
+ tx_id: null,
81
+ query,
82
+ results: [],
83
+ results_by_source: { web: 0, proprietary: 0 },
84
+ total_deduction_pcm: 0,
85
+ total_deduction_dollars: 0,
86
+ total_characters: 0
87
+ };
88
+ }
89
+ if (options.startDate && !this.validateDateFormat(options.startDate)) {
90
+ return {
91
+ success: false,
92
+ error: "Invalid startDate format. Must be YYYY-MM-DD",
93
+ tx_id: null,
94
+ query,
95
+ results: [],
96
+ results_by_source: { web: 0, proprietary: 0 },
97
+ total_deduction_pcm: 0,
98
+ total_deduction_dollars: 0,
99
+ total_characters: 0
100
+ };
101
+ }
102
+ if (options.endDate && !this.validateDateFormat(options.endDate)) {
103
+ return {
104
+ success: false,
105
+ error: "Invalid endDate format. Must be YYYY-MM-DD",
106
+ tx_id: null,
107
+ query,
108
+ results: [],
109
+ results_by_source: { web: 0, proprietary: 0 },
110
+ total_deduction_pcm: 0,
111
+ total_deduction_dollars: 0,
112
+ total_characters: 0
113
+ };
114
+ }
115
+ const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;
116
+ if (maxNumResults < 1 || maxNumResults > 20) {
117
+ return {
118
+ success: false,
119
+ error: "maxNumResults must be between 1 and 20",
120
+ tx_id: null,
121
+ query,
122
+ results: [],
123
+ results_by_source: { web: 0, proprietary: 0 },
124
+ total_deduction_pcm: 0,
125
+ total_deduction_dollars: 0,
126
+ total_characters: 0
127
+ };
128
+ }
67
129
  const payload = {
68
130
  query,
69
- search_type: searchType,
131
+ search_type: finalSearchType,
70
132
  max_num_results: maxNumResults,
71
- query_rewrite: queryRewrite,
72
- similarity_threshold: similarityThreshold,
73
- max_price: maxPrice
133
+ is_tool_call: options.isToolCall ?? defaultIsToolCall,
134
+ relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,
135
+ max_price: options.maxPrice ?? defaultMaxPrice
74
136
  };
75
- if (dataSources !== void 0) {
76
- payload.data_sources = dataSources;
137
+ if (options.includedSources !== void 0) {
138
+ payload.included_sources = options.includedSources;
139
+ }
140
+ if (options.category !== void 0) {
141
+ payload.category = options.category;
142
+ }
143
+ if (options.startDate !== void 0) {
144
+ payload.start_date = options.startDate;
145
+ }
146
+ if (options.endDate !== void 0) {
147
+ payload.end_date = options.endDate;
77
148
  }
78
149
  const response = await import_axios.default.post(
79
- `${this.baseUrl}/knowledge`,
150
+ `${this.baseUrl}/deepsearch`,
80
151
  payload,
81
152
  { headers: this.headers }
82
153
  );
@@ -97,7 +168,7 @@ var Valyu = class {
97
168
  } catch (e) {
98
169
  return {
99
170
  success: false,
100
- error: e.message,
171
+ error: e.response?.data?.error || e.message,
101
172
  tx_id: null,
102
173
  query,
103
174
  results: [],
@@ -108,36 +179,6 @@ var Valyu = class {
108
179
  };
109
180
  }
110
181
  }
111
- async feedback({
112
- tx_id,
113
- feedback,
114
- sentiment
115
- }) {
116
- try {
117
- const payload = {
118
- tx_id,
119
- feedback,
120
- sentiment
121
- };
122
- const response = await import_axios.default.post(
123
- `${this.baseUrl}/feedback`,
124
- payload,
125
- { headers: this.headers }
126
- );
127
- if (!response.status || response.status < 200 || response.status >= 300) {
128
- return {
129
- success: false,
130
- error: response.data?.error
131
- };
132
- }
133
- return response.data;
134
- } catch (e) {
135
- return {
136
- success: false,
137
- error: e.message
138
- };
139
- }
140
- }
141
182
  };
142
183
  // Annotate the CommonJS export names for ESM import in node:
143
184
  0 && (module.exports = {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, FeedbackSentiment, FeedbackResponse } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n async context(\n query: string,\n options: {\n searchType: SearchType;\n maxNumResults?: number;\n queryRewrite?: boolean;\n similarityThreshold?: number;\n maxPrice?: number;\n dataSources?: string[];\n } = {\n searchType: \"all\",\n maxNumResults: 10,\n queryRewrite: true,\n similarityThreshold: 0.4,\n maxPrice: 1\n }\n ): Promise<SearchResponse> {\n try {\n const {\n searchType,\n maxNumResults = 10,\n queryRewrite = true,\n similarityThreshold = 0.4,\n maxPrice = 1,\n dataSources\n } = options;\n\n const payload: Record<string, any> = {\n query,\n search_type: searchType,\n max_num_results: maxNumResults,\n query_rewrite: queryRewrite,\n similarity_threshold: similarityThreshold,\n max_price: maxPrice\n };\n\n if (dataSources !== undefined) {\n payload.data_sources = dataSources;\n }\n\n\n const response = await axios.post(\n `${this.baseUrl}/knowledge`,\n payload,\n { headers: this.headers }\n );\n\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n\n async feedback({\n tx_id,\n feedback,\n sentiment\n }: {\n tx_id: string;\n feedback: string;\n sentiment: FeedbackSentiment;\n }): Promise<FeedbackResponse> {\n try {\n const payload = {\n tx_id,\n feedback,\n sentiment\n };\n\n const response = await axios.post(\n `${this.baseUrl}/feedback`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.message\n };\n }\n }\n}\n\nexport type { \n SearchResponse, \n SearchType, \n FeedbackSentiment, \n FeedbackResponse \n} from './types'; "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,YAAY,QAAiB,UAAkB,gCAAgC;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EAEA,MAAM,QACJ,OACA,UAOI;AAAA,IACF,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,cAAc;AAAA,IACd,qBAAqB;AAAA,IACrB,UAAU;AAAA,EACZ,GACyB;AACzB,QAAI;AACF,YAAM;AAAA,QACJ;AAAA,QACA,gBAAgB;AAAA,QAChB,eAAe;AAAA,QACf,sBAAsB;AAAA,QACtB,WAAW;AAAA,QACX;AAAA,MACF,IAAI;AAEJ,YAAM,UAA+B;AAAA,QACnC;AAAA,QACA,aAAa;AAAA,QACb,iBAAiB;AAAA,QACjB,eAAe;AAAA,QACf,sBAAsB;AAAA,QACtB,WAAW;AAAA,MACb;AAEA,UAAI,gBAAgB,QAAW;AAC7B,gBAAQ,eAAe;AAAA,MACzB;AAGA,YAAM,WAAW,MAAM,aAAAA,QAAM;AAAA,QAC3B,GAAG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["axios"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, SearchOptions } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Search for information using the Valyu API v2\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values for v2 API\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (providedSearchTypeString === \"web\" || providedSearchTypeString === \"proprietary\" || providedSearchTypeString === \"all\") {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error: \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/deepsearch`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n}\n\nexport type { \n SearchResponse, \n SearchType, \n FeedbackSentiment, \n FeedbackResponse,\n SearchOptions\n} from './types'; "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,YAAY,QAAiB,UAAkB,gCAAgC;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,mBAAmB,MAAuB;AAChD,UAAM,YAAY;AAClB,QAAI,CAAC,UAAU,KAAK,IAAI,GAAG;AACzB,aAAO;AAAA,IACT;AACA,UAAM,aAAa,IAAI,KAAK,IAAI;AAChC,WAAO,sBAAsB,QAAQ,CAAC,MAAM,WAAW,QAAQ,CAAC;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,OAAe,UAAyB,CAAC,GAA4B;AAChF,QAAI;AAEF,YAAM,oBAAgC;AACtC,YAAM,uBAAuB;AAC7B,YAAM,oBAAoB;AAC1B,YAAM,4BAA4B;AAClC,YAAM,kBAAkB;AAGxB,UAAI,kBAA8B;AAClC,YAAM,2BAA2B,QAAQ,YAAY,YAAY;AAEjE,UAAI,6BAA6B,SAAS,6BAA6B,iBAAiB,6BAA6B,OAAO;AAC1H,0BAAkB;AAAA,MACpB,WAAW,QAAQ,eAAe,QAAW;AAC3C,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO;AAAA,UACP,OAAO;AAAA,UACP;AAAA,UACA,SAAS,CAAC;AAAA,UACV,mBAAmB,EAAE,KAAK,GAAG,aAAa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AQ;AAAA,MACrC;AAEA,UAAI,QAAQ,aAAa,QAAW;AAClC,gBAAQ,WAAW,QAAQ;AAAA,MAC7B;AAEA,UAAI,QAAQ,cAAc,QAAW;AACnC,gBAAQ,aAAa,QAAQ;AAAA,MAC/B;AAEA,UAAI,QAAQ,YAAY,QAAW;AACjC,gBAAQ,WAAW,QAAQ;AAAA,MAC7B;AAEA,YAAM,WAAW,MAAM,aAAAA,QAAM;AAAA,QAC3B,GAAG,KAAK,OAAO;AAAA,QACf;AAAA,QACA,EAAE,SAAS,KAAK,QAAQ;AAAA,MAC1B;AAEA,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM;AAAA,UACtB,OAAO;AAAA,UACP;AAAA,UACA,SAAS,CAAC;AAAA,UACV,mBAAmB,EAAE,KAAK,GAAG,aAAa,EAAE;AAAA,UAC5C,qBAAqB;AAAA,UACrB,yBAAyB;AAAA,UACzB,kBAAkB;AAAA,QACpB;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,QACpC,OAAO;AAAA,QACP;AAAA,QACA,SAAS,CAAC;AAAA,QACV,mBAAmB,EAAE,KAAK,GAAG,aAAa,EAAE;AAAA,QAC5C,qBAAqB;AAAA,QACrB,yBAAyB;AAAA,QACzB,kBAAkB;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;","names":["axios"]}
package/dist/index.mjs CHANGED
@@ -14,35 +14,106 @@ var Valyu = class {
14
14
  "x-api-key": apiKey
15
15
  };
16
16
  }
17
- async context(query, options = {
18
- searchType: "all",
19
- maxNumResults: 10,
20
- queryRewrite: true,
21
- similarityThreshold: 0.4,
22
- maxPrice: 1
23
- }) {
17
+ /**
18
+ * Validates date format (YYYY-MM-DD)
19
+ */
20
+ validateDateFormat(date) {
21
+ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
22
+ if (!dateRegex.test(date)) {
23
+ return false;
24
+ }
25
+ const parsedDate = new Date(date);
26
+ return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
27
+ }
28
+ /**
29
+ * Search for information using the Valyu API v2
30
+ */
31
+ async search(query, options = {}) {
24
32
  try {
25
- const {
26
- searchType,
27
- maxNumResults = 10,
28
- queryRewrite = true,
29
- similarityThreshold = 0.4,
30
- maxPrice = 1,
31
- dataSources
32
- } = options;
33
+ const defaultSearchType = "all";
34
+ const defaultMaxNumResults = 10;
35
+ const defaultIsToolCall = true;
36
+ const defaultRelevanceThreshold = 0.5;
37
+ const defaultMaxPrice = 30;
38
+ let finalSearchType = defaultSearchType;
39
+ const providedSearchTypeString = options.searchType?.toLowerCase();
40
+ if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all") {
41
+ finalSearchType = providedSearchTypeString;
42
+ } else if (options.searchType !== void 0) {
43
+ return {
44
+ success: false,
45
+ error: "Invalid searchType provided. Must be one of: all, web, proprietary",
46
+ tx_id: null,
47
+ query,
48
+ results: [],
49
+ results_by_source: { web: 0, proprietary: 0 },
50
+ total_deduction_pcm: 0,
51
+ total_deduction_dollars: 0,
52
+ total_characters: 0
53
+ };
54
+ }
55
+ if (options.startDate && !this.validateDateFormat(options.startDate)) {
56
+ return {
57
+ success: false,
58
+ error: "Invalid startDate format. Must be YYYY-MM-DD",
59
+ tx_id: null,
60
+ query,
61
+ results: [],
62
+ results_by_source: { web: 0, proprietary: 0 },
63
+ total_deduction_pcm: 0,
64
+ total_deduction_dollars: 0,
65
+ total_characters: 0
66
+ };
67
+ }
68
+ if (options.endDate && !this.validateDateFormat(options.endDate)) {
69
+ return {
70
+ success: false,
71
+ error: "Invalid endDate format. Must be YYYY-MM-DD",
72
+ tx_id: null,
73
+ query,
74
+ results: [],
75
+ results_by_source: { web: 0, proprietary: 0 },
76
+ total_deduction_pcm: 0,
77
+ total_deduction_dollars: 0,
78
+ total_characters: 0
79
+ };
80
+ }
81
+ const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;
82
+ if (maxNumResults < 1 || maxNumResults > 20) {
83
+ return {
84
+ success: false,
85
+ error: "maxNumResults must be between 1 and 20",
86
+ tx_id: null,
87
+ query,
88
+ results: [],
89
+ results_by_source: { web: 0, proprietary: 0 },
90
+ total_deduction_pcm: 0,
91
+ total_deduction_dollars: 0,
92
+ total_characters: 0
93
+ };
94
+ }
33
95
  const payload = {
34
96
  query,
35
- search_type: searchType,
97
+ search_type: finalSearchType,
36
98
  max_num_results: maxNumResults,
37
- query_rewrite: queryRewrite,
38
- similarity_threshold: similarityThreshold,
39
- max_price: maxPrice
99
+ is_tool_call: options.isToolCall ?? defaultIsToolCall,
100
+ relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,
101
+ max_price: options.maxPrice ?? defaultMaxPrice
40
102
  };
41
- if (dataSources !== void 0) {
42
- payload.data_sources = dataSources;
103
+ if (options.includedSources !== void 0) {
104
+ payload.included_sources = options.includedSources;
105
+ }
106
+ if (options.category !== void 0) {
107
+ payload.category = options.category;
108
+ }
109
+ if (options.startDate !== void 0) {
110
+ payload.start_date = options.startDate;
111
+ }
112
+ if (options.endDate !== void 0) {
113
+ payload.end_date = options.endDate;
43
114
  }
44
115
  const response = await axios.post(
45
- `${this.baseUrl}/knowledge`,
116
+ `${this.baseUrl}/deepsearch`,
46
117
  payload,
47
118
  { headers: this.headers }
48
119
  );
@@ -63,7 +134,7 @@ var Valyu = class {
63
134
  } catch (e) {
64
135
  return {
65
136
  success: false,
66
- error: e.message,
137
+ error: e.response?.data?.error || e.message,
67
138
  tx_id: null,
68
139
  query,
69
140
  results: [],
@@ -74,36 +145,6 @@ var Valyu = class {
74
145
  };
75
146
  }
76
147
  }
77
- async feedback({
78
- tx_id,
79
- feedback,
80
- sentiment
81
- }) {
82
- try {
83
- const payload = {
84
- tx_id,
85
- feedback,
86
- sentiment
87
- };
88
- const response = await axios.post(
89
- `${this.baseUrl}/feedback`,
90
- payload,
91
- { headers: this.headers }
92
- );
93
- if (!response.status || response.status < 200 || response.status >= 300) {
94
- return {
95
- success: false,
96
- error: response.data?.error
97
- };
98
- }
99
- return response.data;
100
- } catch (e) {
101
- return {
102
- success: false,
103
- error: e.message
104
- };
105
- }
106
- }
107
148
  };
108
149
  export {
109
150
  Valyu
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, FeedbackSentiment, FeedbackResponse } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n async context(\n query: string,\n options: {\n searchType: SearchType;\n maxNumResults?: number;\n queryRewrite?: boolean;\n similarityThreshold?: number;\n maxPrice?: number;\n dataSources?: string[];\n } = {\n searchType: \"all\",\n maxNumResults: 10,\n queryRewrite: true,\n similarityThreshold: 0.4,\n maxPrice: 1\n }\n ): Promise<SearchResponse> {\n try {\n const {\n searchType,\n maxNumResults = 10,\n queryRewrite = true,\n similarityThreshold = 0.4,\n maxPrice = 1,\n dataSources\n } = options;\n\n const payload: Record<string, any> = {\n query,\n search_type: searchType,\n max_num_results: maxNumResults,\n query_rewrite: queryRewrite,\n similarity_threshold: similarityThreshold,\n max_price: maxPrice\n };\n\n if (dataSources !== undefined) {\n payload.data_sources = dataSources;\n }\n\n\n const response = await axios.post(\n `${this.baseUrl}/knowledge`,\n payload,\n { headers: this.headers }\n );\n\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n\n async feedback({\n tx_id,\n feedback,\n sentiment\n }: {\n tx_id: string;\n feedback: string;\n sentiment: FeedbackSentiment;\n }): Promise<FeedbackResponse> {\n try {\n const payload = {\n tx_id,\n feedback,\n sentiment\n };\n\n const response = await axios.post(\n `${this.baseUrl}/feedback`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.message\n };\n }\n }\n}\n\nexport type { \n SearchResponse, \n SearchType, \n FeedbackSentiment, \n FeedbackResponse \n} from './types'; "],"mappings":";AAAA,OAAO,WAAW;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,YAAY,QAAiB,UAAkB,gCAAgC;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EAEA,MAAM,QACJ,OACA,UAOI;AAAA,IACF,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,cAAc;AAAA,IACd,qBAAqB;AAAA,IACrB,UAAU;AAAA,EACZ,GACyB;AACzB,QAAI;AACF,YAAM;AAAA,QACJ;AAAA,QACA,gBAAgB;AAAA,QAChB,eAAe;AAAA,QACf,sBAAsB;AAAA,QACtB,WAAW;AAAA,QACX;AAA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AS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM;AAAA,QACxB;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE;AAAA,MACX;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, SearchOptions } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Search for information using the Valyu API v2\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values for v2 API\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (providedSearchTypeString === \"web\" || providedSearchTypeString === \"proprietary\" || providedSearchTypeString === \"all\") {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error: \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/deepsearch`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n}\n\nexport type { \n SearchResponse, \n SearchType, \n FeedbackSentiment, \n FeedbackResponse,\n SearchOptions\n} from './types'; "],"mappings":";AAAA,OAAO,WAAW;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,YAAY,QAAiB,UAAkB,gCAAgC;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,mBAAmB,MAAuB;AAChD,UAAM,YAAY;AAClB,QAAI,CAAC,UAAU,KAAK,IAAI,GAAG;AACzB,aAAO;AAAA,IACT;AACA,UAAM,aAAa,IAAI,KAAK,IAAI;AAChC,WAAO,sBAAsB,QAAQ,CAAC,MAAM,WAAW,QAAQ,CAAC;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,OAAe,UAAyB,CAAC,GAA4B;AAChF,QAAI;AAEF,YAAM,oBAAgC;AACtC,YAAM,uBAAuB;AAC7B,YAAM,oBAAoB;AAC1B,YAAM,4BAA4B;AAClC,YAAM,kBAAkB;AAGxB,UAAI,kBAA8B;AAClC,YAAM,2BAA2B,QAAQ,YAAY,YAAY;AAEjE,UAAI,6BAA6B,SAAS,6BAA6B,iBAAiB,6BAA6B,OAAO;AAC1H,0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u-js",
3
- "version": "1.0.6",
3
+ "version": "2.0.0",
4
4
  "description": "DeepSearch API for AI.",
5
5
  "files": [
6
6
  "dist"