exa-js 1.6.13 → 1.7.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/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 {
@@ -865,7 +861,8 @@ var Exa2 = class {
865
861
  stream: false,
866
862
  text: options?.text ?? false,
867
863
  model: options?.model ?? "exa",
868
- systemPrompt: options?.systemPrompt
864
+ systemPrompt: options?.systemPrompt,
865
+ outputSchema: options?.outputSchema
869
866
  };
870
867
  return await this.request("/answer", "POST", requestBody);
871
868
  }
@@ -894,7 +891,8 @@ var Exa2 = class {
894
891
  text: options?.text ?? false,
895
892
  stream: true,
896
893
  model: options?.model ?? "exa",
897
- systemPrompt: options?.systemPrompt
894
+ systemPrompt: options?.systemPrompt,
895
+ outputSchema: options?.outputSchema
898
896
  };
899
897
  const response = await fetchImpl(this.baseURL + "/answer", {
900
898
  method: "POST",
@@ -918,14 +916,12 @@ var Exa2 = class {
918
916
  try {
919
917
  while (true) {
920
918
  const { done, value } = await reader.read();
921
- if (done)
922
- break;
919
+ if (done) break;
923
920
  buffer += decoder.decode(value, { stream: true });
924
921
  const lines = buffer.split("\n");
925
922
  buffer = lines.pop() || "";
926
923
  for (const line of lines) {
927
- if (!line.startsWith("data: "))
928
- continue;
924
+ if (!line.startsWith("data: ")) continue;
929
925
  const jsonStr = line.replace(/^data:\s*/, "").trim();
930
926
  if (!jsonStr || jsonStr === "[DONE]") {
931
927
  continue;
@@ -977,8 +973,50 @@ var Exa2 = class {
977
973
  }
978
974
  return { content, citations };
979
975
  }
976
+ /**
977
+ * Creates and runs a research task in a blocking manner.
978
+ *
979
+ * Both parameters are required and have fixed shapes:
980
+ * 1. `input`
981
+ * `{ instructions: string }`
982
+ * • `instructions` – High-level guidance that tells the research agent what to do.
983
+ * 2. `output`
984
+ * defines the exact structure you expect back, and guides the research conducted by the agent.
985
+ * `{ schema: JSONSchema }`.
986
+ * The agent’s response will be validated against this schema.
987
+ *
988
+ * @param {{ instructions: string }} input The research prompt.
989
+ * @param {{ schema: JSONSchema }} output The desired output schema.
990
+ * @returns {Promise<ResearchTaskResponse>} The research response.
991
+ *
992
+ * @example
993
+ * const response = await exa.researchTask(
994
+ * { instructions: "I need a few key facts about honey pot ants." },
995
+ * {
996
+ * schema: {
997
+ * type: "object",
998
+ * required: ["scientificName", "primaryRegions"],
999
+ * properties: {
1000
+ * scientificName: { type: "string" },
1001
+ * primaryRegions: { type: "string" },
1002
+ * },
1003
+ * },
1004
+ * },
1005
+ * );
1006
+ */
1007
+ async researchTask(input, output) {
1008
+ const body = {
1009
+ input,
1010
+ output
1011
+ };
1012
+ return await this.request(
1013
+ "/research/tasks",
1014
+ "POST",
1015
+ body
1016
+ );
1017
+ }
980
1018
  };
981
- var src_default = Exa2;
1019
+ var index_default = Exa2;
982
1020
  export {
983
1021
  CreateEnrichmentParametersFormat,
984
1022
  CreateWebsetSearchParametersBehaviour,
@@ -986,6 +1024,7 @@ export {
986
1024
  Exa2 as Exa,
987
1025
  ExaError,
988
1026
  HttpStatusCode,
1027
+ ResearchStatus,
989
1028
  WebhookStatus,
990
1029
  WebsetEnrichmentFormat,
991
1030
  WebsetEnrichmentStatus,
@@ -999,6 +1038,6 @@ export {
999
1038
  WebsetStatus,
1000
1039
  WebsetWebhooksClient,
1001
1040
  WebsetsClient,
1002
- src_default as default
1041
+ index_default as default
1003
1042
  };
1004
1043
  //# sourceMappingURL=index.mjs.map