valyu-js 2.1.7 → 2.2.1
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 +110 -0
- package/dist/index.d.mts +264 -7
- package/dist/index.d.ts +264 -7
- package/dist/index.js +474 -132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +474 -132
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ type ResponseLength = "short" | "medium" | "large" | "max" | number;
|
|
|
6
6
|
interface SearchResult {
|
|
7
7
|
title: string;
|
|
8
8
|
url: string;
|
|
9
|
-
content: string;
|
|
9
|
+
content: string | object | any[];
|
|
10
10
|
description?: string;
|
|
11
11
|
source: string;
|
|
12
|
-
|
|
12
|
+
source_type?: string;
|
|
13
|
+
data_type?: DataType;
|
|
14
|
+
date?: string;
|
|
13
15
|
length: number;
|
|
14
16
|
relevance_score?: number;
|
|
15
|
-
data_type?: DataType;
|
|
16
|
-
source_type?: string;
|
|
17
17
|
publication_date?: string;
|
|
18
18
|
id?: string;
|
|
19
19
|
image_url?: Record<string, string>;
|
|
@@ -95,6 +95,7 @@ interface AnswerOptions {
|
|
|
95
95
|
startDate?: string;
|
|
96
96
|
endDate?: string;
|
|
97
97
|
fastMode?: boolean;
|
|
98
|
+
streaming?: boolean;
|
|
98
99
|
}
|
|
99
100
|
interface SearchMetadata {
|
|
100
101
|
tx_ids: string[];
|
|
@@ -109,6 +110,7 @@ interface Cost {
|
|
|
109
110
|
total_deduction_dollars: number;
|
|
110
111
|
search_deduction_dollars: number;
|
|
111
112
|
ai_deduction_dollars: number;
|
|
113
|
+
contents_deduction_dollars?: number;
|
|
112
114
|
}
|
|
113
115
|
interface AnswerSuccessResponse {
|
|
114
116
|
success: true;
|
|
@@ -126,10 +128,208 @@ interface AnswerErrorResponse {
|
|
|
126
128
|
error: string;
|
|
127
129
|
}
|
|
128
130
|
type AnswerResponse = AnswerSuccessResponse | AnswerErrorResponse;
|
|
131
|
+
type AnswerStreamChunkType = "search_results" | "content" | "metadata" | "done" | "error";
|
|
132
|
+
interface AnswerStreamChunk {
|
|
133
|
+
type: AnswerStreamChunkType;
|
|
134
|
+
search_results?: SearchResult[];
|
|
135
|
+
content?: string;
|
|
136
|
+
finish_reason?: string;
|
|
137
|
+
ai_tx_id?: string;
|
|
138
|
+
original_query?: string;
|
|
139
|
+
data_type?: "structured" | "unstructured";
|
|
140
|
+
search_metadata?: SearchMetadata;
|
|
141
|
+
ai_usage?: AIUsage;
|
|
142
|
+
cost?: Cost;
|
|
143
|
+
error?: string;
|
|
144
|
+
}
|
|
145
|
+
type DeepResearchMode = "lite" | "heavy";
|
|
146
|
+
type DeepResearchStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
|
|
147
|
+
type DeepResearchOutputFormat = "markdown" | "pdf" | Record<string, any>;
|
|
148
|
+
type DeepResearchOutputType = "markdown" | "json";
|
|
149
|
+
type ImageType = "chart" | "ai_generated";
|
|
150
|
+
type ChartType = "line" | "bar" | "area";
|
|
151
|
+
interface FileAttachment {
|
|
152
|
+
data: string;
|
|
153
|
+
filename: string;
|
|
154
|
+
mediaType: string;
|
|
155
|
+
context?: string;
|
|
156
|
+
}
|
|
157
|
+
interface MCPServerConfig {
|
|
158
|
+
url: string;
|
|
159
|
+
name?: string;
|
|
160
|
+
toolPrefix?: string;
|
|
161
|
+
auth?: {
|
|
162
|
+
type: "bearer" | "header" | "none";
|
|
163
|
+
token?: string;
|
|
164
|
+
headers?: Record<string, string>;
|
|
165
|
+
};
|
|
166
|
+
allowedTools?: string[];
|
|
167
|
+
}
|
|
168
|
+
interface DeepResearchSearchConfig {
|
|
169
|
+
searchType?: "all" | "web" | "proprietary";
|
|
170
|
+
includedSources?: string[];
|
|
171
|
+
}
|
|
172
|
+
interface DeepResearchCreateOptions {
|
|
173
|
+
input: string;
|
|
174
|
+
model?: DeepResearchMode;
|
|
175
|
+
outputFormats?: DeepResearchOutputFormat[];
|
|
176
|
+
strategy?: string;
|
|
177
|
+
search?: DeepResearchSearchConfig;
|
|
178
|
+
urls?: string[];
|
|
179
|
+
files?: FileAttachment[];
|
|
180
|
+
mcpServers?: MCPServerConfig[];
|
|
181
|
+
codeExecution?: boolean;
|
|
182
|
+
previousReports?: string[];
|
|
183
|
+
webhookUrl?: string;
|
|
184
|
+
metadata?: Record<string, string | number | boolean>;
|
|
185
|
+
}
|
|
186
|
+
interface Progress {
|
|
187
|
+
current_step: number;
|
|
188
|
+
total_steps: number;
|
|
189
|
+
}
|
|
190
|
+
interface ChartDataPoint {
|
|
191
|
+
x: string | number;
|
|
192
|
+
y: number;
|
|
193
|
+
}
|
|
194
|
+
interface ChartDataSeries {
|
|
195
|
+
name: string;
|
|
196
|
+
data: ChartDataPoint[];
|
|
197
|
+
}
|
|
198
|
+
interface ImageMetadata {
|
|
199
|
+
image_id: string;
|
|
200
|
+
image_type: ImageType;
|
|
201
|
+
deepresearch_id: string;
|
|
202
|
+
title: string;
|
|
203
|
+
description?: string;
|
|
204
|
+
image_url: string;
|
|
205
|
+
s3_key: string;
|
|
206
|
+
created_at: number;
|
|
207
|
+
chart_type?: ChartType;
|
|
208
|
+
x_axis_label?: string;
|
|
209
|
+
y_axis_label?: string;
|
|
210
|
+
data_series?: ChartDataSeries[];
|
|
211
|
+
}
|
|
212
|
+
interface DeepResearchSource {
|
|
213
|
+
title: string;
|
|
214
|
+
url: string;
|
|
215
|
+
snippet?: string;
|
|
216
|
+
description?: string;
|
|
217
|
+
source?: string;
|
|
218
|
+
org_id?: string;
|
|
219
|
+
price?: number;
|
|
220
|
+
id?: string;
|
|
221
|
+
doc_id?: number;
|
|
222
|
+
doi?: string;
|
|
223
|
+
category?: string;
|
|
224
|
+
source_id?: number;
|
|
225
|
+
word_count?: number;
|
|
226
|
+
}
|
|
227
|
+
interface DeepResearchUsage {
|
|
228
|
+
search_cost: number;
|
|
229
|
+
contents_cost: number;
|
|
230
|
+
ai_cost: number;
|
|
231
|
+
compute_cost: number;
|
|
232
|
+
total_cost: number;
|
|
233
|
+
}
|
|
234
|
+
interface DeepResearchCreateResponse {
|
|
235
|
+
success: boolean;
|
|
236
|
+
deepresearch_id?: string;
|
|
237
|
+
status?: DeepResearchStatus;
|
|
238
|
+
model?: DeepResearchMode;
|
|
239
|
+
created_at?: string;
|
|
240
|
+
metadata?: Record<string, string | number | boolean>;
|
|
241
|
+
public?: boolean;
|
|
242
|
+
webhook_secret?: string;
|
|
243
|
+
message?: string;
|
|
244
|
+
error?: string;
|
|
245
|
+
}
|
|
246
|
+
interface DeepResearchStatusResponse {
|
|
247
|
+
success: boolean;
|
|
248
|
+
deepresearch_id?: string;
|
|
249
|
+
status?: DeepResearchStatus;
|
|
250
|
+
query?: string;
|
|
251
|
+
mode?: DeepResearchMode;
|
|
252
|
+
output_formats?: DeepResearchOutputFormat[];
|
|
253
|
+
created_at?: number;
|
|
254
|
+
public?: boolean;
|
|
255
|
+
progress?: Progress;
|
|
256
|
+
messages?: any[];
|
|
257
|
+
completed_at?: number;
|
|
258
|
+
output?: string | Record<string, any>;
|
|
259
|
+
output_type?: DeepResearchOutputType;
|
|
260
|
+
pdf_url?: string;
|
|
261
|
+
images?: ImageMetadata[];
|
|
262
|
+
sources?: DeepResearchSource[];
|
|
263
|
+
usage?: DeepResearchUsage;
|
|
264
|
+
error?: string;
|
|
265
|
+
}
|
|
266
|
+
interface DeepResearchTaskListItem {
|
|
267
|
+
deepresearch_id: string;
|
|
268
|
+
query: string;
|
|
269
|
+
status: DeepResearchStatus;
|
|
270
|
+
created_at: number;
|
|
271
|
+
public?: boolean;
|
|
272
|
+
}
|
|
273
|
+
interface DeepResearchListResponse {
|
|
274
|
+
success: boolean;
|
|
275
|
+
data?: DeepResearchTaskListItem[];
|
|
276
|
+
error?: string;
|
|
277
|
+
}
|
|
278
|
+
interface DeepResearchUpdateResponse {
|
|
279
|
+
success: boolean;
|
|
280
|
+
message?: string;
|
|
281
|
+
deepresearch_id?: string;
|
|
282
|
+
error?: string;
|
|
283
|
+
}
|
|
284
|
+
interface DeepResearchCancelResponse {
|
|
285
|
+
success: boolean;
|
|
286
|
+
message?: string;
|
|
287
|
+
deepresearch_id?: string;
|
|
288
|
+
error?: string;
|
|
289
|
+
}
|
|
290
|
+
interface DeepResearchDeleteResponse {
|
|
291
|
+
success: boolean;
|
|
292
|
+
message?: string;
|
|
293
|
+
deepresearch_id?: string;
|
|
294
|
+
error?: string;
|
|
295
|
+
}
|
|
296
|
+
interface DeepResearchTogglePublicResponse {
|
|
297
|
+
success: boolean;
|
|
298
|
+
message?: string;
|
|
299
|
+
deepresearch_id?: string;
|
|
300
|
+
public?: boolean;
|
|
301
|
+
error?: string;
|
|
302
|
+
}
|
|
303
|
+
interface WaitOptions {
|
|
304
|
+
pollInterval?: number;
|
|
305
|
+
maxWaitTime?: number;
|
|
306
|
+
onProgress?: (status: DeepResearchStatusResponse) => void;
|
|
307
|
+
}
|
|
308
|
+
interface StreamCallback {
|
|
309
|
+
onMessage?: (message: any) => void;
|
|
310
|
+
onProgress?: (current: number, total: number) => void;
|
|
311
|
+
onComplete?: (result: DeepResearchStatusResponse) => void;
|
|
312
|
+
onError?: (error: Error) => void;
|
|
313
|
+
}
|
|
314
|
+
interface ListOptions {
|
|
315
|
+
apiKeyId: string;
|
|
316
|
+
limit?: number;
|
|
317
|
+
}
|
|
129
318
|
|
|
130
319
|
declare class Valyu {
|
|
131
320
|
private baseUrl;
|
|
132
321
|
private headers;
|
|
322
|
+
deepresearch: {
|
|
323
|
+
create: (options: DeepResearchCreateOptions) => Promise<DeepResearchCreateResponse>;
|
|
324
|
+
status: (taskId: string) => Promise<DeepResearchStatusResponse>;
|
|
325
|
+
wait: (taskId: string, options?: WaitOptions) => Promise<DeepResearchStatusResponse>;
|
|
326
|
+
stream: (taskId: string, callback: StreamCallback) => Promise<void>;
|
|
327
|
+
list: (options: ListOptions) => Promise<DeepResearchListResponse>;
|
|
328
|
+
update: (taskId: string, instruction: string) => Promise<DeepResearchUpdateResponse>;
|
|
329
|
+
cancel: (taskId: string) => Promise<DeepResearchCancelResponse>;
|
|
330
|
+
delete: (taskId: string) => Promise<DeepResearchDeleteResponse>;
|
|
331
|
+
togglePublic: (taskId: string, isPublic: boolean) => Promise<DeepResearchTogglePublicResponse>;
|
|
332
|
+
};
|
|
133
333
|
constructor(apiKey?: string, baseUrl?: string);
|
|
134
334
|
/**
|
|
135
335
|
* Validates date format (YYYY-MM-DD)
|
|
@@ -187,6 +387,42 @@ declare class Valyu {
|
|
|
187
387
|
* @returns Promise resolving to content extraction results
|
|
188
388
|
*/
|
|
189
389
|
contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
|
|
390
|
+
/**
|
|
391
|
+
* DeepResearch: Create a new research task
|
|
392
|
+
*/
|
|
393
|
+
private _deepresearchCreate;
|
|
394
|
+
/**
|
|
395
|
+
* DeepResearch: Get task status
|
|
396
|
+
*/
|
|
397
|
+
private _deepresearchStatus;
|
|
398
|
+
/**
|
|
399
|
+
* DeepResearch: Wait for task completion with polling
|
|
400
|
+
*/
|
|
401
|
+
private _deepresearchWait;
|
|
402
|
+
/**
|
|
403
|
+
* DeepResearch: Stream real-time updates
|
|
404
|
+
*/
|
|
405
|
+
private _deepresearchStream;
|
|
406
|
+
/**
|
|
407
|
+
* DeepResearch: List all tasks
|
|
408
|
+
*/
|
|
409
|
+
private _deepresearchList;
|
|
410
|
+
/**
|
|
411
|
+
* DeepResearch: Add follow-up instruction
|
|
412
|
+
*/
|
|
413
|
+
private _deepresearchUpdate;
|
|
414
|
+
/**
|
|
415
|
+
* DeepResearch: Cancel task
|
|
416
|
+
*/
|
|
417
|
+
private _deepresearchCancel;
|
|
418
|
+
/**
|
|
419
|
+
* DeepResearch: Delete task
|
|
420
|
+
*/
|
|
421
|
+
private _deepresearchDelete;
|
|
422
|
+
/**
|
|
423
|
+
* DeepResearch: Toggle public flag
|
|
424
|
+
*/
|
|
425
|
+
private _deepresearchTogglePublic;
|
|
190
426
|
/**
|
|
191
427
|
* Get AI-powered answers using the Valyu Answer API
|
|
192
428
|
* @param query - The question or query string
|
|
@@ -201,9 +437,30 @@ declare class Valyu {
|
|
|
201
437
|
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
202
438
|
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
203
439
|
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
204
|
-
* @
|
|
440
|
+
* @param options.streaming - Enable streaming mode (default: false)
|
|
441
|
+
* @returns Promise resolving to answer response, or AsyncGenerator for streaming
|
|
442
|
+
*/
|
|
443
|
+
answer(query: string, options?: AnswerOptions): Promise<AnswerResponse | AsyncGenerator<AnswerStreamChunk, void, unknown>>;
|
|
444
|
+
/**
|
|
445
|
+
* Validate answer parameters
|
|
446
|
+
*/
|
|
447
|
+
private validateAnswerParams;
|
|
448
|
+
/**
|
|
449
|
+
* Build payload for answer API
|
|
450
|
+
*/
|
|
451
|
+
private buildAnswerPayload;
|
|
452
|
+
/**
|
|
453
|
+
* Fetch answer (non-streaming mode)
|
|
454
|
+
*/
|
|
455
|
+
private fetchAnswer;
|
|
456
|
+
/**
|
|
457
|
+
* Stream answer using SSE
|
|
458
|
+
*/
|
|
459
|
+
private streamAnswer;
|
|
460
|
+
/**
|
|
461
|
+
* Create an error generator for streaming errors
|
|
205
462
|
*/
|
|
206
|
-
|
|
463
|
+
private createErrorGenerator;
|
|
207
464
|
}
|
|
208
465
|
|
|
209
|
-
export { type AIUsage, type AnswerErrorResponse, type AnswerOptions, type AnswerResponse, type AnswerSuccessResponse, type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type Cost, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchMetadata, type SearchOptions, type SearchResponse, type SearchType, Valyu };
|
|
466
|
+
export { type AIUsage, type AnswerErrorResponse, type AnswerOptions, type AnswerResponse, type AnswerStreamChunk, type AnswerStreamChunkType, type AnswerSuccessResponse, type ChartDataPoint, type ChartDataSeries, type ChartType, type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type Cost, type CountryCode, type DeepResearchCancelResponse, type DeepResearchCreateOptions, type DeepResearchCreateResponse, type DeepResearchDeleteResponse, type DeepResearchListResponse, type DeepResearchMode, type DeepResearchOutputFormat, type DeepResearchSearchConfig, type DeepResearchSource, type DeepResearchStatus, type DeepResearchStatusResponse, type DeepResearchTaskListItem, type DeepResearchTogglePublicResponse, type DeepResearchUpdateResponse, type DeepResearchUsage, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type FileAttachment, type ImageMetadata, type ImageType, type ListOptions, type MCPServerConfig, type Progress, type ResponseLength, type SearchMetadata, type SearchOptions, type SearchResponse, type SearchResult, type SearchType, type StreamCallback, Valyu, type WaitOptions };
|