exa-js 1.6.13 → 1.7.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/dist/index.d.ts CHANGED
@@ -1656,12 +1656,14 @@ type AnswerOptions = {
1656
1656
  * @typedef {Object} AnswerResponse
1657
1657
  * @property {string} answer - The generated answer text.
1658
1658
  * @property {SearchResult<{}>[]} citations - The sources used to generate the answer.
1659
+ * @property {CostDollars} [costDollars] - The cost breakdown for this request.
1659
1660
  * @property {string} [requestId] - Optional request ID for the answer.
1660
1661
  */
1661
1662
  type AnswerResponse = {
1662
1663
  answer: string;
1663
1664
  citations: SearchResult<{}>[];
1664
1665
  requestId?: string;
1666
+ costDollars?: CostDollars;
1665
1667
  };
1666
1668
  type AnswerStreamChunk = {
1667
1669
  /**
@@ -1690,6 +1692,28 @@ type AnswerStreamResponse = {
1690
1692
  answer?: string;
1691
1693
  citations?: SearchResult<{}>[];
1692
1694
  };
1695
+ /**
1696
+ * Enum representing the status of a research task.
1697
+ */
1698
+ declare enum ResearchStatus {
1699
+ /** The research request has finished successfully. */
1700
+ completed = "completed",
1701
+ /** The research request failed. */
1702
+ failed = "failed"
1703
+ }
1704
+ /**
1705
+ * @typedef {Object} ResearchTaskResponse
1706
+ * @property {string} id - The unique identifier of the research request.
1707
+ * @property {ResearchStatus | string} status - The current status of the research request.
1708
+ * @property {Record<string, any> | null} output - The structured output, if the research has completed.
1709
+ * @property {SearchResult<{}>[]} citations - References used for the research.
1710
+ */
1711
+ type ResearchTaskResponse = {
1712
+ id: string;
1713
+ status: ResearchStatus | string;
1714
+ output: Record<string, any> | null;
1715
+ citations: SearchResult<{}>[];
1716
+ };
1693
1717
 
1694
1718
  /**
1695
1719
  * The Exa class encapsulates the API's endpoints.
@@ -1806,6 +1830,42 @@ declare class Exa {
1806
1830
  systemPrompt?: string;
1807
1831
  }): AsyncGenerator<AnswerStreamChunk>;
1808
1832
  private processChunk;
1833
+ /**
1834
+ * Creates and runs a research task in a blocking manner.
1835
+ *
1836
+ * Both parameters are required and have fixed shapes:
1837
+ * 1. `input`
1838
+ * `{ instructions: string }`
1839
+ * • `instructions` – High-level guidance that tells the research agent what to do.
1840
+ * 2. `output`
1841
+ * defines the exact structure you expect back, and guides the research conducted by the agent.
1842
+ * `{ schema: JSONSchema }`.
1843
+ * The agent’s response will be validated against this schema.
1844
+ *
1845
+ * @param {{ instructions: string }} input The research prompt.
1846
+ * @param {{ schema: JSONSchema }} output The desired output schema.
1847
+ * @returns {Promise<ResearchTaskResponse>} The research response.
1848
+ *
1849
+ * @example
1850
+ * const response = await exa.researchTask(
1851
+ * { instructions: "I need a few key facts about honey pot ants." },
1852
+ * {
1853
+ * schema: {
1854
+ * type: "object",
1855
+ * required: ["scientificName", "primaryRegions"],
1856
+ * properties: {
1857
+ * scientificName: { type: "string" },
1858
+ * primaryRegions: { type: "string" },
1859
+ * },
1860
+ * },
1861
+ * },
1862
+ * );
1863
+ */
1864
+ researchTask(input: {
1865
+ instructions: string;
1866
+ }, output: {
1867
+ schema: JSONSchema;
1868
+ }): Promise<ResearchTaskResponse>;
1809
1869
  }
1810
1870
 
1811
- export { AnswerOptions, AnswerResponse, AnswerStreamChunk, AnswerStreamResponse, BaseSearchOptions, ContentsOptions, ContentsResultComponent, CostDollars, CostDollarsContents, CostDollarsSeearch, CreateEnrichmentParameters, CreateEnrichmentParametersFormat, CreateWebhookParameters, CreateWebsetParameters, CreateWebsetSearchParameters, CreateWebsetSearchParametersBehaviour, Default, EnrichmentResult, Event, EventType, Exa, ExaError, ExtrasOptions, ExtrasResponse, FindSimilarOptions, GetWebsetResponse, HighlightsContentsOptions, HighlightsResponse, HttpStatusCode, JSONSchema, ListEventsResponse, ListWebhooksOptions, ListWebhooksResponse, ListWebsetItemResponse, ListWebsetsOptions, ListWebsetsResponse, LivecrawlOptions, RegularSearchOptions, SearchResponse, SearchResult, SubpagesResponse, SummaryContentsOptions, SummaryResponse, TextContentsOptions, TextResponse, UpdateWebhookParameters, UpdateWebsetRequest, Webhook, WebhookStatus, Webset, WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, WebsetItem, WebsetItemEvaluationSatisfied, WebsetItemSource, WebsetItemsClient, WebsetSearch, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
1871
+ 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, 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 };
package/dist/index.js CHANGED
@@ -28,14 +28,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  CreateEnrichmentParametersFormat: () => CreateEnrichmentParametersFormat,
34
34
  CreateWebsetSearchParametersBehaviour: () => CreateWebsetSearchParametersBehaviour,
35
35
  EventType: () => EventType,
36
36
  Exa: () => Exa2,
37
37
  ExaError: () => ExaError,
38
38
  HttpStatusCode: () => HttpStatusCode,
39
+ ResearchStatus: () => ResearchStatus,
39
40
  WebhookStatus: () => WebhookStatus,
40
41
  WebsetEnrichmentFormat: () => WebsetEnrichmentFormat,
41
42
  WebsetEnrichmentStatus: () => WebsetEnrichmentStatus,
@@ -49,9 +50,9 @@ __export(src_exports, {
49
50
  WebsetStatus: () => WebsetStatus,
50
51
  WebsetWebhooksClient: () => WebsetWebhooksClient,
51
52
  WebsetsClient: () => WebsetsClient,
52
- default: () => src_default
53
+ default: () => index_default
53
54
  });
54
- module.exports = __toCommonJS(src_exports);
55
+ module.exports = __toCommonJS(index_exports);
55
56
  var import_cross_fetch = __toESM(require("cross-fetch"));
56
57
 
57
58
  // src/errors.ts
@@ -111,12 +112,9 @@ var WebsetsBaseClient = class {
111
112
  */
112
113
  buildPaginationParams(pagination) {
113
114
  const params = {};
114
- if (!pagination)
115
- return params;
116
- if (pagination.cursor)
117
- params.cursor = pagination.cursor;
118
- if (pagination.limit)
119
- params.limit = pagination.limit;
115
+ if (!pagination) return params;
116
+ if (pagination.cursor) params.cursor = pagination.cursor;
117
+ if (pagination.limit) params.limit = pagination.limit;
120
118
  return params;
121
119
  }
122
120
  };
@@ -695,6 +693,11 @@ var WebsetsClient = class extends WebsetsBaseClient {
695
693
  // src/index.ts
696
694
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
697
695
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
696
+ var ResearchStatus = /* @__PURE__ */ ((ResearchStatus2) => {
697
+ ResearchStatus2["completed"] = "completed";
698
+ ResearchStatus2["failed"] = "failed";
699
+ return ResearchStatus2;
700
+ })(ResearchStatus || {});
698
701
  var Exa2 = class {
699
702
  /**
700
703
  * Helper method to separate out the contents-specific options from the rest.
@@ -715,20 +718,14 @@ var Exa2 = class {
715
718
  if (text === void 0 && summary === void 0 && highlights === void 0 && extras === void 0) {
716
719
  contentsOptions.text = true;
717
720
  }
718
- if (text !== void 0)
719
- contentsOptions.text = text;
720
- if (summary !== void 0)
721
- contentsOptions.summary = summary;
722
- if (highlights !== void 0)
723
- contentsOptions.highlights = highlights;
724
- if (subpages !== void 0)
725
- contentsOptions.subpages = subpages;
721
+ if (text !== void 0) contentsOptions.text = text;
722
+ if (summary !== void 0) contentsOptions.summary = summary;
723
+ if (highlights !== void 0) contentsOptions.highlights = highlights;
724
+ if (subpages !== void 0) contentsOptions.subpages = subpages;
726
725
  if (subpageTarget !== void 0)
727
726
  contentsOptions.subpageTarget = subpageTarget;
728
- if (extras !== void 0)
729
- contentsOptions.extras = extras;
730
- if (livecrawl !== void 0)
731
- contentsOptions.livecrawl = livecrawl;
727
+ if (extras !== void 0) contentsOptions.extras = extras;
728
+ if (livecrawl !== void 0) contentsOptions.livecrawl = livecrawl;
732
729
  if (livecrawlTimeout !== void 0)
733
730
  contentsOptions.livecrawlTimeout = livecrawlTimeout;
734
731
  return {
@@ -971,14 +968,12 @@ var Exa2 = class {
971
968
  try {
972
969
  while (true) {
973
970
  const { done, value } = await reader.read();
974
- if (done)
975
- break;
971
+ if (done) break;
976
972
  buffer += decoder.decode(value, { stream: true });
977
973
  const lines = buffer.split("\n");
978
974
  buffer = lines.pop() || "";
979
975
  for (const line of lines) {
980
- if (!line.startsWith("data: "))
981
- continue;
976
+ if (!line.startsWith("data: ")) continue;
982
977
  const jsonStr = line.replace(/^data:\s*/, "").trim();
983
978
  if (!jsonStr || jsonStr === "[DONE]") {
984
979
  continue;
@@ -1030,8 +1025,50 @@ var Exa2 = class {
1030
1025
  }
1031
1026
  return { content, citations };
1032
1027
  }
1028
+ /**
1029
+ * Creates and runs a research task in a blocking manner.
1030
+ *
1031
+ * Both parameters are required and have fixed shapes:
1032
+ * 1. `input`
1033
+ * `{ instructions: string }`
1034
+ * • `instructions` – High-level guidance that tells the research agent what to do.
1035
+ * 2. `output`
1036
+ * defines the exact structure you expect back, and guides the research conducted by the agent.
1037
+ * `{ schema: JSONSchema }`.
1038
+ * The agent’s response will be validated against this schema.
1039
+ *
1040
+ * @param {{ instructions: string }} input The research prompt.
1041
+ * @param {{ schema: JSONSchema }} output The desired output schema.
1042
+ * @returns {Promise<ResearchTaskResponse>} The research response.
1043
+ *
1044
+ * @example
1045
+ * const response = await exa.researchTask(
1046
+ * { instructions: "I need a few key facts about honey pot ants." },
1047
+ * {
1048
+ * schema: {
1049
+ * type: "object",
1050
+ * required: ["scientificName", "primaryRegions"],
1051
+ * properties: {
1052
+ * scientificName: { type: "string" },
1053
+ * primaryRegions: { type: "string" },
1054
+ * },
1055
+ * },
1056
+ * },
1057
+ * );
1058
+ */
1059
+ async researchTask(input, output) {
1060
+ const body = {
1061
+ input,
1062
+ output
1063
+ };
1064
+ return await this.request(
1065
+ "/research/tasks",
1066
+ "POST",
1067
+ body
1068
+ );
1069
+ }
1033
1070
  };
1034
- var src_default = Exa2;
1071
+ var index_default = Exa2;
1035
1072
  // Annotate the CommonJS export names for ESM import in node:
1036
1073
  0 && (module.exports = {
1037
1074
  CreateEnrichmentParametersFormat,
@@ -1040,6 +1077,7 @@ var src_default = Exa2;
1040
1077
  Exa,
1041
1078
  ExaError,
1042
1079
  HttpStatusCode,
1080
+ ResearchStatus,
1043
1081
  WebhookStatus,
1044
1082
  WebsetEnrichmentFormat,
1045
1083
  WebsetEnrichmentStatus,