valyu-js 2.0.0 → 2.0.2
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 +65 -31
- package/dist/index.d.mts +22 -2
- package/dist/index.d.ts +22 -2
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,9 +60,12 @@ valyu.search(
|
|
|
60
60
|
relevanceThreshold: 0.5, // Minimum relevance score (0-1)
|
|
61
61
|
maxPrice: 30, // Maximum price per thousand queries (CPM)
|
|
62
62
|
includedSources: [], // Specific sources to search
|
|
63
|
+
excludeSources: [], // Sources/domains to exclude
|
|
63
64
|
category: null, // Category filter
|
|
64
65
|
startDate: null, // Start date (YYYY-MM-DD)
|
|
65
|
-
endDate: null
|
|
66
|
+
endDate: null, // End date (YYYY-MM-DD)
|
|
67
|
+
countryCode: null, // Country code filter
|
|
68
|
+
responseLength: null // Response length control
|
|
66
69
|
}
|
|
67
70
|
)
|
|
68
71
|
```
|
|
@@ -78,9 +81,12 @@ valyu.search(
|
|
|
78
81
|
| `relevanceThreshold` | `number` | `0.5` | Minimum relevance score for results (0.0-1.0) |
|
|
79
82
|
| `maxPrice` | `number` | `30` | Maximum price per thousand queries in CPM |
|
|
80
83
|
| `includedSources` | `string[]` | `[]` | Specific data sources or URLs to search |
|
|
84
|
+
| `excludeSources` | `string[]` | `[]` | List of URLs/domains to exclude from search results |
|
|
81
85
|
| `category` | `string` | `null` | Category filter for results |
|
|
82
86
|
| `startDate` | `string` | `null` | Start date filter in YYYY-MM-DD format |
|
|
83
87
|
| `endDate` | `string` | `null` | End date filter in YYYY-MM-DD format |
|
|
88
|
+
| `countryCode` | `string` | `null` | Country code filter (e.g., "US", "GB", "JP", "ALL") |
|
|
89
|
+
| `responseLength` | `string \| number` | `null` | Response length: "short", "medium", "large", "max", or character count |
|
|
84
90
|
|
|
85
91
|
### Response Format
|
|
86
92
|
|
|
@@ -129,23 +135,24 @@ const { Valyu } = require('valyu');
|
|
|
129
135
|
|
|
130
136
|
const valyu = new Valyu("your-api-key");
|
|
131
137
|
|
|
132
|
-
// Simple search
|
|
133
|
-
const response = await valyu.search("
|
|
134
|
-
console.log(
|
|
138
|
+
// Simple search with no search parameters
|
|
139
|
+
const response = await valyu.search("what is trans-applifying mRNA");
|
|
140
|
+
console.log(response);
|
|
135
141
|
```
|
|
136
142
|
|
|
137
143
|
### Academic Research
|
|
138
144
|
|
|
139
145
|
```javascript
|
|
140
|
-
//
|
|
146
|
+
// Deep search over academic papers
|
|
141
147
|
const response = await valyu.search(
|
|
142
|
-
"agentic search-enhanced large reasoning models",
|
|
148
|
+
"implementation details of agentic search-enhanced large reasoning models",
|
|
143
149
|
{
|
|
144
150
|
searchType: "proprietary",
|
|
145
151
|
maxNumResults: 10,
|
|
146
152
|
relevanceThreshold: 0.6,
|
|
147
153
|
includedSources: ["valyu/valyu-arxiv"],
|
|
148
|
-
|
|
154
|
+
category: "agentic RAG",
|
|
155
|
+
startDate: "2024-12-01"
|
|
149
156
|
}
|
|
150
157
|
);
|
|
151
158
|
```
|
|
@@ -153,31 +160,63 @@ const response = await valyu.search(
|
|
|
153
160
|
### Web Search with Date Filtering
|
|
154
161
|
|
|
155
162
|
```javascript
|
|
156
|
-
//
|
|
163
|
+
// Web search with date range
|
|
157
164
|
const response = await valyu.search(
|
|
158
|
-
"what
|
|
165
|
+
"what are the grok 4 benchmark results",
|
|
159
166
|
{
|
|
160
167
|
searchType: "web",
|
|
161
168
|
maxNumResults: 7,
|
|
162
169
|
relevanceThreshold: 0.5,
|
|
163
|
-
startDate: "
|
|
164
|
-
endDate: "
|
|
170
|
+
startDate: "2025-06-01",
|
|
171
|
+
endDate: "2025-07-25"
|
|
165
172
|
}
|
|
166
173
|
);
|
|
167
174
|
```
|
|
168
175
|
|
|
169
|
-
###
|
|
176
|
+
### Country-Specific Search
|
|
170
177
|
|
|
171
178
|
```javascript
|
|
172
|
-
//
|
|
179
|
+
// Web search with country filtering
|
|
173
180
|
const response = await valyu.search(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
"what is the weather where i am?",
|
|
182
|
+
{
|
|
183
|
+
searchType: "web",
|
|
184
|
+
maxNumResults: 2,
|
|
185
|
+
countryCode: "UK",
|
|
186
|
+
responseLength: "short"
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Search with Source Exclusion
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
// Hybrid search excluding specific sources
|
|
195
|
+
const response = await valyu.search(
|
|
196
|
+
"quantum computing applications in cryptography",
|
|
197
|
+
{
|
|
198
|
+
searchType: "all",
|
|
199
|
+
maxNumResults: 8,
|
|
200
|
+
relevanceThreshold: 0.5,
|
|
201
|
+
maxPrice: 40,
|
|
202
|
+
excludeSources: ["paperswithcode.com", "wikipedia.org"],
|
|
203
|
+
responseLength: "large",
|
|
204
|
+
isToolCall: true
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Custom Response Length
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
// Search with custom character count
|
|
213
|
+
const response = await valyu.search(
|
|
214
|
+
"State of video generation AI models",
|
|
215
|
+
{
|
|
216
|
+
maxNumResults: 10,
|
|
217
|
+
category: "vLLMs",
|
|
218
|
+
responseLength: 1000 // Limit to 1000 characters per result
|
|
219
|
+
}
|
|
181
220
|
);
|
|
182
221
|
```
|
|
183
222
|
|
|
@@ -215,14 +254,6 @@ Set your API key in one of these ways:
|
|
|
215
254
|
const valyu = new Valyu("your-api-key-here");
|
|
216
255
|
```
|
|
217
256
|
|
|
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
257
|
## Error Handling
|
|
227
258
|
|
|
228
259
|
The SDK handles errors gracefully and returns structured error responses:
|
|
@@ -243,17 +274,20 @@ if (!response.success) {
|
|
|
243
274
|
|
|
244
275
|
## TypeScript Support
|
|
245
276
|
|
|
246
|
-
The SDK includes full TypeScript support:
|
|
277
|
+
The SDK includes full TypeScript support with type definitions for all parameters:
|
|
247
278
|
|
|
248
279
|
```typescript
|
|
249
|
-
import { Valyu, SearchOptions, SearchResponse } from 'valyu';
|
|
280
|
+
import { Valyu, SearchOptions, SearchResponse, CountryCode, ResponseLength } from 'valyu';
|
|
250
281
|
|
|
251
282
|
const valyu = new Valyu("your-api-key");
|
|
252
283
|
|
|
253
284
|
const options: SearchOptions = {
|
|
254
285
|
searchType: "proprietary",
|
|
255
286
|
maxNumResults: 10,
|
|
256
|
-
relevanceThreshold: 0.6
|
|
287
|
+
relevanceThreshold: 0.6,
|
|
288
|
+
excludeSources: ["reddit.com", "twitter.com"],
|
|
289
|
+
countryCode: "US" as CountryCode,
|
|
290
|
+
responseLength: "medium" as ResponseLength
|
|
257
291
|
};
|
|
258
292
|
|
|
259
293
|
const response: SearchResponse = await valyu.search("machine learning", options);
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
type SearchType = "web" | "proprietary" | "all";
|
|
2
2
|
type FeedbackSentiment = "very good" | "good" | "bad" | "very bad";
|
|
3
3
|
type DataType = "structured" | "unstructured";
|
|
4
|
+
type CountryCode = "ALL" | "AR" | "AU" | "AT" | "BE" | "BR" | "CA" | "CL" | "DK" | "FI" | "FR" | "DE" | "HK" | "IN" | "ID" | "IT" | "JP" | "KR" | "MY" | "MX" | "NL" | "NZ" | "NO" | "CN" | "PL" | "PT" | "PH" | "RU" | "SA" | "ZA" | "ES" | "SE" | "CH" | "TW" | "TR" | "GB" | "US";
|
|
5
|
+
type ResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
4
6
|
interface SearchResult {
|
|
5
7
|
title: string;
|
|
6
8
|
url: string;
|
|
@@ -19,9 +21,12 @@ interface SearchOptions {
|
|
|
19
21
|
isToolCall?: boolean;
|
|
20
22
|
relevanceThreshold?: number;
|
|
21
23
|
includedSources?: string[];
|
|
24
|
+
excludeSources?: string[];
|
|
22
25
|
category?: string;
|
|
23
26
|
startDate?: string;
|
|
24
27
|
endDate?: string;
|
|
28
|
+
countryCode?: CountryCode;
|
|
29
|
+
responseLength?: ResponseLength;
|
|
25
30
|
}
|
|
26
31
|
interface SearchResponse {
|
|
27
32
|
success: boolean;
|
|
@@ -51,9 +56,24 @@ declare class Valyu {
|
|
|
51
56
|
*/
|
|
52
57
|
private validateDateFormat;
|
|
53
58
|
/**
|
|
54
|
-
* Search for information using the Valyu API
|
|
59
|
+
* Search for information using the Valyu DeepSearch API
|
|
60
|
+
* @param query - The search query string
|
|
61
|
+
* @param options - Search configuration options
|
|
62
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
63
|
+
* @param options.maxNumResults - Maximum number of results (1-20)
|
|
64
|
+
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
65
|
+
* @param options.isToolCall - Whether this is a tool call
|
|
66
|
+
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
67
|
+
* @param options.includedSources - List of specific sources to include
|
|
68
|
+
* @param options.excludeSources - List of URLs/domains to exclude from search results
|
|
69
|
+
* @param options.category - Category filter for search results
|
|
70
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
71
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
72
|
+
* @param options.countryCode - Country code filter for search results
|
|
73
|
+
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
74
|
+
* @returns Promise resolving to search results
|
|
55
75
|
*/
|
|
56
76
|
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
57
77
|
}
|
|
58
78
|
|
|
59
|
-
export { type FeedbackResponse, type FeedbackSentiment, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
|
79
|
+
export { type CountryCode, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
type SearchType = "web" | "proprietary" | "all";
|
|
2
2
|
type FeedbackSentiment = "very good" | "good" | "bad" | "very bad";
|
|
3
3
|
type DataType = "structured" | "unstructured";
|
|
4
|
+
type CountryCode = "ALL" | "AR" | "AU" | "AT" | "BE" | "BR" | "CA" | "CL" | "DK" | "FI" | "FR" | "DE" | "HK" | "IN" | "ID" | "IT" | "JP" | "KR" | "MY" | "MX" | "NL" | "NZ" | "NO" | "CN" | "PL" | "PT" | "PH" | "RU" | "SA" | "ZA" | "ES" | "SE" | "CH" | "TW" | "TR" | "GB" | "US";
|
|
5
|
+
type ResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
4
6
|
interface SearchResult {
|
|
5
7
|
title: string;
|
|
6
8
|
url: string;
|
|
@@ -19,9 +21,12 @@ interface SearchOptions {
|
|
|
19
21
|
isToolCall?: boolean;
|
|
20
22
|
relevanceThreshold?: number;
|
|
21
23
|
includedSources?: string[];
|
|
24
|
+
excludeSources?: string[];
|
|
22
25
|
category?: string;
|
|
23
26
|
startDate?: string;
|
|
24
27
|
endDate?: string;
|
|
28
|
+
countryCode?: CountryCode;
|
|
29
|
+
responseLength?: ResponseLength;
|
|
25
30
|
}
|
|
26
31
|
interface SearchResponse {
|
|
27
32
|
success: boolean;
|
|
@@ -51,9 +56,24 @@ declare class Valyu {
|
|
|
51
56
|
*/
|
|
52
57
|
private validateDateFormat;
|
|
53
58
|
/**
|
|
54
|
-
* Search for information using the Valyu API
|
|
59
|
+
* Search for information using the Valyu DeepSearch API
|
|
60
|
+
* @param query - The search query string
|
|
61
|
+
* @param options - Search configuration options
|
|
62
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
63
|
+
* @param options.maxNumResults - Maximum number of results (1-20)
|
|
64
|
+
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
65
|
+
* @param options.isToolCall - Whether this is a tool call
|
|
66
|
+
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
67
|
+
* @param options.includedSources - List of specific sources to include
|
|
68
|
+
* @param options.excludeSources - List of URLs/domains to exclude from search results
|
|
69
|
+
* @param options.category - Category filter for search results
|
|
70
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
71
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
72
|
+
* @param options.countryCode - Country code filter for search results
|
|
73
|
+
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
74
|
+
* @returns Promise resolving to search results
|
|
55
75
|
*/
|
|
56
76
|
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
57
77
|
}
|
|
58
78
|
|
|
59
|
-
export { type FeedbackResponse, type FeedbackSentiment, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
|
79
|
+
export { type CountryCode, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
package/dist/index.js
CHANGED
|
@@ -60,7 +60,22 @@ var Valyu = class {
|
|
|
60
60
|
return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Search for information using the Valyu API
|
|
63
|
+
* Search for information using the Valyu DeepSearch API
|
|
64
|
+
* @param query - The search query string
|
|
65
|
+
* @param options - Search configuration options
|
|
66
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
67
|
+
* @param options.maxNumResults - Maximum number of results (1-20)
|
|
68
|
+
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
69
|
+
* @param options.isToolCall - Whether this is a tool call
|
|
70
|
+
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
71
|
+
* @param options.includedSources - List of specific sources to include
|
|
72
|
+
* @param options.excludeSources - List of URLs/domains to exclude from search results
|
|
73
|
+
* @param options.category - Category filter for search results
|
|
74
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
75
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
76
|
+
* @param options.countryCode - Country code filter for search results
|
|
77
|
+
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
78
|
+
* @returns Promise resolving to search results
|
|
64
79
|
*/
|
|
65
80
|
async search(query, options = {}) {
|
|
66
81
|
try {
|
|
@@ -137,6 +152,9 @@ var Valyu = class {
|
|
|
137
152
|
if (options.includedSources !== void 0) {
|
|
138
153
|
payload.included_sources = options.includedSources;
|
|
139
154
|
}
|
|
155
|
+
if (options.excludeSources !== void 0) {
|
|
156
|
+
payload.exclude_sources = options.excludeSources;
|
|
157
|
+
}
|
|
140
158
|
if (options.category !== void 0) {
|
|
141
159
|
payload.category = options.category;
|
|
142
160
|
}
|
|
@@ -146,6 +164,12 @@ var Valyu = class {
|
|
|
146
164
|
if (options.endDate !== void 0) {
|
|
147
165
|
payload.end_date = options.endDate;
|
|
148
166
|
}
|
|
167
|
+
if (options.countryCode !== void 0) {
|
|
168
|
+
payload.country_code = options.countryCode;
|
|
169
|
+
}
|
|
170
|
+
if (options.responseLength !== void 0) {
|
|
171
|
+
payload.response_length = options.responseLength;
|
|
172
|
+
}
|
|
149
173
|
const response = await import_axios.default.post(
|
|
150
174
|
`${this.baseUrl}/deepsearch`,
|
|
151
175
|
payload,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;A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Q,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"]}
|
|
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 DeepSearch API\n * @param query - The search query string\n * @param options - Search configuration options\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.maxNumResults - Maximum number of results (1-20)\n * @param options.maxPrice - Maximum price per thousand characters (CPM)\n * @param options.isToolCall - Whether this is a tool call\n * @param options.relevanceThreshold - Minimum relevance score (0-1)\n * @param options.includedSources - List of specific sources to include\n * @param options.excludeSources - List of URLs/domains to exclude from search results\n * @param options.category - Category filter for search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.countryCode - Country code filter for search results\n * @param options.responseLength - Response content length: \"short\"/\"medium\"/\"large\"/\"max\" or integer character count\n * @returns Promise resolving to search results\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values\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.excludeSources !== undefined) {\n payload.exclude_sources = options.excludeSources;\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 if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\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 CountryCode,\n ResponseLength\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,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;A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ACf,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
|
@@ -26,7 +26,22 @@ var Valyu = class {
|
|
|
26
26
|
return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Search for information using the Valyu API
|
|
29
|
+
* Search for information using the Valyu DeepSearch API
|
|
30
|
+
* @param query - The search query string
|
|
31
|
+
* @param options - Search configuration options
|
|
32
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
33
|
+
* @param options.maxNumResults - Maximum number of results (1-20)
|
|
34
|
+
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
35
|
+
* @param options.isToolCall - Whether this is a tool call
|
|
36
|
+
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
37
|
+
* @param options.includedSources - List of specific sources to include
|
|
38
|
+
* @param options.excludeSources - List of URLs/domains to exclude from search results
|
|
39
|
+
* @param options.category - Category filter for search results
|
|
40
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
41
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
42
|
+
* @param options.countryCode - Country code filter for search results
|
|
43
|
+
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
44
|
+
* @returns Promise resolving to search results
|
|
30
45
|
*/
|
|
31
46
|
async search(query, options = {}) {
|
|
32
47
|
try {
|
|
@@ -103,6 +118,9 @@ var Valyu = class {
|
|
|
103
118
|
if (options.includedSources !== void 0) {
|
|
104
119
|
payload.included_sources = options.includedSources;
|
|
105
120
|
}
|
|
121
|
+
if (options.excludeSources !== void 0) {
|
|
122
|
+
payload.exclude_sources = options.excludeSources;
|
|
123
|
+
}
|
|
106
124
|
if (options.category !== void 0) {
|
|
107
125
|
payload.category = options.category;
|
|
108
126
|
}
|
|
@@ -112,6 +130,12 @@ var Valyu = class {
|
|
|
112
130
|
if (options.endDate !== void 0) {
|
|
113
131
|
payload.end_date = options.endDate;
|
|
114
132
|
}
|
|
133
|
+
if (options.countryCode !== void 0) {
|
|
134
|
+
payload.country_code = options.countryCode;
|
|
135
|
+
}
|
|
136
|
+
if (options.responseLength !== void 0) {
|
|
137
|
+
payload.response_length = options.responseLength;
|
|
138
|
+
}
|
|
115
139
|
const response = await axios.post(
|
|
116
140
|
`${this.baseUrl}/deepsearch`,
|
|
117
141
|
payload,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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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O,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":[]}
|
|
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 DeepSearch API\n * @param query - The search query string\n * @param options - Search configuration options\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.maxNumResults - Maximum number of results (1-20)\n * @param options.maxPrice - Maximum price per thousand characters (CPM)\n * @param options.isToolCall - Whether this is a tool call\n * @param options.relevanceThreshold - Minimum relevance score (0-1)\n * @param options.includedSources - List of specific sources to include\n * @param options.excludeSources - List of URLs/domains to exclude from search results\n * @param options.category - Category filter for search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.countryCode - Country code filter for search results\n * @param options.responseLength - Response content length: \"short\"/\"medium\"/\"large\"/\"max\" or integer character count\n * @returns Promise resolving to search results\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values\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.excludeSources !== undefined) {\n payload.exclude_sources = options.excludeSources;\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 if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\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 CountryCode,\n ResponseLength\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,MAC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