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