valyu-js 2.1.3 → 2.1.7
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 +10 -5
- package/dist/index.d.mts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +21 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,9 +124,12 @@ Each `SearchResult` contains:
|
|
|
124
124
|
source: string, // Source identifier
|
|
125
125
|
price: number, // Cost for this result
|
|
126
126
|
length: number, // Content length in characters
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
relevance_score?: number, // Relevance score (0-1), not available in fast_mode or url_only
|
|
128
|
+
data_type?: string, // "structured" or "unstructured"
|
|
129
|
+
source_type?: string, // Source type identifier
|
|
130
|
+
publication_date?: string, // Publication date (YYYY-MM-DD)
|
|
131
|
+
id?: string, // Unique result identifier
|
|
132
|
+
image_url?: Record<string, string> // Associated images
|
|
130
133
|
}
|
|
131
134
|
```
|
|
132
135
|
|
|
@@ -258,11 +261,13 @@ const response = await valyu.search("climate change solutions");
|
|
|
258
261
|
if (response.success) {
|
|
259
262
|
console.log(`Search cost: $${response.total_deduction_dollars.toFixed(4)}`);
|
|
260
263
|
console.log(`Sources: Web=${response.results_by_source.web}, Proprietary=${response.results_by_source.proprietary}`);
|
|
261
|
-
|
|
264
|
+
|
|
262
265
|
response.results.forEach((result, i) => {
|
|
263
266
|
console.log(`\n${i + 1}. ${result.title}`);
|
|
264
267
|
console.log(` Source: ${result.source}`);
|
|
265
|
-
|
|
268
|
+
if (result.relevance_score !== undefined) {
|
|
269
|
+
console.log(` Relevance: ${result.relevance_score.toFixed(2)}`);
|
|
270
|
+
}
|
|
266
271
|
console.log(` Content: ${result.content.substring(0, 200)}...`);
|
|
267
272
|
});
|
|
268
273
|
} else {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type SearchType = "web" | "proprietary" | "all";
|
|
1
|
+
type SearchType = "web" | "proprietary" | "all" | "news";
|
|
2
2
|
type FeedbackSentiment = "very good" | "good" | "bad" | "very bad";
|
|
3
3
|
type DataType = "structured" | "unstructured";
|
|
4
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";
|
|
@@ -11,8 +11,12 @@ interface SearchResult {
|
|
|
11
11
|
source: string;
|
|
12
12
|
price: number;
|
|
13
13
|
length: number;
|
|
14
|
-
relevance_score
|
|
14
|
+
relevance_score?: number;
|
|
15
15
|
data_type?: DataType;
|
|
16
|
+
source_type?: string;
|
|
17
|
+
publication_date?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
image_url?: Record<string, string>;
|
|
16
20
|
}
|
|
17
21
|
interface SearchOptions {
|
|
18
22
|
searchType?: SearchType;
|
|
@@ -28,6 +32,7 @@ interface SearchOptions {
|
|
|
28
32
|
countryCode?: CountryCode;
|
|
29
33
|
responseLength?: ResponseLength;
|
|
30
34
|
fastMode?: boolean;
|
|
35
|
+
urlOnly?: boolean;
|
|
31
36
|
}
|
|
32
37
|
interface SearchResponse {
|
|
33
38
|
success: boolean;
|
|
@@ -154,8 +159,8 @@ declare class Valyu {
|
|
|
154
159
|
* Search for information using the Valyu DeepSearch API
|
|
155
160
|
* @param query - The search query string
|
|
156
161
|
* @param options - Search configuration options
|
|
157
|
-
* @param options.searchType - Type of search: "web", "proprietary", or "
|
|
158
|
-
* @param options.maxNumResults - Maximum number of results (1-
|
|
162
|
+
* @param options.searchType - Type of search: "web", "proprietary", "all", or "news"
|
|
163
|
+
* @param options.maxNumResults - Maximum number of results (1-100)
|
|
159
164
|
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
160
165
|
* @param options.isToolCall - Whether this is a tool call
|
|
161
166
|
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
@@ -167,6 +172,7 @@ declare class Valyu {
|
|
|
167
172
|
* @param options.countryCode - Country code filter for search results
|
|
168
173
|
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
169
174
|
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
175
|
+
* @param options.urlOnly - Returns shortened snippets (default: false)
|
|
170
176
|
* @returns Promise resolving to search results
|
|
171
177
|
*/
|
|
172
178
|
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
@@ -187,7 +193,7 @@ declare class Valyu {
|
|
|
187
193
|
* @param options - Answer configuration options
|
|
188
194
|
* @param options.structuredOutput - JSON Schema object for structured responses
|
|
189
195
|
* @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
|
|
190
|
-
* @param options.searchType - Type of search: "web", "proprietary", or "
|
|
196
|
+
* @param options.searchType - Type of search: "web", "proprietary", "all", or "news"
|
|
191
197
|
* @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
|
|
192
198
|
* @param options.countryCode - Country code filter for search results
|
|
193
199
|
* @param options.includedSources - List of specific sources to include
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type SearchType = "web" | "proprietary" | "all";
|
|
1
|
+
type SearchType = "web" | "proprietary" | "all" | "news";
|
|
2
2
|
type FeedbackSentiment = "very good" | "good" | "bad" | "very bad";
|
|
3
3
|
type DataType = "structured" | "unstructured";
|
|
4
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";
|
|
@@ -11,8 +11,12 @@ interface SearchResult {
|
|
|
11
11
|
source: string;
|
|
12
12
|
price: number;
|
|
13
13
|
length: number;
|
|
14
|
-
relevance_score
|
|
14
|
+
relevance_score?: number;
|
|
15
15
|
data_type?: DataType;
|
|
16
|
+
source_type?: string;
|
|
17
|
+
publication_date?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
image_url?: Record<string, string>;
|
|
16
20
|
}
|
|
17
21
|
interface SearchOptions {
|
|
18
22
|
searchType?: SearchType;
|
|
@@ -28,6 +32,7 @@ interface SearchOptions {
|
|
|
28
32
|
countryCode?: CountryCode;
|
|
29
33
|
responseLength?: ResponseLength;
|
|
30
34
|
fastMode?: boolean;
|
|
35
|
+
urlOnly?: boolean;
|
|
31
36
|
}
|
|
32
37
|
interface SearchResponse {
|
|
33
38
|
success: boolean;
|
|
@@ -154,8 +159,8 @@ declare class Valyu {
|
|
|
154
159
|
* Search for information using the Valyu DeepSearch API
|
|
155
160
|
* @param query - The search query string
|
|
156
161
|
* @param options - Search configuration options
|
|
157
|
-
* @param options.searchType - Type of search: "web", "proprietary", or "
|
|
158
|
-
* @param options.maxNumResults - Maximum number of results (1-
|
|
162
|
+
* @param options.searchType - Type of search: "web", "proprietary", "all", or "news"
|
|
163
|
+
* @param options.maxNumResults - Maximum number of results (1-100)
|
|
159
164
|
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
160
165
|
* @param options.isToolCall - Whether this is a tool call
|
|
161
166
|
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
@@ -167,6 +172,7 @@ declare class Valyu {
|
|
|
167
172
|
* @param options.countryCode - Country code filter for search results
|
|
168
173
|
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
169
174
|
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
175
|
+
* @param options.urlOnly - Returns shortened snippets (default: false)
|
|
170
176
|
* @returns Promise resolving to search results
|
|
171
177
|
*/
|
|
172
178
|
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
@@ -187,7 +193,7 @@ declare class Valyu {
|
|
|
187
193
|
* @param options - Answer configuration options
|
|
188
194
|
* @param options.structuredOutput - JSON Schema object for structured responses
|
|
189
195
|
* @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
|
|
190
|
-
* @param options.searchType - Type of search: "web", "proprietary", or "
|
|
196
|
+
* @param options.searchType - Type of search: "web", "proprietary", "all", or "news"
|
|
191
197
|
* @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
|
|
192
198
|
* @param options.countryCode - Country code filter for search results
|
|
193
199
|
* @param options.includedSources - List of specific sources to include
|
package/dist/index.js
CHANGED
|
@@ -121,8 +121,8 @@ var Valyu = class {
|
|
|
121
121
|
* Search for information using the Valyu DeepSearch API
|
|
122
122
|
* @param query - The search query string
|
|
123
123
|
* @param options - Search configuration options
|
|
124
|
-
* @param options.searchType - Type of search: "web", "proprietary", or "
|
|
125
|
-
* @param options.maxNumResults - Maximum number of results (1-
|
|
124
|
+
* @param options.searchType - Type of search: "web", "proprietary", "all", or "news"
|
|
125
|
+
* @param options.maxNumResults - Maximum number of results (1-100)
|
|
126
126
|
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
127
127
|
* @param options.isToolCall - Whether this is a tool call
|
|
128
128
|
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
@@ -134,6 +134,7 @@ var Valyu = class {
|
|
|
134
134
|
* @param options.countryCode - Country code filter for search results
|
|
135
135
|
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
136
136
|
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
137
|
+
* @param options.urlOnly - Returns shortened snippets (default: false)
|
|
137
138
|
* @returns Promise resolving to search results
|
|
138
139
|
*/
|
|
139
140
|
async search(query, options = {}) {
|
|
@@ -142,15 +143,14 @@ var Valyu = class {
|
|
|
142
143
|
const defaultMaxNumResults = 10;
|
|
143
144
|
const defaultIsToolCall = true;
|
|
144
145
|
const defaultRelevanceThreshold = 0.5;
|
|
145
|
-
const defaultMaxPrice = 30;
|
|
146
146
|
let finalSearchType = defaultSearchType;
|
|
147
147
|
const providedSearchTypeString = options.searchType?.toLowerCase();
|
|
148
|
-
if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all") {
|
|
148
|
+
if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all" || providedSearchTypeString === "news") {
|
|
149
149
|
finalSearchType = providedSearchTypeString;
|
|
150
150
|
} else if (options.searchType !== void 0) {
|
|
151
151
|
return {
|
|
152
152
|
success: false,
|
|
153
|
-
error: "Invalid searchType provided. Must be one of: all, web, proprietary",
|
|
153
|
+
error: "Invalid searchType provided. Must be one of: all, web, proprietary, news",
|
|
154
154
|
tx_id: null,
|
|
155
155
|
query,
|
|
156
156
|
results: [],
|
|
@@ -187,10 +187,10 @@ var Valyu = class {
|
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;
|
|
190
|
-
if (maxNumResults < 1 || maxNumResults >
|
|
190
|
+
if (maxNumResults < 1 || maxNumResults > 100) {
|
|
191
191
|
return {
|
|
192
192
|
success: false,
|
|
193
|
-
error: "maxNumResults must be between 1 and
|
|
193
|
+
error: "maxNumResults must be between 1 and 100",
|
|
194
194
|
tx_id: null,
|
|
195
195
|
query,
|
|
196
196
|
results: [],
|
|
@@ -271,9 +271,11 @@ var Valyu = class {
|
|
|
271
271
|
search_type: finalSearchType,
|
|
272
272
|
max_num_results: maxNumResults,
|
|
273
273
|
is_tool_call: options.isToolCall ?? defaultIsToolCall,
|
|
274
|
-
relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold
|
|
275
|
-
max_price: options.maxPrice ?? defaultMaxPrice
|
|
274
|
+
relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold
|
|
276
275
|
};
|
|
276
|
+
if (options.maxPrice !== void 0) {
|
|
277
|
+
payload.max_price = options.maxPrice;
|
|
278
|
+
}
|
|
277
279
|
if (options.includedSources !== void 0) {
|
|
278
280
|
payload.included_sources = options.includedSources;
|
|
279
281
|
}
|
|
@@ -298,6 +300,9 @@ var Valyu = class {
|
|
|
298
300
|
if (options.fastMode !== void 0) {
|
|
299
301
|
payload.fast_mode = options.fastMode;
|
|
300
302
|
}
|
|
303
|
+
if (options.urlOnly !== void 0) {
|
|
304
|
+
payload.url_only = options.urlOnly;
|
|
305
|
+
}
|
|
301
306
|
const response = await import_axios.default.post(`${this.baseUrl}/deepsearch`, payload, {
|
|
302
307
|
headers: this.headers
|
|
303
308
|
});
|
|
@@ -466,7 +471,7 @@ var Valyu = class {
|
|
|
466
471
|
* @param options - Answer configuration options
|
|
467
472
|
* @param options.structuredOutput - JSON Schema object for structured responses
|
|
468
473
|
* @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
|
|
469
|
-
* @param options.searchType - Type of search: "web", "proprietary", or "
|
|
474
|
+
* @param options.searchType - Type of search: "web", "proprietary", "all", or "news"
|
|
470
475
|
* @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
|
|
471
476
|
* @param options.countryCode - Country code filter for search results
|
|
472
477
|
* @param options.includedSources - List of specific sources to include
|
|
@@ -479,7 +484,6 @@ var Valyu = class {
|
|
|
479
484
|
async answer(query, options = {}) {
|
|
480
485
|
try {
|
|
481
486
|
const defaultSearchType = "all";
|
|
482
|
-
const defaultDataMaxPrice = 30;
|
|
483
487
|
if (!query || typeof query !== "string" || query.trim().length === 0) {
|
|
484
488
|
return {
|
|
485
489
|
success: false,
|
|
@@ -488,12 +492,12 @@ var Valyu = class {
|
|
|
488
492
|
}
|
|
489
493
|
let finalSearchType = defaultSearchType;
|
|
490
494
|
const providedSearchTypeString = options.searchType?.toLowerCase();
|
|
491
|
-
if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all") {
|
|
495
|
+
if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all" || providedSearchTypeString === "news") {
|
|
492
496
|
finalSearchType = providedSearchTypeString;
|
|
493
497
|
} else if (options.searchType !== void 0) {
|
|
494
498
|
return {
|
|
495
499
|
success: false,
|
|
496
|
-
error: "Invalid searchType provided. Must be one of: all, web, proprietary"
|
|
500
|
+
error: "Invalid searchType provided. Must be one of: all, web, proprietary, news"
|
|
497
501
|
};
|
|
498
502
|
}
|
|
499
503
|
if (options.systemInstructions !== void 0) {
|
|
@@ -587,9 +591,11 @@ var Valyu = class {
|
|
|
587
591
|
}
|
|
588
592
|
const payload = {
|
|
589
593
|
query: query.trim(),
|
|
590
|
-
search_type: finalSearchType
|
|
591
|
-
data_max_price: options.dataMaxPrice ?? defaultDataMaxPrice
|
|
594
|
+
search_type: finalSearchType
|
|
592
595
|
};
|
|
596
|
+
if (options.dataMaxPrice !== void 0) {
|
|
597
|
+
payload.data_max_price = options.dataMaxPrice;
|
|
598
|
+
}
|
|
593
599
|
if (options.structuredOutput !== void 0) {
|
|
594
600
|
payload.structured_output = options.structuredOutput;
|
|
595
601
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n SearchResponse,\n SearchType,\n SearchOptions,\n ContentsOptions,\n ContentsResponse,\n AnswerOptions,\n AnswerResponse,\n} from \"./types\";\n\n\n// Valyu API client\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(\n apiKey?: string,\n baseUrl: string = \"https://api.valyu.ai/v1\"\n ) {\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 * Validates if a string is a valid URL\n */\n private validateUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Validates if a string is a valid domain (with optional path)\n */\n private validateDomain(domain: string): boolean {\n // Domain must have at least one dot and valid structure\n // Supports: example.com, example.com/path, subdomain.example.com/path/to/resource\n const domainRegex =\n /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\/.+)?$/;\n return domainRegex.test(domain);\n }\n\n /**\n * Validates if a string is a valid dataset identifier (provider/datasetname)\n */\n private validateDatasetId(datasetId: string): boolean {\n // Dataset format: provider/datasetname (exactly one slash)\n // Provider and dataset name can contain alphanumeric, hyphens, underscores\n const parts = datasetId.split(\"/\");\n if (parts.length !== 2) return false;\n\n const providerRegex = /^[a-zA-Z0-9_-]+$/;\n const datasetRegex = /^[a-zA-Z0-9_-]+$/;\n\n return (\n providerRegex.test(parts[0]) &&\n datasetRegex.test(parts[1]) &&\n parts[0].length > 0 &&\n parts[1].length > 0\n );\n }\n\n /**\n * Validates source strings (domains, URLs, or dataset IDs)\n */\n private validateSource(source: string): boolean {\n // Check if it's a valid URL\n if (this.validateUrl(source)) {\n return true;\n }\n\n // Check if it's a valid domain (with optional path)\n if (this.validateDomain(source)) {\n return true;\n }\n\n // Check if it's a valid dataset identifier\n if (this.validateDatasetId(source)) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Validates an array of source strings\n */\n private validateSources(sources: string[]): {\n valid: boolean;\n invalidSources: string[];\n } {\n const invalidSources: string[] = [];\n\n for (const source of sources) {\n if (!this.validateSource(source)) {\n invalidSources.push(source);\n }\n }\n\n return {\n valid: invalidSources.length === 0,\n invalidSources,\n };\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 * @param options.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to search results\n */\n async search(\n query: string,\n options: SearchOptions = {}\n ): 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 (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"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 // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\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 const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\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 // Validate excludeSources format\n if (options.excludeSources !== undefined) {\n if (!Array.isArray(options.excludeSources)) {\n return {\n success: false,\n error: \"excludeSources must be an array\",\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 const excludeSourcesValidation = this.validateSources(\n options.excludeSources\n );\n if (!excludeSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludeSources format. Invalid sources: ${excludeSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\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 // 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:\n 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 if (options.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/deepsearch`, 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 /**\n * Extract content from URLs with optional AI processing\n * @param urls - Array of URLs to process (max 10)\n * @param options - Content extraction configuration options\n * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema\n * @param options.extractEffort - Extraction thoroughness: \"normal\" or \"high\"\n * @param options.responseLength - Content length per URL\n * @param options.maxPriceDollars - Maximum cost limit in USD\n * @returns Promise resolving to content extraction results\n */\n async contents(\n urls: string[],\n options: ContentsOptions = {}\n ): Promise<ContentsResponse> {\n try {\n // Validate URLs array\n if (!urls || !Array.isArray(urls)) {\n return {\n success: false,\n error: \"urls must be an array\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length === 0) {\n return {\n success: false,\n error: \"urls array cannot be empty\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length > 10) {\n return {\n success: false,\n error: \"Maximum 10 URLs allowed per request\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate extractEffort if provided\n if (\n options.extractEffort &&\n ![\"normal\", \"high\", \"auto\"].includes(options.extractEffort)\n ) {\n return {\n success: false,\n error: \"extractEffort must be 'normal', 'high', or 'auto'\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate responseLength if provided\n if (options.responseLength !== undefined) {\n const validLengths = [\"short\", \"medium\", \"large\", \"max\"];\n if (\n typeof options.responseLength === \"string\" &&\n !validLengths.includes(options.responseLength)\n ) {\n return {\n success: false,\n error:\n \"responseLength must be 'short', 'medium', 'large', 'max', or a number\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n if (\n typeof options.responseLength === \"number\" &&\n options.responseLength <= 0\n ) {\n return {\n success: false,\n error: \"responseLength number must be positive\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n urls,\n };\n\n // Add optional parameters only if provided\n if (options.summary !== undefined) {\n payload.summary = options.summary;\n }\n\n if (options.extractEffort !== undefined) {\n payload.extract_effort = options.extractEffort;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.maxPriceDollars !== undefined) {\n payload.max_price_dollars = options.maxPriceDollars;\n }\n\n const response = await axios.post(`${this.baseUrl}/contents`, 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 || \"Request failed\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 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 urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n /**\n * Get AI-powered answers using the Valyu Answer API\n * @param query - The question or query string\n * @param options - Answer configuration options\n * @param options.structuredOutput - JSON Schema object for structured responses\n * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval\n * @param options.countryCode - Country code filter for search results\n * @param options.includedSources - List of specific sources to include\n * @param options.excludedSources - List of URLs/domains to exclude from 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.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to answer response\n */\n async answer(\n query: string,\n options: AnswerOptions = {}\n ): Promise<AnswerResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultDataMaxPrice = 30.0;\n\n // Validate query\n if (!query || typeof query !== \"string\" || query.trim().length === 0) {\n return {\n success: false,\n error: \"Query is required and must be a non-empty string\",\n };\n }\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n };\n }\n\n // Validate systemInstructions length\n if (options.systemInstructions !== undefined) {\n if (typeof options.systemInstructions !== \"string\") {\n return {\n success: false,\n error: \"systemInstructions must be a string\",\n };\n }\n\n const trimmed = options.systemInstructions.trim();\n if (trimmed.length === 0) {\n return {\n success: false,\n error: \"systemInstructions cannot be empty when provided\",\n };\n }\n\n if (trimmed.length > 2000) {\n return {\n success: false,\n error: \"systemInstructions must be 2000 characters or less\",\n };\n }\n }\n\n // Validate dataMaxPrice\n if (options.dataMaxPrice !== undefined) {\n if (\n typeof options.dataMaxPrice !== \"number\" ||\n options.dataMaxPrice <= 0\n ) {\n return {\n success: false,\n error: \"dataMaxPrice must be a positive number\",\n };\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 };\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 };\n }\n\n // Validate date order\n if (options.startDate && options.endDate) {\n const startDate = new Date(options.startDate);\n const endDate = new Date(options.endDate);\n if (startDate > endDate) {\n return {\n success: false,\n error: \"startDate must be before endDate\",\n };\n }\n }\n\n // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\n };\n }\n\n const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Validate excludedSources format\n if (options.excludedSources !== undefined) {\n if (!Array.isArray(options.excludedSources)) {\n return {\n success: false,\n error: \"excludedSources must be an array\",\n };\n }\n\n const excludedSourcesValidation = this.validateSources(\n options.excludedSources\n );\n if (!excludedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludedSources format. Invalid sources: ${excludedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query: query.trim(),\n search_type: finalSearchType,\n data_max_price: options.dataMaxPrice ?? defaultDataMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.structuredOutput !== undefined) {\n payload.structured_output = options.structuredOutput;\n }\n\n if (options.systemInstructions !== undefined) {\n payload.system_instructions = options.systemInstructions.trim();\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludedSources !== undefined) {\n payload.excluded_sources = options.excludedSources;\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.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/answer`, 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 || \"Request failed\",\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 };\n }\n }\n}\n\nexport type {\n SearchResponse,\n SearchType,\n FeedbackSentiment,\n FeedbackResponse,\n SearchOptions,\n CountryCode,\n ResponseLength,\n ContentsOptions,\n ContentsResponse,\n ContentResult,\n ExtractEffort,\n ContentResponseLength,\n AnswerOptions,\n AnswerResponse,\n AnswerSuccessResponse,\n AnswerErrorResponse,\n SearchMetadata,\n AIUsage,\n Cost,\n} from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAaX,IAAM,QAAN,MAAY;AAAA,EAIjB,YACE,QACA,UAAkB,2BAClB;AACA,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,EAKQ,YAAY,KAAsB;AACxC,QAAI;AACF,UAAI,IAAI,GAAG;AACX,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,eAAe,QAAyB;AAG9C,UAAM,cACJ;AACF,WAAO,YAAY,KAAK,MAAM;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKQ,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C7B;AAEA,UAAI,QAAQ,aAAa,QAAW;AAClC,gBAAQ,YAAY,QAAQ;AAAA,MAC9B;AAEA,YAAM,WAAW,MAAM,aAAAA,QAAM,KAAK,GAAG,KAAK,OAAO,WAAW,SAAS;AAAA,QACnE,SAAS,KAAK;AAAA,MAChB,CAAC;AAED,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM,SAAS;AAAA,QACjC;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":["axios"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n SearchResponse,\n SearchType,\n SearchOptions,\n ContentsOptions,\n ContentsResponse,\n AnswerOptions,\n AnswerResponse,\n} from \"./types\";\n\n\n// Valyu API client\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(\n apiKey?: string,\n baseUrl: string = \"https://api.valyu.ai/v1\"\n ) {\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 * Validates if a string is a valid URL\n */\n private validateUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Validates if a string is a valid domain (with optional path)\n */\n private validateDomain(domain: string): boolean {\n // Domain must have at least one dot and valid structure\n // Supports: example.com, example.com/path, subdomain.example.com/path/to/resource\n const domainRegex =\n /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\/.+)?$/;\n return domainRegex.test(domain);\n }\n\n /**\n * Validates if a string is a valid dataset identifier (provider/datasetname)\n */\n private validateDatasetId(datasetId: string): boolean {\n // Dataset format: provider/datasetname (exactly one slash)\n // Provider and dataset name can contain alphanumeric, hyphens, underscores\n const parts = datasetId.split(\"/\");\n if (parts.length !== 2) return false;\n\n const providerRegex = /^[a-zA-Z0-9_-]+$/;\n const datasetRegex = /^[a-zA-Z0-9_-]+$/;\n\n return (\n providerRegex.test(parts[0]) &&\n datasetRegex.test(parts[1]) &&\n parts[0].length > 0 &&\n parts[1].length > 0\n );\n }\n\n /**\n * Validates source strings (domains, URLs, or dataset IDs)\n */\n private validateSource(source: string): boolean {\n // Check if it's a valid URL\n if (this.validateUrl(source)) {\n return true;\n }\n\n // Check if it's a valid domain (with optional path)\n if (this.validateDomain(source)) {\n return true;\n }\n\n // Check if it's a valid dataset identifier\n if (this.validateDatasetId(source)) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Validates an array of source strings\n */\n private validateSources(sources: string[]): {\n valid: boolean;\n invalidSources: string[];\n } {\n const invalidSources: string[] = [];\n\n for (const source of sources) {\n if (!this.validateSource(source)) {\n invalidSources.push(source);\n }\n }\n\n return {\n valid: invalidSources.length === 0,\n invalidSources,\n };\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\", \"all\", or \"news\"\n * @param options.maxNumResults - Maximum number of results (1-100)\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 * @param options.fastMode - Fast mode for quicker but shorter results (default: false)\n * @param options.urlOnly - Returns shortened snippets (default: false)\n * @returns Promise resolving to search results\n */\n async search(\n query: string,\n options: SearchOptions = {}\n ): 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\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\" ||\n providedSearchTypeString === \"news\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary, news\",\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 > 100) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 100\",\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 includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\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 const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\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 // Validate excludeSources format\n if (options.excludeSources !== undefined) {\n if (!Array.isArray(options.excludeSources)) {\n return {\n success: false,\n error: \"excludeSources must be an array\",\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 const excludeSourcesValidation = this.validateSources(\n options.excludeSources\n );\n if (!excludeSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludeSources format. Invalid sources: ${excludeSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\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 // 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:\n options.relevanceThreshold ?? defaultRelevanceThreshold,\n };\n\n // Add maxPrice only if explicitly provided\n if (options.maxPrice !== undefined) {\n payload.max_price = options.maxPrice;\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 if (options.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n if (options.urlOnly !== undefined) {\n payload.url_only = options.urlOnly;\n }\n\n const response = await axios.post(`${this.baseUrl}/deepsearch`, 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 /**\n * Extract content from URLs with optional AI processing\n * @param urls - Array of URLs to process (max 10)\n * @param options - Content extraction configuration options\n * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema\n * @param options.extractEffort - Extraction thoroughness: \"normal\" or \"high\"\n * @param options.responseLength - Content length per URL\n * @param options.maxPriceDollars - Maximum cost limit in USD\n * @returns Promise resolving to content extraction results\n */\n async contents(\n urls: string[],\n options: ContentsOptions = {}\n ): Promise<ContentsResponse> {\n try {\n // Validate URLs array\n if (!urls || !Array.isArray(urls)) {\n return {\n success: false,\n error: \"urls must be an array\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length === 0) {\n return {\n success: false,\n error: \"urls array cannot be empty\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length > 10) {\n return {\n success: false,\n error: \"Maximum 10 URLs allowed per request\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate extractEffort if provided\n if (\n options.extractEffort &&\n ![\"normal\", \"high\", \"auto\"].includes(options.extractEffort)\n ) {\n return {\n success: false,\n error: \"extractEffort must be 'normal', 'high', or 'auto'\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate responseLength if provided\n if (options.responseLength !== undefined) {\n const validLengths = [\"short\", \"medium\", \"large\", \"max\"];\n if (\n typeof options.responseLength === \"string\" &&\n !validLengths.includes(options.responseLength)\n ) {\n return {\n success: false,\n error:\n \"responseLength must be 'short', 'medium', 'large', 'max', or a number\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n if (\n typeof options.responseLength === \"number\" &&\n options.responseLength <= 0\n ) {\n return {\n success: false,\n error: \"responseLength number must be positive\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n urls,\n };\n\n // Add optional parameters only if provided\n if (options.summary !== undefined) {\n payload.summary = options.summary;\n }\n\n if (options.extractEffort !== undefined) {\n payload.extract_effort = options.extractEffort;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.maxPriceDollars !== undefined) {\n payload.max_price_dollars = options.maxPriceDollars;\n }\n\n const response = await axios.post(`${this.baseUrl}/contents`, 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 || \"Request failed\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 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 urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n /**\n * Get AI-powered answers using the Valyu Answer API\n * @param query - The question or query string\n * @param options - Answer configuration options\n * @param options.structuredOutput - JSON Schema object for structured responses\n * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)\n * @param options.searchType - Type of search: \"web\", \"proprietary\", \"all\", or \"news\"\n * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval\n * @param options.countryCode - Country code filter for search results\n * @param options.includedSources - List of specific sources to include\n * @param options.excludedSources - List of URLs/domains to exclude from 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.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to answer response\n */\n async answer(\n query: string,\n options: AnswerOptions = {}\n ): Promise<AnswerResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n\n // Validate query\n if (!query || typeof query !== \"string\" || query.trim().length === 0) {\n return {\n success: false,\n error: \"Query is required and must be a non-empty string\",\n };\n }\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\" ||\n providedSearchTypeString === \"news\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary, news\",\n };\n }\n\n // Validate systemInstructions length\n if (options.systemInstructions !== undefined) {\n if (typeof options.systemInstructions !== \"string\") {\n return {\n success: false,\n error: \"systemInstructions must be a string\",\n };\n }\n\n const trimmed = options.systemInstructions.trim();\n if (trimmed.length === 0) {\n return {\n success: false,\n error: \"systemInstructions cannot be empty when provided\",\n };\n }\n\n if (trimmed.length > 2000) {\n return {\n success: false,\n error: \"systemInstructions must be 2000 characters or less\",\n };\n }\n }\n\n // Validate dataMaxPrice\n if (options.dataMaxPrice !== undefined) {\n if (\n typeof options.dataMaxPrice !== \"number\" ||\n options.dataMaxPrice <= 0\n ) {\n return {\n success: false,\n error: \"dataMaxPrice must be a positive number\",\n };\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 };\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 };\n }\n\n // Validate date order\n if (options.startDate && options.endDate) {\n const startDate = new Date(options.startDate);\n const endDate = new Date(options.endDate);\n if (startDate > endDate) {\n return {\n success: false,\n error: \"startDate must be before endDate\",\n };\n }\n }\n\n // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\n };\n }\n\n const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Validate excludedSources format\n if (options.excludedSources !== undefined) {\n if (!Array.isArray(options.excludedSources)) {\n return {\n success: false,\n error: \"excludedSources must be an array\",\n };\n }\n\n const excludedSourcesValidation = this.validateSources(\n options.excludedSources\n );\n if (!excludedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludedSources format. Invalid sources: ${excludedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query: query.trim(),\n search_type: finalSearchType,\n };\n\n // Add dataMaxPrice only if explicitly provided\n if (options.dataMaxPrice !== undefined) {\n payload.data_max_price = options.dataMaxPrice;\n }\n\n // Add optional parameters only if provided\n if (options.structuredOutput !== undefined) {\n payload.structured_output = options.structuredOutput;\n }\n\n if (options.systemInstructions !== undefined) {\n payload.system_instructions = options.systemInstructions.trim();\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludedSources !== undefined) {\n payload.excluded_sources = options.excludedSources;\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.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/answer`, 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 || \"Request failed\",\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 };\n }\n }\n}\n\nexport type {\n SearchResponse,\n SearchType,\n FeedbackSentiment,\n FeedbackResponse,\n SearchOptions,\n CountryCode,\n ResponseLength,\n ContentsOptions,\n ContentsResponse,\n ContentResult,\n ExtractEffort,\n ContentResponseLength,\n AnswerOptions,\n AnswerResponse,\n AnswerSuccessResponse,\n AnswerErrorResponse,\n SearchMetadata,\n AIUsage,\n Cost,\n} from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAaX,IAAM,QAAN,MAAY;AAAA,EAIjB,YACE,QACA,UAAkB,2BAClB;AACA,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,EAKQ,YAAY,KAAsB;AACxC,QAAI;AACF,UAAI,IAAI,GAAG;AACX,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,eAAe,QAAyB;AAG9C,UAAM,cACJ;AACF,WAAO,YAAY,KAAK,MAAM;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKQ,kBAAkB,WAA4B;AAGpD,UAAM,QAAQ,UAAU,MAAM,GAAG;AACjC,QAAI,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;AAAA,MAC/B;AAEA,UAAI,QAAQ,YAAY,QAAW;AACjC,gBAAQ,WAAW,QAAQ;AAAA,MAC7B;AAEA,UAAI,QAAQ,aAAa,QAAW;AAClC,gBAAQ,YAAY,QAAQ;AAAA,MAC9B;AAEA,YAAM,WAAW,MAAM,aAAAA,QAAM,KAAK,GAAG,KAAK,OAAO,WAAW,SAAS;AAAA,QACnE,SAAS,KAAK;AAAA,MAChB,CAAC;AAED,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM,SAAS;AAAA,QACjC;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":["axios"]}
|
package/dist/index.mjs
CHANGED
|
@@ -87,8 +87,8 @@ var Valyu = class {
|
|
|
87
87
|
* Search for information using the Valyu DeepSearch API
|
|
88
88
|
* @param query - The search query string
|
|
89
89
|
* @param options - Search configuration options
|
|
90
|
-
* @param options.searchType - Type of search: "web", "proprietary", or "
|
|
91
|
-
* @param options.maxNumResults - Maximum number of results (1-
|
|
90
|
+
* @param options.searchType - Type of search: "web", "proprietary", "all", or "news"
|
|
91
|
+
* @param options.maxNumResults - Maximum number of results (1-100)
|
|
92
92
|
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
93
93
|
* @param options.isToolCall - Whether this is a tool call
|
|
94
94
|
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
@@ -100,6 +100,7 @@ var Valyu = class {
|
|
|
100
100
|
* @param options.countryCode - Country code filter for search results
|
|
101
101
|
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
102
102
|
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
103
|
+
* @param options.urlOnly - Returns shortened snippets (default: false)
|
|
103
104
|
* @returns Promise resolving to search results
|
|
104
105
|
*/
|
|
105
106
|
async search(query, options = {}) {
|
|
@@ -108,15 +109,14 @@ var Valyu = class {
|
|
|
108
109
|
const defaultMaxNumResults = 10;
|
|
109
110
|
const defaultIsToolCall = true;
|
|
110
111
|
const defaultRelevanceThreshold = 0.5;
|
|
111
|
-
const defaultMaxPrice = 30;
|
|
112
112
|
let finalSearchType = defaultSearchType;
|
|
113
113
|
const providedSearchTypeString = options.searchType?.toLowerCase();
|
|
114
|
-
if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all") {
|
|
114
|
+
if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all" || providedSearchTypeString === "news") {
|
|
115
115
|
finalSearchType = providedSearchTypeString;
|
|
116
116
|
} else if (options.searchType !== void 0) {
|
|
117
117
|
return {
|
|
118
118
|
success: false,
|
|
119
|
-
error: "Invalid searchType provided. Must be one of: all, web, proprietary",
|
|
119
|
+
error: "Invalid searchType provided. Must be one of: all, web, proprietary, news",
|
|
120
120
|
tx_id: null,
|
|
121
121
|
query,
|
|
122
122
|
results: [],
|
|
@@ -153,10 +153,10 @@ var Valyu = class {
|
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;
|
|
156
|
-
if (maxNumResults < 1 || maxNumResults >
|
|
156
|
+
if (maxNumResults < 1 || maxNumResults > 100) {
|
|
157
157
|
return {
|
|
158
158
|
success: false,
|
|
159
|
-
error: "maxNumResults must be between 1 and
|
|
159
|
+
error: "maxNumResults must be between 1 and 100",
|
|
160
160
|
tx_id: null,
|
|
161
161
|
query,
|
|
162
162
|
results: [],
|
|
@@ -237,9 +237,11 @@ var Valyu = class {
|
|
|
237
237
|
search_type: finalSearchType,
|
|
238
238
|
max_num_results: maxNumResults,
|
|
239
239
|
is_tool_call: options.isToolCall ?? defaultIsToolCall,
|
|
240
|
-
relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold
|
|
241
|
-
max_price: options.maxPrice ?? defaultMaxPrice
|
|
240
|
+
relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold
|
|
242
241
|
};
|
|
242
|
+
if (options.maxPrice !== void 0) {
|
|
243
|
+
payload.max_price = options.maxPrice;
|
|
244
|
+
}
|
|
243
245
|
if (options.includedSources !== void 0) {
|
|
244
246
|
payload.included_sources = options.includedSources;
|
|
245
247
|
}
|
|
@@ -264,6 +266,9 @@ var Valyu = class {
|
|
|
264
266
|
if (options.fastMode !== void 0) {
|
|
265
267
|
payload.fast_mode = options.fastMode;
|
|
266
268
|
}
|
|
269
|
+
if (options.urlOnly !== void 0) {
|
|
270
|
+
payload.url_only = options.urlOnly;
|
|
271
|
+
}
|
|
267
272
|
const response = await axios.post(`${this.baseUrl}/deepsearch`, payload, {
|
|
268
273
|
headers: this.headers
|
|
269
274
|
});
|
|
@@ -432,7 +437,7 @@ var Valyu = class {
|
|
|
432
437
|
* @param options - Answer configuration options
|
|
433
438
|
* @param options.structuredOutput - JSON Schema object for structured responses
|
|
434
439
|
* @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
|
|
435
|
-
* @param options.searchType - Type of search: "web", "proprietary", or "
|
|
440
|
+
* @param options.searchType - Type of search: "web", "proprietary", "all", or "news"
|
|
436
441
|
* @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
|
|
437
442
|
* @param options.countryCode - Country code filter for search results
|
|
438
443
|
* @param options.includedSources - List of specific sources to include
|
|
@@ -445,7 +450,6 @@ var Valyu = class {
|
|
|
445
450
|
async answer(query, options = {}) {
|
|
446
451
|
try {
|
|
447
452
|
const defaultSearchType = "all";
|
|
448
|
-
const defaultDataMaxPrice = 30;
|
|
449
453
|
if (!query || typeof query !== "string" || query.trim().length === 0) {
|
|
450
454
|
return {
|
|
451
455
|
success: false,
|
|
@@ -454,12 +458,12 @@ var Valyu = class {
|
|
|
454
458
|
}
|
|
455
459
|
let finalSearchType = defaultSearchType;
|
|
456
460
|
const providedSearchTypeString = options.searchType?.toLowerCase();
|
|
457
|
-
if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all") {
|
|
461
|
+
if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all" || providedSearchTypeString === "news") {
|
|
458
462
|
finalSearchType = providedSearchTypeString;
|
|
459
463
|
} else if (options.searchType !== void 0) {
|
|
460
464
|
return {
|
|
461
465
|
success: false,
|
|
462
|
-
error: "Invalid searchType provided. Must be one of: all, web, proprietary"
|
|
466
|
+
error: "Invalid searchType provided. Must be one of: all, web, proprietary, news"
|
|
463
467
|
};
|
|
464
468
|
}
|
|
465
469
|
if (options.systemInstructions !== void 0) {
|
|
@@ -553,9 +557,11 @@ var Valyu = class {
|
|
|
553
557
|
}
|
|
554
558
|
const payload = {
|
|
555
559
|
query: query.trim(),
|
|
556
|
-
search_type: finalSearchType
|
|
557
|
-
data_max_price: options.dataMaxPrice ?? defaultDataMaxPrice
|
|
560
|
+
search_type: finalSearchType
|
|
558
561
|
};
|
|
562
|
+
if (options.dataMaxPrice !== void 0) {
|
|
563
|
+
payload.data_max_price = options.dataMaxPrice;
|
|
564
|
+
}
|
|
559
565
|
if (options.structuredOutput !== void 0) {
|
|
560
566
|
payload.structured_output = options.structuredOutput;
|
|
561
567
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n SearchResponse,\n SearchType,\n SearchOptions,\n ContentsOptions,\n ContentsResponse,\n AnswerOptions,\n AnswerResponse,\n} from \"./types\";\n\n\n// Valyu API client\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(\n apiKey?: string,\n baseUrl: string = \"https://api.valyu.ai/v1\"\n ) {\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 * Validates if a string is a valid URL\n */\n private validateUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Validates if a string is a valid domain (with optional path)\n */\n private validateDomain(domain: string): boolean {\n // Domain must have at least one dot and valid structure\n // Supports: example.com, example.com/path, subdomain.example.com/path/to/resource\n const domainRegex =\n /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\/.+)?$/;\n return domainRegex.test(domain);\n }\n\n /**\n * Validates if a string is a valid dataset identifier (provider/datasetname)\n */\n private validateDatasetId(datasetId: string): boolean {\n // Dataset format: provider/datasetname (exactly one slash)\n // Provider and dataset name can contain alphanumeric, hyphens, underscores\n const parts = datasetId.split(\"/\");\n if (parts.length !== 2) return false;\n\n const providerRegex = /^[a-zA-Z0-9_-]+$/;\n const datasetRegex = /^[a-zA-Z0-9_-]+$/;\n\n return (\n providerRegex.test(parts[0]) &&\n datasetRegex.test(parts[1]) &&\n parts[0].length > 0 &&\n parts[1].length > 0\n );\n }\n\n /**\n * Validates source strings (domains, URLs, or dataset IDs)\n */\n private validateSource(source: string): boolean {\n // Check if it's a valid URL\n if (this.validateUrl(source)) {\n return true;\n }\n\n // Check if it's a valid domain (with optional path)\n if (this.validateDomain(source)) {\n return true;\n }\n\n // Check if it's a valid dataset identifier\n if (this.validateDatasetId(source)) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Validates an array of source strings\n */\n private validateSources(sources: string[]): {\n valid: boolean;\n invalidSources: string[];\n } {\n const invalidSources: string[] = [];\n\n for (const source of sources) {\n if (!this.validateSource(source)) {\n invalidSources.push(source);\n }\n }\n\n return {\n valid: invalidSources.length === 0,\n invalidSources,\n };\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 * @param options.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to search results\n */\n async search(\n query: string,\n options: SearchOptions = {}\n ): 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 (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"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 // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\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 const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\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 // Validate excludeSources format\n if (options.excludeSources !== undefined) {\n if (!Array.isArray(options.excludeSources)) {\n return {\n success: false,\n error: \"excludeSources must be an array\",\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 const excludeSourcesValidation = this.validateSources(\n options.excludeSources\n );\n if (!excludeSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludeSources format. Invalid sources: ${excludeSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\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 // 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:\n 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 if (options.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/deepsearch`, 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 /**\n * Extract content from URLs with optional AI processing\n * @param urls - Array of URLs to process (max 10)\n * @param options - Content extraction configuration options\n * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema\n * @param options.extractEffort - Extraction thoroughness: \"normal\" or \"high\"\n * @param options.responseLength - Content length per URL\n * @param options.maxPriceDollars - Maximum cost limit in USD\n * @returns Promise resolving to content extraction results\n */\n async contents(\n urls: string[],\n options: ContentsOptions = {}\n ): Promise<ContentsResponse> {\n try {\n // Validate URLs array\n if (!urls || !Array.isArray(urls)) {\n return {\n success: false,\n error: \"urls must be an array\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length === 0) {\n return {\n success: false,\n error: \"urls array cannot be empty\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length > 10) {\n return {\n success: false,\n error: \"Maximum 10 URLs allowed per request\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate extractEffort if provided\n if (\n options.extractEffort &&\n ![\"normal\", \"high\", \"auto\"].includes(options.extractEffort)\n ) {\n return {\n success: false,\n error: \"extractEffort must be 'normal', 'high', or 'auto'\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate responseLength if provided\n if (options.responseLength !== undefined) {\n const validLengths = [\"short\", \"medium\", \"large\", \"max\"];\n if (\n typeof options.responseLength === \"string\" &&\n !validLengths.includes(options.responseLength)\n ) {\n return {\n success: false,\n error:\n \"responseLength must be 'short', 'medium', 'large', 'max', or a number\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n if (\n typeof options.responseLength === \"number\" &&\n options.responseLength <= 0\n ) {\n return {\n success: false,\n error: \"responseLength number must be positive\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n urls,\n };\n\n // Add optional parameters only if provided\n if (options.summary !== undefined) {\n payload.summary = options.summary;\n }\n\n if (options.extractEffort !== undefined) {\n payload.extract_effort = options.extractEffort;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.maxPriceDollars !== undefined) {\n payload.max_price_dollars = options.maxPriceDollars;\n }\n\n const response = await axios.post(`${this.baseUrl}/contents`, 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 || \"Request failed\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 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 urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n /**\n * Get AI-powered answers using the Valyu Answer API\n * @param query - The question or query string\n * @param options - Answer configuration options\n * @param options.structuredOutput - JSON Schema object for structured responses\n * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval\n * @param options.countryCode - Country code filter for search results\n * @param options.includedSources - List of specific sources to include\n * @param options.excludedSources - List of URLs/domains to exclude from 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.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to answer response\n */\n async answer(\n query: string,\n options: AnswerOptions = {}\n ): Promise<AnswerResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultDataMaxPrice = 30.0;\n\n // Validate query\n if (!query || typeof query !== \"string\" || query.trim().length === 0) {\n return {\n success: false,\n error: \"Query is required and must be a non-empty string\",\n };\n }\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n };\n }\n\n // Validate systemInstructions length\n if (options.systemInstructions !== undefined) {\n if (typeof options.systemInstructions !== \"string\") {\n return {\n success: false,\n error: \"systemInstructions must be a string\",\n };\n }\n\n const trimmed = options.systemInstructions.trim();\n if (trimmed.length === 0) {\n return {\n success: false,\n error: \"systemInstructions cannot be empty when provided\",\n };\n }\n\n if (trimmed.length > 2000) {\n return {\n success: false,\n error: \"systemInstructions must be 2000 characters or less\",\n };\n }\n }\n\n // Validate dataMaxPrice\n if (options.dataMaxPrice !== undefined) {\n if (\n typeof options.dataMaxPrice !== \"number\" ||\n options.dataMaxPrice <= 0\n ) {\n return {\n success: false,\n error: \"dataMaxPrice must be a positive number\",\n };\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 };\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 };\n }\n\n // Validate date order\n if (options.startDate && options.endDate) {\n const startDate = new Date(options.startDate);\n const endDate = new Date(options.endDate);\n if (startDate > endDate) {\n return {\n success: false,\n error: \"startDate must be before endDate\",\n };\n }\n }\n\n // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\n };\n }\n\n const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Validate excludedSources format\n if (options.excludedSources !== undefined) {\n if (!Array.isArray(options.excludedSources)) {\n return {\n success: false,\n error: \"excludedSources must be an array\",\n };\n }\n\n const excludedSourcesValidation = this.validateSources(\n options.excludedSources\n );\n if (!excludedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludedSources format. Invalid sources: ${excludedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query: query.trim(),\n search_type: finalSearchType,\n data_max_price: options.dataMaxPrice ?? defaultDataMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.structuredOutput !== undefined) {\n payload.structured_output = options.structuredOutput;\n }\n\n if (options.systemInstructions !== undefined) {\n payload.system_instructions = options.systemInstructions.trim();\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludedSources !== undefined) {\n payload.excluded_sources = options.excludedSources;\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.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/answer`, 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 || \"Request failed\",\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 };\n }\n }\n}\n\nexport type {\n SearchResponse,\n SearchType,\n FeedbackSentiment,\n FeedbackResponse,\n SearchOptions,\n CountryCode,\n ResponseLength,\n ContentsOptions,\n ContentsResponse,\n ContentResult,\n ExtractEffort,\n ContentResponseLength,\n AnswerOptions,\n AnswerResponse,\n AnswerSuccessResponse,\n AnswerErrorResponse,\n SearchMetadata,\n AIUsage,\n Cost,\n} from \"./types\";\n"],"mappings":";AAAA,OAAO,WAAW;AAaX,IAAM,QAAN,MAAY;AAAA,EAIjB,YACE,QACA,UAAkB,2BAClB;AACA,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,EAKQ,YAAY,KAAsB;AACxC,QAAI;AACF,UAAI,IAAI,GAAG;AACX,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,eAA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AAQ;AAAA,MAC/B;AAEA,UAAI,QAAQ,YAAY,QAAW;AACjC,gBAAQ,WAAW,QAAQ;AAAA,MAC7B;AAEA,UAAI,QAAQ,aAAa,QAAW;AAClC,gBAAQ,YAAY,QAAQ;AAAA,MAC9B;AAEA,YAAM,WAAW,MAAM,MAAM,KAAK,GAAG,KAAK,OAAO,WAAW,SAAS;AAAA,QACnE,SAAS,KAAK;AAAA,MAChB,CAAC;AAED,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM,SAAS;AAAA,QACjC;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n SearchResponse,\n SearchType,\n SearchOptions,\n ContentsOptions,\n ContentsResponse,\n AnswerOptions,\n AnswerResponse,\n} from \"./types\";\n\n\n// Valyu API client\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(\n apiKey?: string,\n baseUrl: string = \"https://api.valyu.ai/v1\"\n ) {\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 * Validates if a string is a valid URL\n */\n private validateUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Validates if a string is a valid domain (with optional path)\n */\n private validateDomain(domain: string): boolean {\n // Domain must have at least one dot and valid structure\n // Supports: example.com, example.com/path, subdomain.example.com/path/to/resource\n const domainRegex =\n /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\/.+)?$/;\n return domainRegex.test(domain);\n }\n\n /**\n * Validates if a string is a valid dataset identifier (provider/datasetname)\n */\n private validateDatasetId(datasetId: string): boolean {\n // Dataset format: provider/datasetname (exactly one slash)\n // Provider and dataset name can contain alphanumeric, hyphens, underscores\n const parts = datasetId.split(\"/\");\n if (parts.length !== 2) return false;\n\n const providerRegex = /^[a-zA-Z0-9_-]+$/;\n const datasetRegex = /^[a-zA-Z0-9_-]+$/;\n\n return (\n providerRegex.test(parts[0]) &&\n datasetRegex.test(parts[1]) &&\n parts[0].length > 0 &&\n parts[1].length > 0\n );\n }\n\n /**\n * Validates source strings (domains, URLs, or dataset IDs)\n */\n private validateSource(source: string): boolean {\n // Check if it's a valid URL\n if (this.validateUrl(source)) {\n return true;\n }\n\n // Check if it's a valid domain (with optional path)\n if (this.validateDomain(source)) {\n return true;\n }\n\n // Check if it's a valid dataset identifier\n if (this.validateDatasetId(source)) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Validates an array of source strings\n */\n private validateSources(sources: string[]): {\n valid: boolean;\n invalidSources: string[];\n } {\n const invalidSources: string[] = [];\n\n for (const source of sources) {\n if (!this.validateSource(source)) {\n invalidSources.push(source);\n }\n }\n\n return {\n valid: invalidSources.length === 0,\n invalidSources,\n };\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\", \"all\", or \"news\"\n * @param options.maxNumResults - Maximum number of results (1-100)\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 * @param options.fastMode - Fast mode for quicker but shorter results (default: false)\n * @param options.urlOnly - Returns shortened snippets (default: false)\n * @returns Promise resolving to search results\n */\n async search(\n query: string,\n options: SearchOptions = {}\n ): 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\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\" ||\n providedSearchTypeString === \"news\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary, news\",\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 > 100) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 100\",\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 includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\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 const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\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 // Validate excludeSources format\n if (options.excludeSources !== undefined) {\n if (!Array.isArray(options.excludeSources)) {\n return {\n success: false,\n error: \"excludeSources must be an array\",\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 const excludeSourcesValidation = this.validateSources(\n options.excludeSources\n );\n if (!excludeSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludeSources format. Invalid sources: ${excludeSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\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 // 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:\n options.relevanceThreshold ?? defaultRelevanceThreshold,\n };\n\n // Add maxPrice only if explicitly provided\n if (options.maxPrice !== undefined) {\n payload.max_price = options.maxPrice;\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 if (options.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n if (options.urlOnly !== undefined) {\n payload.url_only = options.urlOnly;\n }\n\n const response = await axios.post(`${this.baseUrl}/deepsearch`, 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 /**\n * Extract content from URLs with optional AI processing\n * @param urls - Array of URLs to process (max 10)\n * @param options - Content extraction configuration options\n * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema\n * @param options.extractEffort - Extraction thoroughness: \"normal\" or \"high\"\n * @param options.responseLength - Content length per URL\n * @param options.maxPriceDollars - Maximum cost limit in USD\n * @returns Promise resolving to content extraction results\n */\n async contents(\n urls: string[],\n options: ContentsOptions = {}\n ): Promise<ContentsResponse> {\n try {\n // Validate URLs array\n if (!urls || !Array.isArray(urls)) {\n return {\n success: false,\n error: \"urls must be an array\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length === 0) {\n return {\n success: false,\n error: \"urls array cannot be empty\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length > 10) {\n return {\n success: false,\n error: \"Maximum 10 URLs allowed per request\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate extractEffort if provided\n if (\n options.extractEffort &&\n ![\"normal\", \"high\", \"auto\"].includes(options.extractEffort)\n ) {\n return {\n success: false,\n error: \"extractEffort must be 'normal', 'high', or 'auto'\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate responseLength if provided\n if (options.responseLength !== undefined) {\n const validLengths = [\"short\", \"medium\", \"large\", \"max\"];\n if (\n typeof options.responseLength === \"string\" &&\n !validLengths.includes(options.responseLength)\n ) {\n return {\n success: false,\n error:\n \"responseLength must be 'short', 'medium', 'large', 'max', or a number\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n if (\n typeof options.responseLength === \"number\" &&\n options.responseLength <= 0\n ) {\n return {\n success: false,\n error: \"responseLength number must be positive\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n urls,\n };\n\n // Add optional parameters only if provided\n if (options.summary !== undefined) {\n payload.summary = options.summary;\n }\n\n if (options.extractEffort !== undefined) {\n payload.extract_effort = options.extractEffort;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.maxPriceDollars !== undefined) {\n payload.max_price_dollars = options.maxPriceDollars;\n }\n\n const response = await axios.post(`${this.baseUrl}/contents`, 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 || \"Request failed\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 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 urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n /**\n * Get AI-powered answers using the Valyu Answer API\n * @param query - The question or query string\n * @param options - Answer configuration options\n * @param options.structuredOutput - JSON Schema object for structured responses\n * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)\n * @param options.searchType - Type of search: \"web\", \"proprietary\", \"all\", or \"news\"\n * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval\n * @param options.countryCode - Country code filter for search results\n * @param options.includedSources - List of specific sources to include\n * @param options.excludedSources - List of URLs/domains to exclude from 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.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to answer response\n */\n async answer(\n query: string,\n options: AnswerOptions = {}\n ): Promise<AnswerResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n\n // Validate query\n if (!query || typeof query !== \"string\" || query.trim().length === 0) {\n return {\n success: false,\n error: \"Query is required and must be a non-empty string\",\n };\n }\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\" ||\n providedSearchTypeString === \"news\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary, news\",\n };\n }\n\n // Validate systemInstructions length\n if (options.systemInstructions !== undefined) {\n if (typeof options.systemInstructions !== \"string\") {\n return {\n success: false,\n error: \"systemInstructions must be a string\",\n };\n }\n\n const trimmed = options.systemInstructions.trim();\n if (trimmed.length === 0) {\n return {\n success: false,\n error: \"systemInstructions cannot be empty when provided\",\n };\n }\n\n if (trimmed.length > 2000) {\n return {\n success: false,\n error: \"systemInstructions must be 2000 characters or less\",\n };\n }\n }\n\n // Validate dataMaxPrice\n if (options.dataMaxPrice !== undefined) {\n if (\n typeof options.dataMaxPrice !== \"number\" ||\n options.dataMaxPrice <= 0\n ) {\n return {\n success: false,\n error: \"dataMaxPrice must be a positive number\",\n };\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 };\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 };\n }\n\n // Validate date order\n if (options.startDate && options.endDate) {\n const startDate = new Date(options.startDate);\n const endDate = new Date(options.endDate);\n if (startDate > endDate) {\n return {\n success: false,\n error: \"startDate must be before endDate\",\n };\n }\n }\n\n // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\n };\n }\n\n const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Validate excludedSources format\n if (options.excludedSources !== undefined) {\n if (!Array.isArray(options.excludedSources)) {\n return {\n success: false,\n error: \"excludedSources must be an array\",\n };\n }\n\n const excludedSourcesValidation = this.validateSources(\n options.excludedSources\n );\n if (!excludedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludedSources format. Invalid sources: ${excludedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query: query.trim(),\n search_type: finalSearchType,\n };\n\n // Add dataMaxPrice only if explicitly provided\n if (options.dataMaxPrice !== undefined) {\n payload.data_max_price = options.dataMaxPrice;\n }\n\n // Add optional parameters only if provided\n if (options.structuredOutput !== undefined) {\n payload.structured_output = options.structuredOutput;\n }\n\n if (options.systemInstructions !== undefined) {\n payload.system_instructions = options.systemInstructions.trim();\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludedSources !== undefined) {\n payload.excluded_sources = options.excludedSources;\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.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/answer`, 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 || \"Request failed\",\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 };\n }\n }\n}\n\nexport type {\n SearchResponse,\n SearchType,\n FeedbackSentiment,\n FeedbackResponse,\n SearchOptions,\n CountryCode,\n ResponseLength,\n ContentsOptions,\n ContentsResponse,\n ContentResult,\n ExtractEffort,\n ContentResponseLength,\n AnswerOptions,\n AnswerResponse,\n AnswerSuccessResponse,\n AnswerErrorResponse,\n SearchMetadata,\n AIUsage,\n Cost,\n} from \"./types\";\n"],"mappings":";AAAA,OAAO,WAAW;AAaX,IAAM,QAAN,MAAY;AAAA,EAIjB,YACE,QACA,UAAkB,2BAClB;AACA,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,EAKQ,YAAY,KAAsB;AACxC,QAAI;AACF,UAAI,IAAI,GAAG;AACX,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,eAAe,QAAyB;AAG9C,UAAM,cACJ;AACF,WAAO,YAAY,KAAK,MAAM;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKQ,kBAAkB,WAA4B;AAGpD,UAAM,QAAQ,UAAU,MAAM,GAA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