valyu-js 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +215 -35
- package/dist/index.d.mts +65 -2
- package/dist/index.d.ts +65 -2
- package/dist/index.js +158 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Valyu SDK
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Search for AIs**
|
|
4
4
|
|
|
5
5
|
Valyu's Deepsearch API gives AI the context it needs. Integrate trusted, high-quality public and proprietary sources, with full-text multimodal retrieval.
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ Get **$10 free credits** for the Valyu API when you sign up at [Valyu](https://p
|
|
|
10
10
|
|
|
11
11
|
## How does it work?
|
|
12
12
|
|
|
13
|
-
We do all the heavy lifting for you -
|
|
13
|
+
We do all the heavy lifting for you - one unified API for all data:
|
|
14
14
|
|
|
15
15
|
- **Academic & Research Content** - Access millions of scholarly papers and textbooks
|
|
16
16
|
- **Real-time Web Search** - Get the latest information from across the internet
|
|
@@ -36,7 +36,11 @@ const { Valyu } = require('valyu');
|
|
|
36
36
|
const valyu = new Valyu("your-api-key-here");
|
|
37
37
|
|
|
38
38
|
const response = await valyu.search(
|
|
39
|
-
"Implementation details of agentic search-enhanced large reasoning models"
|
|
39
|
+
"Implementation details of agentic search-enhanced large reasoning models",
|
|
40
|
+
{
|
|
41
|
+
maxNumResults: 5, // Limit to top 5 results
|
|
42
|
+
maxPrice: 10 // Maximum price per thousand queries (CPM)
|
|
43
|
+
}
|
|
40
44
|
);
|
|
41
45
|
|
|
42
46
|
console.log(response);
|
|
@@ -60,9 +64,12 @@ valyu.search(
|
|
|
60
64
|
relevanceThreshold: 0.5, // Minimum relevance score (0-1)
|
|
61
65
|
maxPrice: 30, // Maximum price per thousand queries (CPM)
|
|
62
66
|
includedSources: [], // Specific sources to search
|
|
67
|
+
excludeSources: [], // Sources/domains to exclude
|
|
63
68
|
category: null, // Category filter
|
|
64
69
|
startDate: null, // Start date (YYYY-MM-DD)
|
|
65
|
-
endDate: null
|
|
70
|
+
endDate: null, // End date (YYYY-MM-DD)
|
|
71
|
+
countryCode: null, // Country code filter
|
|
72
|
+
responseLength: null // Response length control
|
|
66
73
|
}
|
|
67
74
|
)
|
|
68
75
|
```
|
|
@@ -78,9 +85,12 @@ valyu.search(
|
|
|
78
85
|
| `relevanceThreshold` | `number` | `0.5` | Minimum relevance score for results (0.0-1.0) |
|
|
79
86
|
| `maxPrice` | `number` | `30` | Maximum price per thousand queries in CPM |
|
|
80
87
|
| `includedSources` | `string[]` | `[]` | Specific data sources or URLs to search |
|
|
88
|
+
| `excludeSources` | `string[]` | `[]` | Data sources or URLs to exclude from search |
|
|
81
89
|
| `category` | `string` | `null` | Category filter for results |
|
|
82
90
|
| `startDate` | `string` | `null` | Start date filter in YYYY-MM-DD format |
|
|
83
91
|
| `endDate` | `string` | `null` | End date filter in YYYY-MM-DD format |
|
|
92
|
+
| `countryCode` | `string` | `null` | Country code filter (e.g., "US", "GB", "JP", "ALL") |
|
|
93
|
+
| `responseLength` | `string \| number` | `null` | Response length: "short", "medium", "large", "max", or character count |
|
|
84
94
|
|
|
85
95
|
### Response Format
|
|
86
96
|
|
|
@@ -120,6 +130,67 @@ Each `SearchResult` contains:
|
|
|
120
130
|
}
|
|
121
131
|
```
|
|
122
132
|
|
|
133
|
+
### Contents Method
|
|
134
|
+
|
|
135
|
+
The `contents()` method extracts clean, structured content from web pages with optional AI-powered data extraction and summarization. It accepts an array of URLs as the first parameter, followed by optional configuration parameters.
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
valyu.contents(
|
|
139
|
+
urls, // Array of URLs to process (max 10)
|
|
140
|
+
{
|
|
141
|
+
summary: false, // AI processing: false, true, string, or JSON schema
|
|
142
|
+
extractEffort: "normal", // Extraction effort: "normal" or "high"
|
|
143
|
+
responseLength: "short", // Content length control
|
|
144
|
+
maxPriceDollars: null // Maximum cost limit in USD
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Parameters
|
|
150
|
+
|
|
151
|
+
| Parameter | Type | Default | Description |
|
|
152
|
+
|-----------|------|---------|-------------|
|
|
153
|
+
| `urls` | `string[]` | *required* | Array of URLs to process (maximum 10 URLs per request) |
|
|
154
|
+
| `summary` | `boolean \| string \| object` | `false` | AI summary configuration: `false` (raw content), `true` (auto summary), string (custom instructions), or JSON schema (structured extraction) |
|
|
155
|
+
| `extractEffort` | `string` | `"normal"` | Extraction thoroughness: `"normal"` (fast) or `"high"` (more thorough but slower) |
|
|
156
|
+
| `responseLength` | `string \| number` | `"short"` | Content length per URL: `"short"` (25k chars), `"medium"` (50k), `"large"` (100k), `"max"` (no limit), or custom number |
|
|
157
|
+
| `maxPriceDollars` | `number` | `null` | Maximum cost limit in USD |
|
|
158
|
+
|
|
159
|
+
### Contents Response Format
|
|
160
|
+
|
|
161
|
+
The contents method returns a `ContentsResponse` object with the following structure:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
{
|
|
165
|
+
success: boolean, // Request success status
|
|
166
|
+
error: string | null, // Error message if any
|
|
167
|
+
tx_id: string, // Transaction ID for tracking
|
|
168
|
+
urls_requested: number, // Total URLs requested
|
|
169
|
+
urls_processed: number, // Successfully processed URLs
|
|
170
|
+
urls_failed: number, // Failed URL count
|
|
171
|
+
results: ContentResult[], // Array of processed results
|
|
172
|
+
total_cost_dollars: number, // Actual cost charged
|
|
173
|
+
total_characters: number // Total characters extracted
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Each `ContentResult` contains:
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
{
|
|
181
|
+
url: string, // Source URL
|
|
182
|
+
title: string, // Page/document title
|
|
183
|
+
content: string | number, // Extracted content
|
|
184
|
+
length: number, // Content length in characters
|
|
185
|
+
source: string, // Data source identifier
|
|
186
|
+
summary?: string | object, // AI-generated summary (if enabled)
|
|
187
|
+
summary_success?: boolean, // Whether summary generation succeeded
|
|
188
|
+
data_type?: string, // Type of data extracted
|
|
189
|
+
image_url?: Record<string, string>, // Extracted images
|
|
190
|
+
citation?: string // APA-style citation
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
123
194
|
## Examples
|
|
124
195
|
|
|
125
196
|
### Basic Search
|
|
@@ -139,13 +210,12 @@ console.log(`Found ${response.results.length} results`);
|
|
|
139
210
|
```javascript
|
|
140
211
|
// Search academic papers on arXiv
|
|
141
212
|
const response = await valyu.search(
|
|
142
|
-
"
|
|
213
|
+
"transformer architecture improvements",
|
|
143
214
|
{
|
|
144
215
|
searchType: "proprietary",
|
|
145
|
-
maxNumResults: 10,
|
|
146
|
-
relevanceThreshold: 0.6,
|
|
147
216
|
includedSources: ["valyu/valyu-arxiv"],
|
|
148
|
-
|
|
217
|
+
relevanceThreshold: 0.7,
|
|
218
|
+
maxNumResults: 10
|
|
149
219
|
}
|
|
150
220
|
);
|
|
151
221
|
```
|
|
@@ -155,13 +225,12 @@ const response = await valyu.search(
|
|
|
155
225
|
```javascript
|
|
156
226
|
// Search recent web content
|
|
157
227
|
const response = await valyu.search(
|
|
158
|
-
"
|
|
228
|
+
"AI safety developments",
|
|
159
229
|
{
|
|
160
230
|
searchType: "web",
|
|
161
|
-
maxNumResults: 7,
|
|
162
|
-
relevanceThreshold: 0.5,
|
|
163
231
|
startDate: "2024-01-01",
|
|
164
|
-
endDate: "2024-12-31"
|
|
232
|
+
endDate: "2024-12-31",
|
|
233
|
+
maxNumResults: 5
|
|
165
234
|
}
|
|
166
235
|
);
|
|
167
236
|
```
|
|
@@ -171,13 +240,13 @@ const response = await valyu.search(
|
|
|
171
240
|
```javascript
|
|
172
241
|
// Search both web and proprietary sources
|
|
173
242
|
const response = await valyu.search(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
243
|
+
"quantum computing breakthroughs",
|
|
244
|
+
{
|
|
245
|
+
searchType: "all",
|
|
246
|
+
category: "technology",
|
|
247
|
+
relevanceThreshold: 0.6,
|
|
248
|
+
maxPrice: 50
|
|
249
|
+
}
|
|
181
250
|
);
|
|
182
251
|
```
|
|
183
252
|
|
|
@@ -201,6 +270,94 @@ if (response.success) {
|
|
|
201
270
|
}
|
|
202
271
|
```
|
|
203
272
|
|
|
273
|
+
### Content Extraction Examples
|
|
274
|
+
|
|
275
|
+
#### Basic Content Extraction
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
// Extract raw content from URLs
|
|
279
|
+
const response = await valyu.contents(
|
|
280
|
+
["https://techcrunch.com/2025/08/28/anthropic-users-face-a-new-choice-opt-out-or-share-your-data-for-ai-training/"]
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
if (response.success) {
|
|
284
|
+
response.results.forEach(result => {
|
|
285
|
+
console.log(`Title: ${result.title}`);
|
|
286
|
+
console.log(`Content: ${result.content.substring(0, 500)}...`);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
#### Content with AI Summary
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
// Extract content with automatic summarization
|
|
295
|
+
const response = await valyu.contents(
|
|
296
|
+
["https://docs.python.org/3/tutorial/"],
|
|
297
|
+
{
|
|
298
|
+
summary: true,
|
|
299
|
+
responseLength: "max"
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
response.results.forEach(result => {
|
|
304
|
+
console.log(`Summary: ${result.summary}`);
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
#### Structured Data Extraction
|
|
309
|
+
|
|
310
|
+
```javascript
|
|
311
|
+
// Extract structured data using JSON schema
|
|
312
|
+
const companySchema = {
|
|
313
|
+
type: "object",
|
|
314
|
+
properties: {
|
|
315
|
+
company_name: { type: "string" },
|
|
316
|
+
founded_year: { type: "integer" },
|
|
317
|
+
key_products: {
|
|
318
|
+
type: "array",
|
|
319
|
+
items: { type: "string" },
|
|
320
|
+
maxItems: 3
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const response = await valyu.contents(
|
|
326
|
+
["https://en.wikipedia.org/wiki/OpenAI"],
|
|
327
|
+
{
|
|
328
|
+
summary: companySchema,
|
|
329
|
+
responseLength: "max"
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
if (response.success) {
|
|
334
|
+
response.results.forEach(result => {
|
|
335
|
+
if (result.summary) {
|
|
336
|
+
console.log(`Structured data: ${JSON.stringify(result.summary, null, 2)}`);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Multiple URLs
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
// Process multiple URLs with a cost limit
|
|
346
|
+
const response = await valyu.contents(
|
|
347
|
+
[
|
|
348
|
+
"https://www.valyu.network/",
|
|
349
|
+
"https://docs.valyu.network/overview",
|
|
350
|
+
"https://www.valyu.network/blogs/why-ai-agents-and-llms-struggle-with-search-and-data-access"
|
|
351
|
+
],
|
|
352
|
+
{
|
|
353
|
+
summary: "Provide key takeaways in bullet points, and write in very emphasised singaporean english"
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
console.log(`Processed ${response.urls_processed}/${response.urls_requested} URLs`);
|
|
358
|
+
console.log(`Cost: $${response.total_cost_dollars.toFixed(4)}`);
|
|
359
|
+
```
|
|
360
|
+
|
|
204
361
|
## Authentication
|
|
205
362
|
|
|
206
363
|
Set your API key in one of these ways:
|
|
@@ -215,14 +372,6 @@ Set your API key in one of these ways:
|
|
|
215
372
|
const valyu = new Valyu("your-api-key-here");
|
|
216
373
|
```
|
|
217
374
|
|
|
218
|
-
3. **Custom base URL** (for staging/testing):
|
|
219
|
-
```javascript
|
|
220
|
-
const valyu = new Valyu(
|
|
221
|
-
"your-api-key-here",
|
|
222
|
-
"https://stage.api.valyu.network/v1"
|
|
223
|
-
);
|
|
224
|
-
```
|
|
225
|
-
|
|
226
375
|
## Error Handling
|
|
227
376
|
|
|
228
377
|
The SDK handles errors gracefully and returns structured error responses:
|
|
@@ -243,20 +392,45 @@ if (!response.success) {
|
|
|
243
392
|
|
|
244
393
|
## TypeScript Support
|
|
245
394
|
|
|
246
|
-
The SDK includes full TypeScript support:
|
|
395
|
+
The SDK includes full TypeScript support with type definitions for all parameters:
|
|
247
396
|
|
|
248
397
|
```typescript
|
|
249
|
-
import {
|
|
398
|
+
import {
|
|
399
|
+
Valyu,
|
|
400
|
+
SearchOptions,
|
|
401
|
+
SearchResponse,
|
|
402
|
+
ContentsOptions,
|
|
403
|
+
ContentsResponse,
|
|
404
|
+
CountryCode,
|
|
405
|
+
ResponseLength
|
|
406
|
+
} from 'valyu';
|
|
250
407
|
|
|
251
408
|
const valyu = new Valyu("your-api-key");
|
|
252
409
|
|
|
253
|
-
|
|
410
|
+
// Search API with types
|
|
411
|
+
const searchOptions: SearchOptions = {
|
|
254
412
|
searchType: "proprietary",
|
|
255
413
|
maxNumResults: 10,
|
|
256
|
-
relevanceThreshold: 0.6
|
|
414
|
+
relevanceThreshold: 0.6,
|
|
415
|
+
excludeSources: ["reddit.com", "twitter.com"],
|
|
416
|
+
countryCode: "US" as CountryCode,
|
|
417
|
+
responseLength: "medium" as ResponseLength
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const searchResponse: SearchResponse = await valyu.search("machine learning", searchOptions);
|
|
421
|
+
|
|
422
|
+
// Contents API with types
|
|
423
|
+
const contentsOptions: ContentsOptions = {
|
|
424
|
+
summary: true,
|
|
425
|
+
extractEffort: "high",
|
|
426
|
+
responseLength: "medium",
|
|
427
|
+
maxPriceDollars: 0.10
|
|
257
428
|
};
|
|
258
429
|
|
|
259
|
-
const
|
|
430
|
+
const contentsResponse: ContentsResponse = await valyu.contents(
|
|
431
|
+
["https://example.com"],
|
|
432
|
+
contentsOptions
|
|
433
|
+
);
|
|
260
434
|
```
|
|
261
435
|
|
|
262
436
|
## Backward Compatibility
|
|
@@ -287,7 +461,7 @@ const response = await valyu.context(
|
|
|
287
461
|
|
|
288
462
|
## Getting Started
|
|
289
463
|
|
|
290
|
-
1. Sign up for a free account at [Valyu](https://
|
|
464
|
+
1. Sign up for a free account at [Valyu](https://platform.valyu.network)
|
|
291
465
|
2. Get your API key from the dashboard
|
|
292
466
|
3. Install the SDK: `npm install valyu`
|
|
293
467
|
4. Start building with the examples above
|
|
@@ -300,10 +474,16 @@ Run the integration tests:
|
|
|
300
474
|
npm run test:integration
|
|
301
475
|
```
|
|
302
476
|
|
|
303
|
-
Run the
|
|
477
|
+
Run the Search API examples:
|
|
478
|
+
|
|
479
|
+
```bash
|
|
480
|
+
node examples/search-examples.js
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Run the Contents API examples:
|
|
304
484
|
|
|
305
485
|
```bash
|
|
306
|
-
node examples/
|
|
486
|
+
node examples/contents-examples.js
|
|
307
487
|
```
|
|
308
488
|
|
|
309
489
|
## Support
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
type SearchType = "web" | "proprietary" | "all";
|
|
2
2
|
type FeedbackSentiment = "very good" | "good" | "bad" | "very bad";
|
|
3
3
|
type DataType = "structured" | "unstructured";
|
|
4
|
+
type CountryCode = "ALL" | "AR" | "AU" | "AT" | "BE" | "BR" | "CA" | "CL" | "DK" | "FI" | "FR" | "DE" | "HK" | "IN" | "ID" | "IT" | "JP" | "KR" | "MY" | "MX" | "NL" | "NZ" | "NO" | "CN" | "PL" | "PT" | "PH" | "RU" | "SA" | "ZA" | "ES" | "SE" | "CH" | "TW" | "TR" | "GB" | "US";
|
|
5
|
+
type ResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
4
6
|
interface SearchResult {
|
|
5
7
|
title: string;
|
|
6
8
|
url: string;
|
|
@@ -19,9 +21,12 @@ interface SearchOptions {
|
|
|
19
21
|
isToolCall?: boolean;
|
|
20
22
|
relevanceThreshold?: number;
|
|
21
23
|
includedSources?: string[];
|
|
24
|
+
excludeSources?: string[];
|
|
22
25
|
category?: string;
|
|
23
26
|
startDate?: string;
|
|
24
27
|
endDate?: string;
|
|
28
|
+
countryCode?: CountryCode;
|
|
29
|
+
responseLength?: ResponseLength;
|
|
25
30
|
}
|
|
26
31
|
interface SearchResponse {
|
|
27
32
|
success: boolean;
|
|
@@ -41,6 +46,38 @@ interface FeedbackResponse {
|
|
|
41
46
|
success: boolean;
|
|
42
47
|
error?: string;
|
|
43
48
|
}
|
|
49
|
+
type ExtractEffort = "normal" | "high";
|
|
50
|
+
type ContentResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
51
|
+
interface ContentsOptions {
|
|
52
|
+
summary?: boolean | string | object;
|
|
53
|
+
extractEffort?: ExtractEffort;
|
|
54
|
+
responseLength?: ContentResponseLength;
|
|
55
|
+
maxPriceDollars?: number;
|
|
56
|
+
}
|
|
57
|
+
interface ContentResult {
|
|
58
|
+
url: string;
|
|
59
|
+
title: string;
|
|
60
|
+
content: string | number;
|
|
61
|
+
length: number;
|
|
62
|
+
source: string;
|
|
63
|
+
summary?: string | object;
|
|
64
|
+
summary_success?: boolean;
|
|
65
|
+
data_type?: string;
|
|
66
|
+
image_url?: Record<string, string>;
|
|
67
|
+
citation?: string;
|
|
68
|
+
}
|
|
69
|
+
interface ContentsResponse {
|
|
70
|
+
success: boolean;
|
|
71
|
+
error?: string | null;
|
|
72
|
+
tx_id?: string;
|
|
73
|
+
urls_requested?: number;
|
|
74
|
+
urls_processed?: number;
|
|
75
|
+
urls_failed?: number;
|
|
76
|
+
results?: ContentResult[];
|
|
77
|
+
total_cost_dollars?: number;
|
|
78
|
+
total_characters?: number;
|
|
79
|
+
isProvisioning?: boolean;
|
|
80
|
+
}
|
|
44
81
|
|
|
45
82
|
declare class Valyu {
|
|
46
83
|
private baseUrl;
|
|
@@ -51,9 +88,35 @@ declare class Valyu {
|
|
|
51
88
|
*/
|
|
52
89
|
private validateDateFormat;
|
|
53
90
|
/**
|
|
54
|
-
* Search for information using the Valyu API
|
|
91
|
+
* Search for information using the Valyu DeepSearch API
|
|
92
|
+
* @param query - The search query string
|
|
93
|
+
* @param options - Search configuration options
|
|
94
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
95
|
+
* @param options.maxNumResults - Maximum number of results (1-20)
|
|
96
|
+
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
97
|
+
* @param options.isToolCall - Whether this is a tool call
|
|
98
|
+
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
99
|
+
* @param options.includedSources - List of specific sources to include
|
|
100
|
+
* @param options.excludeSources - List of URLs/domains to exclude from search results
|
|
101
|
+
* @param options.category - Category filter for search results
|
|
102
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
103
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
104
|
+
* @param options.countryCode - Country code filter for search results
|
|
105
|
+
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
106
|
+
* @returns Promise resolving to search results
|
|
55
107
|
*/
|
|
56
108
|
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
109
|
+
/**
|
|
110
|
+
* Extract content from URLs with optional AI processing
|
|
111
|
+
* @param urls - Array of URLs to process (max 10)
|
|
112
|
+
* @param options - Content extraction configuration options
|
|
113
|
+
* @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
|
|
114
|
+
* @param options.extractEffort - Extraction thoroughness: "normal" or "high"
|
|
115
|
+
* @param options.responseLength - Content length per URL
|
|
116
|
+
* @param options.maxPriceDollars - Maximum cost limit in USD
|
|
117
|
+
* @returns Promise resolving to content extraction results
|
|
118
|
+
*/
|
|
119
|
+
contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
|
|
57
120
|
}
|
|
58
121
|
|
|
59
|
-
export { type FeedbackResponse, type FeedbackSentiment, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
|
122
|
+
export { type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
type SearchType = "web" | "proprietary" | "all";
|
|
2
2
|
type FeedbackSentiment = "very good" | "good" | "bad" | "very bad";
|
|
3
3
|
type DataType = "structured" | "unstructured";
|
|
4
|
+
type CountryCode = "ALL" | "AR" | "AU" | "AT" | "BE" | "BR" | "CA" | "CL" | "DK" | "FI" | "FR" | "DE" | "HK" | "IN" | "ID" | "IT" | "JP" | "KR" | "MY" | "MX" | "NL" | "NZ" | "NO" | "CN" | "PL" | "PT" | "PH" | "RU" | "SA" | "ZA" | "ES" | "SE" | "CH" | "TW" | "TR" | "GB" | "US";
|
|
5
|
+
type ResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
4
6
|
interface SearchResult {
|
|
5
7
|
title: string;
|
|
6
8
|
url: string;
|
|
@@ -19,9 +21,12 @@ interface SearchOptions {
|
|
|
19
21
|
isToolCall?: boolean;
|
|
20
22
|
relevanceThreshold?: number;
|
|
21
23
|
includedSources?: string[];
|
|
24
|
+
excludeSources?: string[];
|
|
22
25
|
category?: string;
|
|
23
26
|
startDate?: string;
|
|
24
27
|
endDate?: string;
|
|
28
|
+
countryCode?: CountryCode;
|
|
29
|
+
responseLength?: ResponseLength;
|
|
25
30
|
}
|
|
26
31
|
interface SearchResponse {
|
|
27
32
|
success: boolean;
|
|
@@ -41,6 +46,38 @@ interface FeedbackResponse {
|
|
|
41
46
|
success: boolean;
|
|
42
47
|
error?: string;
|
|
43
48
|
}
|
|
49
|
+
type ExtractEffort = "normal" | "high";
|
|
50
|
+
type ContentResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
51
|
+
interface ContentsOptions {
|
|
52
|
+
summary?: boolean | string | object;
|
|
53
|
+
extractEffort?: ExtractEffort;
|
|
54
|
+
responseLength?: ContentResponseLength;
|
|
55
|
+
maxPriceDollars?: number;
|
|
56
|
+
}
|
|
57
|
+
interface ContentResult {
|
|
58
|
+
url: string;
|
|
59
|
+
title: string;
|
|
60
|
+
content: string | number;
|
|
61
|
+
length: number;
|
|
62
|
+
source: string;
|
|
63
|
+
summary?: string | object;
|
|
64
|
+
summary_success?: boolean;
|
|
65
|
+
data_type?: string;
|
|
66
|
+
image_url?: Record<string, string>;
|
|
67
|
+
citation?: string;
|
|
68
|
+
}
|
|
69
|
+
interface ContentsResponse {
|
|
70
|
+
success: boolean;
|
|
71
|
+
error?: string | null;
|
|
72
|
+
tx_id?: string;
|
|
73
|
+
urls_requested?: number;
|
|
74
|
+
urls_processed?: number;
|
|
75
|
+
urls_failed?: number;
|
|
76
|
+
results?: ContentResult[];
|
|
77
|
+
total_cost_dollars?: number;
|
|
78
|
+
total_characters?: number;
|
|
79
|
+
isProvisioning?: boolean;
|
|
80
|
+
}
|
|
44
81
|
|
|
45
82
|
declare class Valyu {
|
|
46
83
|
private baseUrl;
|
|
@@ -51,9 +88,35 @@ declare class Valyu {
|
|
|
51
88
|
*/
|
|
52
89
|
private validateDateFormat;
|
|
53
90
|
/**
|
|
54
|
-
* Search for information using the Valyu API
|
|
91
|
+
* Search for information using the Valyu DeepSearch API
|
|
92
|
+
* @param query - The search query string
|
|
93
|
+
* @param options - Search configuration options
|
|
94
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
95
|
+
* @param options.maxNumResults - Maximum number of results (1-20)
|
|
96
|
+
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
97
|
+
* @param options.isToolCall - Whether this is a tool call
|
|
98
|
+
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
99
|
+
* @param options.includedSources - List of specific sources to include
|
|
100
|
+
* @param options.excludeSources - List of URLs/domains to exclude from search results
|
|
101
|
+
* @param options.category - Category filter for search results
|
|
102
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
103
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
104
|
+
* @param options.countryCode - Country code filter for search results
|
|
105
|
+
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
106
|
+
* @returns Promise resolving to search results
|
|
55
107
|
*/
|
|
56
108
|
search(query: string, options?: SearchOptions): Promise<SearchResponse>;
|
|
109
|
+
/**
|
|
110
|
+
* Extract content from URLs with optional AI processing
|
|
111
|
+
* @param urls - Array of URLs to process (max 10)
|
|
112
|
+
* @param options - Content extraction configuration options
|
|
113
|
+
* @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
|
|
114
|
+
* @param options.extractEffort - Extraction thoroughness: "normal" or "high"
|
|
115
|
+
* @param options.responseLength - Content length per URL
|
|
116
|
+
* @param options.maxPriceDollars - Maximum cost limit in USD
|
|
117
|
+
* @returns Promise resolving to content extraction results
|
|
118
|
+
*/
|
|
119
|
+
contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
|
|
57
120
|
}
|
|
58
121
|
|
|
59
|
-
export { type FeedbackResponse, type FeedbackSentiment, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
|
122
|
+
export { type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
package/dist/index.js
CHANGED
|
@@ -60,7 +60,22 @@ var Valyu = class {
|
|
|
60
60
|
return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Search for information using the Valyu API
|
|
63
|
+
* Search for information using the Valyu DeepSearch API
|
|
64
|
+
* @param query - The search query string
|
|
65
|
+
* @param options - Search configuration options
|
|
66
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
67
|
+
* @param options.maxNumResults - Maximum number of results (1-20)
|
|
68
|
+
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
69
|
+
* @param options.isToolCall - Whether this is a tool call
|
|
70
|
+
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
71
|
+
* @param options.includedSources - List of specific sources to include
|
|
72
|
+
* @param options.excludeSources - List of URLs/domains to exclude from search results
|
|
73
|
+
* @param options.category - Category filter for search results
|
|
74
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
75
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
76
|
+
* @param options.countryCode - Country code filter for search results
|
|
77
|
+
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
78
|
+
* @returns Promise resolving to search results
|
|
64
79
|
*/
|
|
65
80
|
async search(query, options = {}) {
|
|
66
81
|
try {
|
|
@@ -137,6 +152,9 @@ var Valyu = class {
|
|
|
137
152
|
if (options.includedSources !== void 0) {
|
|
138
153
|
payload.included_sources = options.includedSources;
|
|
139
154
|
}
|
|
155
|
+
if (options.excludeSources !== void 0) {
|
|
156
|
+
payload.exclude_sources = options.excludeSources;
|
|
157
|
+
}
|
|
140
158
|
if (options.category !== void 0) {
|
|
141
159
|
payload.category = options.category;
|
|
142
160
|
}
|
|
@@ -146,6 +164,12 @@ var Valyu = class {
|
|
|
146
164
|
if (options.endDate !== void 0) {
|
|
147
165
|
payload.end_date = options.endDate;
|
|
148
166
|
}
|
|
167
|
+
if (options.countryCode !== void 0) {
|
|
168
|
+
payload.country_code = options.countryCode;
|
|
169
|
+
}
|
|
170
|
+
if (options.responseLength !== void 0) {
|
|
171
|
+
payload.response_length = options.responseLength;
|
|
172
|
+
}
|
|
149
173
|
const response = await import_axios.default.post(
|
|
150
174
|
`${this.baseUrl}/deepsearch`,
|
|
151
175
|
payload,
|
|
@@ -179,6 +203,139 @@ var Valyu = class {
|
|
|
179
203
|
};
|
|
180
204
|
}
|
|
181
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Extract content from URLs with optional AI processing
|
|
208
|
+
* @param urls - Array of URLs to process (max 10)
|
|
209
|
+
* @param options - Content extraction configuration options
|
|
210
|
+
* @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
|
|
211
|
+
* @param options.extractEffort - Extraction thoroughness: "normal" or "high"
|
|
212
|
+
* @param options.responseLength - Content length per URL
|
|
213
|
+
* @param options.maxPriceDollars - Maximum cost limit in USD
|
|
214
|
+
* @returns Promise resolving to content extraction results
|
|
215
|
+
*/
|
|
216
|
+
async contents(urls, options = {}) {
|
|
217
|
+
try {
|
|
218
|
+
if (!urls || !Array.isArray(urls)) {
|
|
219
|
+
return {
|
|
220
|
+
success: false,
|
|
221
|
+
error: "urls must be an array",
|
|
222
|
+
urls_requested: 0,
|
|
223
|
+
urls_processed: 0,
|
|
224
|
+
urls_failed: 0,
|
|
225
|
+
results: [],
|
|
226
|
+
total_cost_dollars: 0,
|
|
227
|
+
total_characters: 0
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
if (urls.length === 0) {
|
|
231
|
+
return {
|
|
232
|
+
success: false,
|
|
233
|
+
error: "urls array cannot be empty",
|
|
234
|
+
urls_requested: 0,
|
|
235
|
+
urls_processed: 0,
|
|
236
|
+
urls_failed: 0,
|
|
237
|
+
results: [],
|
|
238
|
+
total_cost_dollars: 0,
|
|
239
|
+
total_characters: 0
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (urls.length > 10) {
|
|
243
|
+
return {
|
|
244
|
+
success: false,
|
|
245
|
+
error: "Maximum 10 URLs allowed per request",
|
|
246
|
+
urls_requested: urls.length,
|
|
247
|
+
urls_processed: 0,
|
|
248
|
+
urls_failed: urls.length,
|
|
249
|
+
results: [],
|
|
250
|
+
total_cost_dollars: 0,
|
|
251
|
+
total_characters: 0
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
if (options.extractEffort && !["normal", "high"].includes(options.extractEffort)) {
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
error: "extractEffort must be 'normal' or 'high'",
|
|
258
|
+
urls_requested: urls.length,
|
|
259
|
+
urls_processed: 0,
|
|
260
|
+
urls_failed: urls.length,
|
|
261
|
+
results: [],
|
|
262
|
+
total_cost_dollars: 0,
|
|
263
|
+
total_characters: 0
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (options.responseLength !== void 0) {
|
|
267
|
+
const validLengths = ["short", "medium", "large", "max"];
|
|
268
|
+
if (typeof options.responseLength === "string" && !validLengths.includes(options.responseLength)) {
|
|
269
|
+
return {
|
|
270
|
+
success: false,
|
|
271
|
+
error: "responseLength must be 'short', 'medium', 'large', 'max', or a number",
|
|
272
|
+
urls_requested: urls.length,
|
|
273
|
+
urls_processed: 0,
|
|
274
|
+
urls_failed: urls.length,
|
|
275
|
+
results: [],
|
|
276
|
+
total_cost_dollars: 0,
|
|
277
|
+
total_characters: 0
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (typeof options.responseLength === "number" && options.responseLength <= 0) {
|
|
281
|
+
return {
|
|
282
|
+
success: false,
|
|
283
|
+
error: "responseLength number must be positive",
|
|
284
|
+
urls_requested: urls.length,
|
|
285
|
+
urls_processed: 0,
|
|
286
|
+
urls_failed: urls.length,
|
|
287
|
+
results: [],
|
|
288
|
+
total_cost_dollars: 0,
|
|
289
|
+
total_characters: 0
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const payload = {
|
|
294
|
+
urls
|
|
295
|
+
};
|
|
296
|
+
if (options.summary !== void 0) {
|
|
297
|
+
payload.summary = options.summary;
|
|
298
|
+
}
|
|
299
|
+
if (options.extractEffort !== void 0) {
|
|
300
|
+
payload.extract_effort = options.extractEffort;
|
|
301
|
+
}
|
|
302
|
+
if (options.responseLength !== void 0) {
|
|
303
|
+
payload.response_length = options.responseLength;
|
|
304
|
+
}
|
|
305
|
+
if (options.maxPriceDollars !== void 0) {
|
|
306
|
+
payload.max_price_dollars = options.maxPriceDollars;
|
|
307
|
+
}
|
|
308
|
+
const response = await import_axios.default.post(
|
|
309
|
+
`${this.baseUrl}/contents`,
|
|
310
|
+
payload,
|
|
311
|
+
{ headers: this.headers }
|
|
312
|
+
);
|
|
313
|
+
if (!response.status || response.status < 200 || response.status >= 300) {
|
|
314
|
+
return {
|
|
315
|
+
success: false,
|
|
316
|
+
error: response.data?.error || "Request failed",
|
|
317
|
+
urls_requested: urls.length,
|
|
318
|
+
urls_processed: 0,
|
|
319
|
+
urls_failed: urls.length,
|
|
320
|
+
results: [],
|
|
321
|
+
total_cost_dollars: 0,
|
|
322
|
+
total_characters: 0
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return response.data;
|
|
326
|
+
} catch (e) {
|
|
327
|
+
return {
|
|
328
|
+
success: false,
|
|
329
|
+
error: e.response?.data?.error || e.message,
|
|
330
|
+
urls_requested: urls.length,
|
|
331
|
+
urls_processed: 0,
|
|
332
|
+
urls_failed: urls.length,
|
|
333
|
+
results: [],
|
|
334
|
+
total_cost_dollars: 0,
|
|
335
|
+
total_characters: 0
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
182
339
|
};
|
|
183
340
|
// Annotate the CommonJS export names for ESM import in node:
|
|
184
341
|
0 && (module.exports = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, SearchOptions } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Search for information using the Valyu API v2\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values for v2 API\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (providedSearchTypeString === \"web\" || providedSearchTypeString === \"proprietary\" || providedSearchTypeString === \"all\") {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error: \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/deepsearch`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n}\n\nexport type { \n SearchResponse, \n SearchType, \n FeedbackSentiment, \n FeedbackResponse,\n SearchOptions\n} from './types'; "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,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WAAW,MAAM,aAAAA,QAAM;AAAA,QAC3B,GAAG,KAAK,OAAO;AAAA,QACf;AAAA,QACA,EAAE,SAAS,KAAK,QAAQ;AAAA,MAC1B;AAEA,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM;AAAA,UACtB,OAAO;AAAA,UACP;AAAA,UACA,SAAS,CAAC;AAAA,UACV,mBAAmB,EAAE,KAAK,GAAG,aAAa,EAAE;AAAA,UAC5C,qBAAqB;AAAA,UACrB,yBAAyB;AAAA,UACzB,kBAAkB;AAAA,QACpB;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,QACpC,OAAO;AAAA,QACP;AAAA,QACA,SAAS,CAAC;AAAA,QACV,mBAAmB,EAAE,KAAK,GAAG,aAAa,EAAE;AAAA,QAC5C,qBAAqB;AAAA,QACrB,yBAAyB;AAAA,QACzB,kBAAkB;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;","names":["axios"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, SearchOptions, ContentsOptions, ContentsResponse } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Search for information using the Valyu DeepSearch API\n * @param query - The search query string\n * @param options - Search configuration options\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.maxNumResults - Maximum number of results (1-20)\n * @param options.maxPrice - Maximum price per thousand characters (CPM)\n * @param options.isToolCall - Whether this is a tool call\n * @param options.relevanceThreshold - Minimum relevance score (0-1)\n * @param options.includedSources - List of specific sources to include\n * @param options.excludeSources - List of URLs/domains to exclude from search results\n * @param options.category - Category filter for search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.countryCode - Country code filter for search results\n * @param options.responseLength - Response content length: \"short\"/\"medium\"/\"large\"/\"max\" or integer character count\n * @returns Promise resolving to search results\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (providedSearchTypeString === \"web\" || providedSearchTypeString === \"proprietary\" || providedSearchTypeString === \"all\") {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error: \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludeSources !== undefined) {\n payload.exclude_sources = options.excludeSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/deepsearch`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n\n /**\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(urls: string[], options: ContentsOptions = {}): 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 (options.extractEffort && ![\"normal\", \"high\"].includes(options.extractEffort)) {\n return {\n success: false,\n error: \"extractEffort must be 'normal' or 'high'\",\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 (typeof options.responseLength === \"string\" && !validLengths.includes(options.responseLength)) {\n return {\n success: false,\n error: \"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 (typeof options.responseLength === \"number\" && options.responseLength <= 0) {\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(\n `${this.baseUrl}/contents`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error || \"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\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} from './types'; "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,YAAY,QAAiB,UAAkB,gCAAgC;AAC7E,QAAI,CAAC,QAAQ;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AAA,QAClB,SAAS,CAAC;AAAA,QACV,oBAAoB;AAAA,QACpB,kBAAkB;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;","names":["axios"]}
|
package/dist/index.mjs
CHANGED
|
@@ -26,7 +26,22 @@ var Valyu = class {
|
|
|
26
26
|
return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Search for information using the Valyu API
|
|
29
|
+
* Search for information using the Valyu DeepSearch API
|
|
30
|
+
* @param query - The search query string
|
|
31
|
+
* @param options - Search configuration options
|
|
32
|
+
* @param options.searchType - Type of search: "web", "proprietary", or "all"
|
|
33
|
+
* @param options.maxNumResults - Maximum number of results (1-20)
|
|
34
|
+
* @param options.maxPrice - Maximum price per thousand characters (CPM)
|
|
35
|
+
* @param options.isToolCall - Whether this is a tool call
|
|
36
|
+
* @param options.relevanceThreshold - Minimum relevance score (0-1)
|
|
37
|
+
* @param options.includedSources - List of specific sources to include
|
|
38
|
+
* @param options.excludeSources - List of URLs/domains to exclude from search results
|
|
39
|
+
* @param options.category - Category filter for search results
|
|
40
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
41
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
42
|
+
* @param options.countryCode - Country code filter for search results
|
|
43
|
+
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
44
|
+
* @returns Promise resolving to search results
|
|
30
45
|
*/
|
|
31
46
|
async search(query, options = {}) {
|
|
32
47
|
try {
|
|
@@ -103,6 +118,9 @@ var Valyu = class {
|
|
|
103
118
|
if (options.includedSources !== void 0) {
|
|
104
119
|
payload.included_sources = options.includedSources;
|
|
105
120
|
}
|
|
121
|
+
if (options.excludeSources !== void 0) {
|
|
122
|
+
payload.exclude_sources = options.excludeSources;
|
|
123
|
+
}
|
|
106
124
|
if (options.category !== void 0) {
|
|
107
125
|
payload.category = options.category;
|
|
108
126
|
}
|
|
@@ -112,6 +130,12 @@ var Valyu = class {
|
|
|
112
130
|
if (options.endDate !== void 0) {
|
|
113
131
|
payload.end_date = options.endDate;
|
|
114
132
|
}
|
|
133
|
+
if (options.countryCode !== void 0) {
|
|
134
|
+
payload.country_code = options.countryCode;
|
|
135
|
+
}
|
|
136
|
+
if (options.responseLength !== void 0) {
|
|
137
|
+
payload.response_length = options.responseLength;
|
|
138
|
+
}
|
|
115
139
|
const response = await axios.post(
|
|
116
140
|
`${this.baseUrl}/deepsearch`,
|
|
117
141
|
payload,
|
|
@@ -145,6 +169,139 @@ var Valyu = class {
|
|
|
145
169
|
};
|
|
146
170
|
}
|
|
147
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Extract content from URLs with optional AI processing
|
|
174
|
+
* @param urls - Array of URLs to process (max 10)
|
|
175
|
+
* @param options - Content extraction configuration options
|
|
176
|
+
* @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
|
|
177
|
+
* @param options.extractEffort - Extraction thoroughness: "normal" or "high"
|
|
178
|
+
* @param options.responseLength - Content length per URL
|
|
179
|
+
* @param options.maxPriceDollars - Maximum cost limit in USD
|
|
180
|
+
* @returns Promise resolving to content extraction results
|
|
181
|
+
*/
|
|
182
|
+
async contents(urls, options = {}) {
|
|
183
|
+
try {
|
|
184
|
+
if (!urls || !Array.isArray(urls)) {
|
|
185
|
+
return {
|
|
186
|
+
success: false,
|
|
187
|
+
error: "urls must be an array",
|
|
188
|
+
urls_requested: 0,
|
|
189
|
+
urls_processed: 0,
|
|
190
|
+
urls_failed: 0,
|
|
191
|
+
results: [],
|
|
192
|
+
total_cost_dollars: 0,
|
|
193
|
+
total_characters: 0
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (urls.length === 0) {
|
|
197
|
+
return {
|
|
198
|
+
success: false,
|
|
199
|
+
error: "urls array cannot be empty",
|
|
200
|
+
urls_requested: 0,
|
|
201
|
+
urls_processed: 0,
|
|
202
|
+
urls_failed: 0,
|
|
203
|
+
results: [],
|
|
204
|
+
total_cost_dollars: 0,
|
|
205
|
+
total_characters: 0
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (urls.length > 10) {
|
|
209
|
+
return {
|
|
210
|
+
success: false,
|
|
211
|
+
error: "Maximum 10 URLs allowed per request",
|
|
212
|
+
urls_requested: urls.length,
|
|
213
|
+
urls_processed: 0,
|
|
214
|
+
urls_failed: urls.length,
|
|
215
|
+
results: [],
|
|
216
|
+
total_cost_dollars: 0,
|
|
217
|
+
total_characters: 0
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (options.extractEffort && !["normal", "high"].includes(options.extractEffort)) {
|
|
221
|
+
return {
|
|
222
|
+
success: false,
|
|
223
|
+
error: "extractEffort must be 'normal' or 'high'",
|
|
224
|
+
urls_requested: urls.length,
|
|
225
|
+
urls_processed: 0,
|
|
226
|
+
urls_failed: urls.length,
|
|
227
|
+
results: [],
|
|
228
|
+
total_cost_dollars: 0,
|
|
229
|
+
total_characters: 0
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (options.responseLength !== void 0) {
|
|
233
|
+
const validLengths = ["short", "medium", "large", "max"];
|
|
234
|
+
if (typeof options.responseLength === "string" && !validLengths.includes(options.responseLength)) {
|
|
235
|
+
return {
|
|
236
|
+
success: false,
|
|
237
|
+
error: "responseLength must be 'short', 'medium', 'large', 'max', or a number",
|
|
238
|
+
urls_requested: urls.length,
|
|
239
|
+
urls_processed: 0,
|
|
240
|
+
urls_failed: urls.length,
|
|
241
|
+
results: [],
|
|
242
|
+
total_cost_dollars: 0,
|
|
243
|
+
total_characters: 0
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (typeof options.responseLength === "number" && options.responseLength <= 0) {
|
|
247
|
+
return {
|
|
248
|
+
success: false,
|
|
249
|
+
error: "responseLength number must be positive",
|
|
250
|
+
urls_requested: urls.length,
|
|
251
|
+
urls_processed: 0,
|
|
252
|
+
urls_failed: urls.length,
|
|
253
|
+
results: [],
|
|
254
|
+
total_cost_dollars: 0,
|
|
255
|
+
total_characters: 0
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const payload = {
|
|
260
|
+
urls
|
|
261
|
+
};
|
|
262
|
+
if (options.summary !== void 0) {
|
|
263
|
+
payload.summary = options.summary;
|
|
264
|
+
}
|
|
265
|
+
if (options.extractEffort !== void 0) {
|
|
266
|
+
payload.extract_effort = options.extractEffort;
|
|
267
|
+
}
|
|
268
|
+
if (options.responseLength !== void 0) {
|
|
269
|
+
payload.response_length = options.responseLength;
|
|
270
|
+
}
|
|
271
|
+
if (options.maxPriceDollars !== void 0) {
|
|
272
|
+
payload.max_price_dollars = options.maxPriceDollars;
|
|
273
|
+
}
|
|
274
|
+
const response = await axios.post(
|
|
275
|
+
`${this.baseUrl}/contents`,
|
|
276
|
+
payload,
|
|
277
|
+
{ headers: this.headers }
|
|
278
|
+
);
|
|
279
|
+
if (!response.status || response.status < 200 || response.status >= 300) {
|
|
280
|
+
return {
|
|
281
|
+
success: false,
|
|
282
|
+
error: response.data?.error || "Request failed",
|
|
283
|
+
urls_requested: urls.length,
|
|
284
|
+
urls_processed: 0,
|
|
285
|
+
urls_failed: urls.length,
|
|
286
|
+
results: [],
|
|
287
|
+
total_cost_dollars: 0,
|
|
288
|
+
total_characters: 0
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return response.data;
|
|
292
|
+
} catch (e) {
|
|
293
|
+
return {
|
|
294
|
+
success: false,
|
|
295
|
+
error: e.response?.data?.error || e.message,
|
|
296
|
+
urls_requested: urls.length,
|
|
297
|
+
urls_processed: 0,
|
|
298
|
+
urls_failed: urls.length,
|
|
299
|
+
results: [],
|
|
300
|
+
total_cost_dollars: 0,
|
|
301
|
+
total_characters: 0
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
148
305
|
};
|
|
149
306
|
export {
|
|
150
307
|
Valyu
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, SearchOptions } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Search for information using the Valyu API v2\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values for v2 API\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (providedSearchTypeString === \"web\" || providedSearchTypeString === \"proprietary\" || providedSearchTypeString === \"all\") {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error: \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/deepsearch`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n}\n\nexport type { \n SearchResponse, \n SearchType, \n FeedbackSentiment, \n FeedbackResponse,\n SearchOptions\n} from './types'; "],"mappings":";AAAA,OAAO,WAAW;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,YAAY,QAAiB,UAAkB,gCAAgC;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,mBAAmB,MAAuB;AAChD,UAAM,YAAY;AAClB,QAAI,CAAC,UAAU,KAAK,IAAI,GAAG;AACzB,aAAO;AAAA,IACT;AACA,UAAM,aAAa,IAAI,KAAK,IAAI;AAChC,WAAO,sBAAsB,QAAQ,CAAC,MAAM,WAAW,QAAQ,CAAC;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,OAAe,UAAyB,CAAC,GAA4B;AAChF,QAAI;AAEF,YAAM,oBAAgC;AACtC,YAAM,uBAAuB;AAC7B,YAAM,oBAAoB;AAC1B,YAAM,4BAA4B;AAClC,YAAM,kBAAkB;AAGxB,UAAI,kBAA8B;AAClC,YAAM,2BAA2B,QAAQ,YAAY,YAAY;AAEjE,UAAI,6BAA6B,SAAS,6BAA6B,iBAAiB,6BAA6B,OAAO;AAC1H,0BAAkB;AAAA,MACpB,WAAW,QAAQ,eAAe,QAAW;AAC3C,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO;AAAA,UACP,OAAO;AAAA,UACP;AAAA,UACA,SAAS,CAAC;AAAA,UACV,mBAAmB,EAAE,KAAK,GAAG,aAAa,EAAE;AAAA,UAC5C,qBAAqB;AAAA,UACrB,yBAAyB;AAAA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gBAAQ,WAAW,QAAQ;AAAA,MAC7B;AAEA,UAAI,QAAQ,cAAc,QAAW;AACnC,gBAAQ,aAAa,QAAQ;AAAA,MAC/B;AAEA,UAAI,QAAQ,YAAY,QAAW;AACjC,gBAAQ,WAAW,QAAQ;AAAA,MAC7B;AAEA,YAAM,WAAW,MAAM,MAAM;AAAA,QAC3B,GAAG,KAAK,OAAO;AAAA,QACf;AAAA,QACA,EAAE,SAAS,KAAK,QAAQ;AAAA,MAC1B;AAEA,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM;AAAA,UACtB,OAAO;AAAA,UACP;AAAA,UACA,SAAS,CAAC;AAAA,UACV,mBAAmB,EAAE,KAAK,GAAG,aAAa,EAAE;AAAA,UAC5C,qBAAqB;AAAA,UACrB,yBAAyB;AAAA,UACzB,kBAAkB;AAAA,QACpB;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,QACpC,OAAO;AAAA,QACP;AAAA,QACA,SAAS,CAAC;AAAA,QACV,mBAAmB,EAAE,KAAK,GAAG,aAAa,EAAE;AAAA,QAC5C,qBAAqB;AAAA,QACrB,yBAAyB;AAAA,QACzB,kBAAkB;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, SearchOptions, ContentsOptions, ContentsResponse } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Search for information using the Valyu DeepSearch API\n * @param query - The search query string\n * @param options - Search configuration options\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.maxNumResults - Maximum number of results (1-20)\n * @param options.maxPrice - Maximum price per thousand characters (CPM)\n * @param options.isToolCall - Whether this is a tool call\n * @param options.relevanceThreshold - Minimum relevance score (0-1)\n * @param options.includedSources - List of specific sources to include\n * @param options.excludeSources - List of URLs/domains to exclude from search results\n * @param options.category - Category filter for search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.countryCode - Country code filter for search results\n * @param options.responseLength - Response content length: \"short\"/\"medium\"/\"large\"/\"max\" or integer character count\n * @returns Promise resolving to search results\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (providedSearchTypeString === \"web\" || providedSearchTypeString === \"proprietary\" || providedSearchTypeString === \"all\") {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error: \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludeSources !== undefined) {\n payload.exclude_sources = options.excludeSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/deepsearch`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n\n /**\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(urls: string[], options: ContentsOptions = {}): 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 (options.extractEffort && ![\"normal\", \"high\"].includes(options.extractEffort)) {\n return {\n success: false,\n error: \"extractEffort must be 'normal' or 'high'\",\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 (typeof options.responseLength === \"string\" && !validLengths.includes(options.responseLength)) {\n return {\n success: false,\n error: \"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 (typeof options.responseLength === \"number\" && options.responseLength <= 0) {\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(\n `${this.baseUrl}/contents`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error || \"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\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} from './types'; "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O,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,QACpC,gBAAgB,KAAK;AAAA,QACrB,gBAAgB;AAAA,QAChB,aAAa,KAAK;AAAA,QAClB,SAAS,CAAC;AAAA,QACV,oBAAoB;AAAA,QACpB,kBAAkB;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valyu-js",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "DeepSearch
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Search for AIs - DeepSearch and Content API.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
@@ -31,7 +31,10 @@
|
|
|
31
31
|
"ai",
|
|
32
32
|
"sdk",
|
|
33
33
|
"rag",
|
|
34
|
-
"valyu"
|
|
34
|
+
"valyu",
|
|
35
|
+
"search",
|
|
36
|
+
"content-extraction",
|
|
37
|
+
"deepsearch"
|
|
35
38
|
],
|
|
36
39
|
"author": "Valyu",
|
|
37
40
|
"license": "MIT",
|