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.mjs CHANGED
@@ -58,12 +58,9 @@ var WebsetsBaseClient = class {
58
58
  */
59
59
  buildPaginationParams(pagination) {
60
60
  const params = {};
61
- if (!pagination)
62
- return params;
63
- if (pagination.cursor)
64
- params.cursor = pagination.cursor;
65
- if (pagination.limit)
66
- params.limit = pagination.limit;
61
+ if (!pagination) return params;
62
+ if (pagination.cursor) params.cursor = pagination.cursor;
63
+ if (pagination.limit) params.limit = pagination.limit;
67
64
  return params;
68
65
  }
69
66
  };
@@ -642,6 +639,11 @@ var WebsetsClient = class extends WebsetsBaseClient {
642
639
  // src/index.ts
643
640
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch;
644
641
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
642
+ var ResearchStatus = /* @__PURE__ */ ((ResearchStatus2) => {
643
+ ResearchStatus2["completed"] = "completed";
644
+ ResearchStatus2["failed"] = "failed";
645
+ return ResearchStatus2;
646
+ })(ResearchStatus || {});
645
647
  var Exa2 = class {
646
648
  /**
647
649
  * Helper method to separate out the contents-specific options from the rest.
@@ -662,20 +664,14 @@ var Exa2 = class {
662
664
  if (text === void 0 && summary === void 0 && highlights === void 0 && extras === void 0) {
663
665
  contentsOptions.text = true;
664
666
  }
665
- if (text !== void 0)
666
- contentsOptions.text = text;
667
- if (summary !== void 0)
668
- contentsOptions.summary = summary;
669
- if (highlights !== void 0)
670
- contentsOptions.highlights = highlights;
671
- if (subpages !== void 0)
672
- contentsOptions.subpages = subpages;
667
+ if (text !== void 0) contentsOptions.text = text;
668
+ if (summary !== void 0) contentsOptions.summary = summary;
669
+ if (highlights !== void 0) contentsOptions.highlights = highlights;
670
+ if (subpages !== void 0) contentsOptions.subpages = subpages;
673
671
  if (subpageTarget !== void 0)
674
672
  contentsOptions.subpageTarget = subpageTarget;
675
- if (extras !== void 0)
676
- contentsOptions.extras = extras;
677
- if (livecrawl !== void 0)
678
- contentsOptions.livecrawl = livecrawl;
673
+ if (extras !== void 0) contentsOptions.extras = extras;
674
+ if (livecrawl !== void 0) contentsOptions.livecrawl = livecrawl;
679
675
  if (livecrawlTimeout !== void 0)
680
676
  contentsOptions.livecrawlTimeout = livecrawlTimeout;
681
677
  return {
@@ -918,14 +914,12 @@ var Exa2 = class {
918
914
  try {
919
915
  while (true) {
920
916
  const { done, value } = await reader.read();
921
- if (done)
922
- break;
917
+ if (done) break;
923
918
  buffer += decoder.decode(value, { stream: true });
924
919
  const lines = buffer.split("\n");
925
920
  buffer = lines.pop() || "";
926
921
  for (const line of lines) {
927
- if (!line.startsWith("data: "))
928
- continue;
922
+ if (!line.startsWith("data: ")) continue;
929
923
  const jsonStr = line.replace(/^data:\s*/, "").trim();
930
924
  if (!jsonStr || jsonStr === "[DONE]") {
931
925
  continue;
@@ -977,8 +971,50 @@ var Exa2 = class {
977
971
  }
978
972
  return { content, citations };
979
973
  }
974
+ /**
975
+ * Creates and runs a research task in a blocking manner.
976
+ *
977
+ * Both parameters are required and have fixed shapes:
978
+ * 1. `input`
979
+ * `{ instructions: string }`
980
+ * • `instructions` – High-level guidance that tells the research agent what to do.
981
+ * 2. `output`
982
+ * defines the exact structure you expect back, and guides the research conducted by the agent.
983
+ * `{ schema: JSONSchema }`.
984
+ * The agent’s response will be validated against this schema.
985
+ *
986
+ * @param {{ instructions: string }} input The research prompt.
987
+ * @param {{ schema: JSONSchema }} output The desired output schema.
988
+ * @returns {Promise<ResearchTaskResponse>} The research response.
989
+ *
990
+ * @example
991
+ * const response = await exa.researchTask(
992
+ * { instructions: "I need a few key facts about honey pot ants." },
993
+ * {
994
+ * schema: {
995
+ * type: "object",
996
+ * required: ["scientificName", "primaryRegions"],
997
+ * properties: {
998
+ * scientificName: { type: "string" },
999
+ * primaryRegions: { type: "string" },
1000
+ * },
1001
+ * },
1002
+ * },
1003
+ * );
1004
+ */
1005
+ async researchTask(input, output) {
1006
+ const body = {
1007
+ input,
1008
+ output
1009
+ };
1010
+ return await this.request(
1011
+ "/research/tasks",
1012
+ "POST",
1013
+ body
1014
+ );
1015
+ }
980
1016
  };
981
- var src_default = Exa2;
1017
+ var index_default = Exa2;
982
1018
  export {
983
1019
  CreateEnrichmentParametersFormat,
984
1020
  CreateWebsetSearchParametersBehaviour,
@@ -986,6 +1022,7 @@ export {
986
1022
  Exa2 as Exa,
987
1023
  ExaError,
988
1024
  HttpStatusCode,
1025
+ ResearchStatus,
989
1026
  WebhookStatus,
990
1027
  WebsetEnrichmentFormat,
991
1028
  WebsetEnrichmentStatus,
@@ -999,6 +1036,6 @@ export {
999
1036
  WebsetStatus,
1000
1037
  WebsetWebhooksClient,
1001
1038
  WebsetsClient,
1002
- src_default as default
1039
+ index_default as default
1003
1040
  };
1004
1041
  //# sourceMappingURL=index.mjs.map