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 CHANGED
@@ -50,6 +50,116 @@ console.log(response);
50
50
 
51
51
  ## API Reference
52
52
 
53
+ ### DeepResearch Method
54
+
55
+ The `deepresearch` namespace provides access to Valyu's AI-powered research agent that conducts comprehensive, multi-step research with citations and cost tracking.
56
+
57
+ ```javascript
58
+ // Create a research task
59
+ const task = await valyu.deepresearch.create({
60
+ input: "What are the latest developments in quantum computing?",
61
+ model: "lite", // "lite" (fast, Haiku) or "heavy" (thorough, Sonnet)
62
+ outputFormats: ["markdown", "pdf"] // Output formats
63
+ });
64
+
65
+ // Wait for completion with progress updates
66
+ const result = await valyu.deepresearch.wait(task.deepresearch_id, {
67
+ onProgress: (status) => {
68
+ if (status.progress) {
69
+ console.log(`Step ${status.progress.current_step}/${status.progress.total_steps}`);
70
+ }
71
+ }
72
+ });
73
+
74
+ console.log(result.output); // Markdown report
75
+ console.log(result.pdf_url); // PDF download URL
76
+ ```
77
+
78
+ #### DeepResearch Methods
79
+
80
+ | Method | Description |
81
+ |--------|-------------|
82
+ | `create(options)` | Create a new research task |
83
+ | `status(taskId)` | Get current status of a task |
84
+ | `wait(taskId, options?)` | Wait for task completion with polling |
85
+ | `stream(taskId, callbacks)` | Stream real-time updates |
86
+ | `list(options)` | List all your research tasks |
87
+ | `update(taskId, instruction)` | Add follow-up instruction to running task |
88
+ | `cancel(taskId)` | Cancel a running task |
89
+ | `delete(taskId)` | Delete a task |
90
+ | `togglePublic(taskId, isPublic)` | Make task publicly accessible |
91
+
92
+ #### DeepResearch Create Options
93
+
94
+ | Parameter | Type | Default | Description |
95
+ |-----------|------|---------|-------------|
96
+ | `input` | `string` | *required* | Research query or task description |
97
+ | `model` | `"lite" \| "heavy"` | `"lite"` | Research model - lite (fast) or heavy (thorough) |
98
+ | `outputFormats` | `("markdown" \| "pdf")[]` | `["markdown"]` | Output formats for the report |
99
+ | `strategy` | `string` | - | Natural language research strategy |
100
+ | `search` | `object` | - | Search configuration (type, sources) |
101
+ | `urls` | `string[]` | - | URLs to extract and analyze |
102
+ | `files` | `FileAttachment[]` | - | PDF/image files to analyze |
103
+ | `mcpServers` | `MCPServerConfig[]` | - | MCP tool server configurations |
104
+ | `codeExecution` | `boolean` | `true` | Enable/disable code execution |
105
+ | `previousReports` | `string[]` | - | Previous report IDs for context (max 3) |
106
+ | `webhookUrl` | `string` | - | HTTPS webhook URL for completion notification |
107
+ | `metadata` | `Record<string, any>` | - | Custom metadata key-value pairs |
108
+
109
+ #### DeepResearch Examples
110
+
111
+ **Basic Research:**
112
+ ```javascript
113
+ const task = await valyu.deepresearch.create({
114
+ input: "Summarize recent AI safety research",
115
+ model: "lite"
116
+ });
117
+
118
+ const result = await valyu.deepresearch.wait(task.deepresearch_id);
119
+ console.log(result.output);
120
+ ```
121
+
122
+ **With Custom Sources:**
123
+ ```javascript
124
+ const task = await valyu.deepresearch.create({
125
+ input: "Latest transformer architecture improvements",
126
+ search: {
127
+ searchType: "proprietary",
128
+ includedSources: ["valyu/valyu-arxiv"]
129
+ },
130
+ model: "heavy",
131
+ outputFormats: ["markdown", "pdf"]
132
+ });
133
+ ```
134
+
135
+ **Streaming Updates:**
136
+ ```javascript
137
+ await valyu.deepresearch.stream(task.deepresearch_id, {
138
+ onProgress: (current, total) => {
139
+ console.log(`Progress: ${current}/${total}`);
140
+ },
141
+ onMessage: (message) => {
142
+ console.log("Agent:", message);
143
+ },
144
+ onComplete: (result) => {
145
+ console.log("Complete! Cost:", result.usage.total_cost);
146
+ }
147
+ });
148
+ ```
149
+
150
+ **With File Analysis:**
151
+ ```javascript
152
+ const task = await valyu.deepresearch.create({
153
+ input: "Analyze these research papers and provide key insights",
154
+ files: [{
155
+ data: "data:application/pdf;base64,...",
156
+ filename: "paper.pdf",
157
+ mediaType: "application/pdf"
158
+ }],
159
+ urls: ["https://arxiv.org/abs/2103.14030"]
160
+ });
161
+ ```
162
+
53
163
  ### Search Method
54
164
 
55
165
  The `search()` method is the core of the Valyu SDK. It accepts a query string as the first parameter, followed by optional configuration parameters.
package/dist/index.d.mts 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
- price: number;
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
- * @returns Promise resolving to answer response
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
- answer(query: string, options?: AnswerOptions): Promise<AnswerResponse>;
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 };