exa-js 1.7.2 → 1.7.3

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
@@ -190,7 +190,7 @@ Each chunk contains:
190
190
  - `content`: A string containing the next piece of generated text
191
191
  - `citations`: An array of citation objects containing source information
192
192
 
193
- ### `exa.research.createTask(input: object, options?: { schema?: object }): Promise<ResearchTaskResponse>`
193
+ ### `exa.research.createTask(input: object, options?: { schema?: object }): Promise<{id: string}>`
194
194
 
195
195
  Exa's research agent can autonomously gather information and return a structured JSON object that conforms to a schema you provide.
196
196
 
@@ -207,12 +207,13 @@ const schema = {
207
207
  },
208
208
  };
209
209
 
210
- const response = await exa.research.createTask(
210
+ const { id: taskId } = await exa.research.createTask(
211
211
  {
212
212
  instructions: "In ≤3 sentences, explain quantum computing.",
213
213
  },
214
214
  { schema }
215
215
  );
216
+ const result = await exa.research.pollTask(taskId);
216
217
  ```
217
218
 
218
219
  Use the `status` field to poll long-running tasks if needed (a future `getTask` helper will be added when the async API is released).
package/dist/index.d.mts CHANGED
@@ -1340,33 +1340,6 @@ declare class WebsetsClient extends WebsetsBaseClient {
1340
1340
  } | number): Promise<Webset>;
1341
1341
  }
1342
1342
 
1343
- /**
1344
- * Enum representing the status of a research task.
1345
- */
1346
- declare enum ResearchStatus {
1347
- /** The research request has finished successfully. */
1348
- completed = "completed",
1349
- /** The research request failed. */
1350
- failed = "failed"
1351
- }
1352
- /**
1353
- * Response object returned from the research API.
1354
- */
1355
- type ResearchTaskResponse = {
1356
- /** Unique identifier for the task. */
1357
- id: string;
1358
- /** Current status (may include future enum values served by the API). */
1359
- status: ResearchStatus | string;
1360
- /** Structured output that follows the user-provided schema (null while running). */
1361
- output: Record<string, any> | null;
1362
- /**
1363
- * Citations collected while deriving each top-level field in `output`.
1364
- * The key is the field name, the value is the list of `SearchResult`s that
1365
- * were used to compute that field.
1366
- */
1367
- citations: Record<string, SearchResult<{}>[]>;
1368
- };
1369
-
1370
1343
  type QueryParams = Record<string, string | number | boolean | string[] | undefined>;
1371
1344
  interface RequestBody {
1372
1345
  [key: string]: unknown;
@@ -1398,7 +1371,7 @@ declare class ResearchBaseClient {
1398
1371
  declare class ResearchClient extends ResearchBaseClient {
1399
1372
  constructor(client: Exa);
1400
1373
  /**
1401
- * Create and run a research task (blocking call).
1374
+ * Create a research task.
1402
1375
  *
1403
1376
  * Both parameters are required and have fixed shapes:
1404
1377
  * 1. `input`
@@ -1417,15 +1390,52 @@ declare class ResearchClient extends ResearchBaseClient {
1417
1390
  instructions: string;
1418
1391
  }, output: {
1419
1392
  schema: JSONSchema;
1420
- }): Promise<ResearchTaskResponse>;
1393
+ }): Promise<{
1394
+ id: string;
1395
+ }>;
1421
1396
  /**
1422
1397
  * Retrieve a research task by ID.
1423
- *
1424
- * Not yet implemented server-side. Calling this will throw until the API is
1425
- * available.
1426
1398
  */
1427
- getTask(): Promise<ResearchTaskResponse>;
1399
+ getTask(id: string): Promise<ResearchTask>;
1400
+ /**
1401
+ * Poll a research task until completion or failure.
1402
+ * Polls every 1 second with a maximum timeout of 10 minutes.
1403
+ */
1404
+ pollTask(id: string): Promise<ResearchTask>;
1405
+ }
1406
+
1407
+ /**
1408
+ * Enum representing the status of a research task.
1409
+ */
1410
+ declare enum ResearchStatus {
1411
+ /** The research task is still in progress. */
1412
+ in_progress = "in_progress",
1413
+ /** The research request has finished successfully. */
1414
+ completed = "completed",
1415
+ /** The research task request failed. */
1416
+ failed = "failed"
1428
1417
  }
1418
+ /**
1419
+ * Response object returned from the research API.
1420
+ */
1421
+ type ResearchTask = {
1422
+ /** Unique identifier for the task. */
1423
+ id: string;
1424
+ /** Current status. */
1425
+ status: ResearchStatus;
1426
+ /** The original instructions provided along with the task. */
1427
+ instructions: string;
1428
+ /** The original schema defining the task */
1429
+ schema: Record<string, any>;
1430
+ /** Structured output that follows the user-provided schema (null while running or if failed). */
1431
+ data: Record<string, any> | null;
1432
+ /**
1433
+ * Citations collected while deriving each top-level field in `output`.
1434
+ * The key is the field name, the value is the list of `SearchResult`s that
1435
+ * were used to compute that field.
1436
+ */
1437
+ citations: Record<string, SearchResult<{}>[]>;
1438
+ };
1429
1439
 
1430
1440
  /**
1431
1441
  * HTTP status codes
@@ -1904,4 +1914,4 @@ declare class Exa {
1904
1914
  private parseSSEStream;
1905
1915
  }
1906
1916
 
1907
- export { type AnswerOptions, type AnswerResponse, type AnswerStreamChunk, type AnswerStreamResponse, type BaseSearchOptions, type ContentsOptions, type ContentsResultComponent, type CostDollars, type CostDollarsContents, type CostDollarsSeearch, type CreateEnrichmentParameters, CreateEnrichmentParametersFormat, type CreateWebhookParameters, type CreateWebsetParameters, type CreateWebsetSearchParameters, CreateWebsetSearchParametersBehaviour, type Default, type EnrichmentResult, type Event, EventType, Exa, ExaError, type ExtrasOptions, type ExtrasResponse, type FindSimilarOptions, type GetWebsetResponse, type HighlightsContentsOptions, type HighlightsResponse, HttpStatusCode, type JSONSchema, type ListEventsResponse, type ListWebhooksOptions, type ListWebhooksResponse, type ListWebsetItemResponse, type ListWebsetsOptions, type ListWebsetsResponse, type LivecrawlOptions, type RegularSearchOptions, ResearchClient, ResearchStatus, type ResearchTaskResponse, type SearchResponse, type SearchResult, type SubpagesResponse, type SummaryContentsOptions, type SummaryResponse, type TextContentsOptions, type TextResponse, type UpdateWebhookParameters, type UpdateWebsetRequest, type Webhook, WebhookStatus, type Webset, type WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, type WebsetItem, WebsetItemEvaluationSatisfied, WebsetItemSource, WebsetItemsClient, type WebsetSearch, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
1917
+ export { type AnswerOptions, type AnswerResponse, type AnswerStreamChunk, type AnswerStreamResponse, type BaseSearchOptions, type ContentsOptions, type ContentsResultComponent, type CostDollars, type CostDollarsContents, type CostDollarsSeearch, type CreateEnrichmentParameters, CreateEnrichmentParametersFormat, type CreateWebhookParameters, type CreateWebsetParameters, type CreateWebsetSearchParameters, CreateWebsetSearchParametersBehaviour, type Default, type EnrichmentResult, type Event, EventType, Exa, ExaError, type ExtrasOptions, type ExtrasResponse, type FindSimilarOptions, type GetWebsetResponse, type HighlightsContentsOptions, type HighlightsResponse, HttpStatusCode, type JSONSchema, type ListEventsResponse, type ListWebhooksOptions, type ListWebhooksResponse, type ListWebsetItemResponse, type ListWebsetsOptions, type ListWebsetsResponse, type LivecrawlOptions, type RegularSearchOptions, ResearchClient, ResearchStatus, type ResearchTask, type SearchResponse, type SearchResult, type SubpagesResponse, type SummaryContentsOptions, type SummaryResponse, type TextContentsOptions, type TextResponse, type UpdateWebhookParameters, type UpdateWebsetRequest, type Webhook, WebhookStatus, type Webset, type WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, type WebsetItem, WebsetItemEvaluationSatisfied, WebsetItemSource, WebsetItemsClient, type WebsetSearch, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
package/dist/index.d.ts CHANGED
@@ -1340,33 +1340,6 @@ declare class WebsetsClient extends WebsetsBaseClient {
1340
1340
  } | number): Promise<Webset>;
1341
1341
  }
1342
1342
 
1343
- /**
1344
- * Enum representing the status of a research task.
1345
- */
1346
- declare enum ResearchStatus {
1347
- /** The research request has finished successfully. */
1348
- completed = "completed",
1349
- /** The research request failed. */
1350
- failed = "failed"
1351
- }
1352
- /**
1353
- * Response object returned from the research API.
1354
- */
1355
- type ResearchTaskResponse = {
1356
- /** Unique identifier for the task. */
1357
- id: string;
1358
- /** Current status (may include future enum values served by the API). */
1359
- status: ResearchStatus | string;
1360
- /** Structured output that follows the user-provided schema (null while running). */
1361
- output: Record<string, any> | null;
1362
- /**
1363
- * Citations collected while deriving each top-level field in `output`.
1364
- * The key is the field name, the value is the list of `SearchResult`s that
1365
- * were used to compute that field.
1366
- */
1367
- citations: Record<string, SearchResult<{}>[]>;
1368
- };
1369
-
1370
1343
  type QueryParams = Record<string, string | number | boolean | string[] | undefined>;
1371
1344
  interface RequestBody {
1372
1345
  [key: string]: unknown;
@@ -1398,7 +1371,7 @@ declare class ResearchBaseClient {
1398
1371
  declare class ResearchClient extends ResearchBaseClient {
1399
1372
  constructor(client: Exa);
1400
1373
  /**
1401
- * Create and run a research task (blocking call).
1374
+ * Create a research task.
1402
1375
  *
1403
1376
  * Both parameters are required and have fixed shapes:
1404
1377
  * 1. `input`
@@ -1417,15 +1390,52 @@ declare class ResearchClient extends ResearchBaseClient {
1417
1390
  instructions: string;
1418
1391
  }, output: {
1419
1392
  schema: JSONSchema;
1420
- }): Promise<ResearchTaskResponse>;
1393
+ }): Promise<{
1394
+ id: string;
1395
+ }>;
1421
1396
  /**
1422
1397
  * Retrieve a research task by ID.
1423
- *
1424
- * Not yet implemented server-side. Calling this will throw until the API is
1425
- * available.
1426
1398
  */
1427
- getTask(): Promise<ResearchTaskResponse>;
1399
+ getTask(id: string): Promise<ResearchTask>;
1400
+ /**
1401
+ * Poll a research task until completion or failure.
1402
+ * Polls every 1 second with a maximum timeout of 10 minutes.
1403
+ */
1404
+ pollTask(id: string): Promise<ResearchTask>;
1405
+ }
1406
+
1407
+ /**
1408
+ * Enum representing the status of a research task.
1409
+ */
1410
+ declare enum ResearchStatus {
1411
+ /** The research task is still in progress. */
1412
+ in_progress = "in_progress",
1413
+ /** The research request has finished successfully. */
1414
+ completed = "completed",
1415
+ /** The research task request failed. */
1416
+ failed = "failed"
1428
1417
  }
1418
+ /**
1419
+ * Response object returned from the research API.
1420
+ */
1421
+ type ResearchTask = {
1422
+ /** Unique identifier for the task. */
1423
+ id: string;
1424
+ /** Current status. */
1425
+ status: ResearchStatus;
1426
+ /** The original instructions provided along with the task. */
1427
+ instructions: string;
1428
+ /** The original schema defining the task */
1429
+ schema: Record<string, any>;
1430
+ /** Structured output that follows the user-provided schema (null while running or if failed). */
1431
+ data: Record<string, any> | null;
1432
+ /**
1433
+ * Citations collected while deriving each top-level field in `output`.
1434
+ * The key is the field name, the value is the list of `SearchResult`s that
1435
+ * were used to compute that field.
1436
+ */
1437
+ citations: Record<string, SearchResult<{}>[]>;
1438
+ };
1429
1439
 
1430
1440
  /**
1431
1441
  * HTTP status codes
@@ -1904,4 +1914,4 @@ declare class Exa {
1904
1914
  private parseSSEStream;
1905
1915
  }
1906
1916
 
1907
- export { type AnswerOptions, type AnswerResponse, type AnswerStreamChunk, type AnswerStreamResponse, type BaseSearchOptions, type ContentsOptions, type ContentsResultComponent, type CostDollars, type CostDollarsContents, type CostDollarsSeearch, type CreateEnrichmentParameters, CreateEnrichmentParametersFormat, type CreateWebhookParameters, type CreateWebsetParameters, type CreateWebsetSearchParameters, CreateWebsetSearchParametersBehaviour, type Default, type EnrichmentResult, type Event, EventType, Exa, ExaError, type ExtrasOptions, type ExtrasResponse, type FindSimilarOptions, type GetWebsetResponse, type HighlightsContentsOptions, type HighlightsResponse, HttpStatusCode, type JSONSchema, type ListEventsResponse, type ListWebhooksOptions, type ListWebhooksResponse, type ListWebsetItemResponse, type ListWebsetsOptions, type ListWebsetsResponse, type LivecrawlOptions, type RegularSearchOptions, ResearchClient, ResearchStatus, type ResearchTaskResponse, type SearchResponse, type SearchResult, type SubpagesResponse, type SummaryContentsOptions, type SummaryResponse, type TextContentsOptions, type TextResponse, type UpdateWebhookParameters, type UpdateWebsetRequest, type Webhook, WebhookStatus, type Webset, type WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, type WebsetItem, WebsetItemEvaluationSatisfied, WebsetItemSource, WebsetItemsClient, type WebsetSearch, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
1917
+ export { type AnswerOptions, type AnswerResponse, type AnswerStreamChunk, type AnswerStreamResponse, type BaseSearchOptions, type ContentsOptions, type ContentsResultComponent, type CostDollars, type CostDollarsContents, type CostDollarsSeearch, type CreateEnrichmentParameters, CreateEnrichmentParametersFormat, type CreateWebhookParameters, type CreateWebsetParameters, type CreateWebsetSearchParameters, CreateWebsetSearchParametersBehaviour, type Default, type EnrichmentResult, type Event, EventType, Exa, ExaError, type ExtrasOptions, type ExtrasResponse, type FindSimilarOptions, type GetWebsetResponse, type HighlightsContentsOptions, type HighlightsResponse, HttpStatusCode, type JSONSchema, type ListEventsResponse, type ListWebhooksOptions, type ListWebhooksResponse, type ListWebsetItemResponse, type ListWebsetsOptions, type ListWebsetsResponse, type LivecrawlOptions, type RegularSearchOptions, ResearchClient, ResearchStatus, type ResearchTask, type SearchResponse, type SearchResult, type SubpagesResponse, type SummaryContentsOptions, type SummaryResponse, type TextContentsOptions, type TextResponse, type UpdateWebhookParameters, type UpdateWebsetRequest, type Webhook, WebhookStatus, type Webset, type WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, type WebsetItem, WebsetItemEvaluationSatisfied, WebsetItemSource, WebsetItemsClient, type WebsetSearch, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
package/dist/index.js CHANGED
@@ -719,7 +719,7 @@ var ResearchClient = class extends ResearchBaseClient {
719
719
  super(client);
720
720
  }
721
721
  /**
722
- * Create and run a research task (blocking call).
722
+ * Create a research task.
723
723
  *
724
724
  * Both parameters are required and have fixed shapes:
725
725
  * 1. `input`
@@ -742,17 +742,36 @@ var ResearchClient = class extends ResearchBaseClient {
742
742
  }
743
743
  /**
744
744
  * Retrieve a research task by ID.
745
- *
746
- * Not yet implemented server-side. Calling this will throw until the API is
747
- * available.
748
745
  */
749
- async getTask() {
750
- throw new Error("getTask is not implemented yet.");
746
+ async getTask(id) {
747
+ return this.request(`/tasks/${id}`, "GET");
748
+ }
749
+ /**
750
+ * Poll a research task until completion or failure.
751
+ * Polls every 1 second with a maximum timeout of 10 minutes.
752
+ */
753
+ async pollTask(id) {
754
+ const pollingInterval = 1e3;
755
+ const maxPollingTime = 10 * 60 * 1e3;
756
+ const startTime = Date.now();
757
+ while (true) {
758
+ const task = await this.request(`/tasks/${id}`, "GET");
759
+ if (task.status === "completed" || task.status === "failed") {
760
+ return task;
761
+ }
762
+ if (Date.now() - startTime > maxPollingTime) {
763
+ throw new Error(
764
+ `Polling timeout: Task ${id} did not complete within 10 minutes`
765
+ );
766
+ }
767
+ await new Promise((resolve) => setTimeout(resolve, pollingInterval));
768
+ }
751
769
  }
752
770
  };
753
771
 
754
772
  // src/research/types.ts
755
773
  var ResearchStatus = /* @__PURE__ */ ((ResearchStatus2) => {
774
+ ResearchStatus2["in_progress"] = "in_progress";
756
775
  ResearchStatus2["completed"] = "completed";
757
776
  ResearchStatus2["failed"] = "failed";
758
777
  return ResearchStatus2;