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/README.md +82 -42
- package/dist/index.d.mts +1874 -0
- package/dist/index.d.ts +66 -3
- package/dist/index.js +69 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1644,24 +1644,28 @@ type SearchResponse<T extends ContentsOptions> = {
|
|
|
1644
1644
|
* @property {boolean} [text] - Whether to include text in the source results. Default false.
|
|
1645
1645
|
* @property {"exa" | "exa-pro"} [model] - The model to use for generating the answer. Default "exa".
|
|
1646
1646
|
* @property {string} [systemPrompt] - A system prompt to guide the LLM's behavior when generating the answer.
|
|
1647
|
+
* @property {Object} [outputSchema] - A JSON Schema specification for the structure you expect the output to take
|
|
1647
1648
|
*/
|
|
1648
1649
|
type AnswerOptions = {
|
|
1649
1650
|
stream?: boolean;
|
|
1650
1651
|
text?: boolean;
|
|
1651
1652
|
model?: "exa" | "exa-pro";
|
|
1652
1653
|
systemPrompt?: string;
|
|
1654
|
+
outputSchema?: Record<string, unknown>;
|
|
1653
1655
|
};
|
|
1654
1656
|
/**
|
|
1655
1657
|
* Represents an answer response object from the /answer endpoint.
|
|
1656
1658
|
* @typedef {Object} AnswerResponse
|
|
1657
|
-
* @property {string} answer - The generated answer text
|
|
1659
|
+
* @property {string | Object} answer - The generated answer text (or an object matching `outputSchema`, if provided)
|
|
1658
1660
|
* @property {SearchResult<{}>[]} citations - The sources used to generate the answer.
|
|
1661
|
+
* @property {CostDollars} [costDollars] - The cost breakdown for this request.
|
|
1659
1662
|
* @property {string} [requestId] - Optional request ID for the answer.
|
|
1660
1663
|
*/
|
|
1661
1664
|
type AnswerResponse = {
|
|
1662
|
-
answer: string
|
|
1665
|
+
answer: string | Record<string, unknown>;
|
|
1663
1666
|
citations: SearchResult<{}>[];
|
|
1664
1667
|
requestId?: string;
|
|
1668
|
+
costDollars?: CostDollars;
|
|
1665
1669
|
};
|
|
1666
1670
|
type AnswerStreamChunk = {
|
|
1667
1671
|
/**
|
|
@@ -1690,6 +1694,28 @@ type AnswerStreamResponse = {
|
|
|
1690
1694
|
answer?: string;
|
|
1691
1695
|
citations?: SearchResult<{}>[];
|
|
1692
1696
|
};
|
|
1697
|
+
/**
|
|
1698
|
+
* Enum representing the status of a research task.
|
|
1699
|
+
*/
|
|
1700
|
+
declare enum ResearchStatus {
|
|
1701
|
+
/** The research request has finished successfully. */
|
|
1702
|
+
completed = "completed",
|
|
1703
|
+
/** The research request failed. */
|
|
1704
|
+
failed = "failed"
|
|
1705
|
+
}
|
|
1706
|
+
/**
|
|
1707
|
+
* @typedef {Object} ResearchTaskResponse
|
|
1708
|
+
* @property {string} id - The unique identifier of the research request.
|
|
1709
|
+
* @property {ResearchStatus | string} status - The current status of the research request.
|
|
1710
|
+
* @property {Record<string, any> | null} output - The structured output, if the research has completed.
|
|
1711
|
+
* @property {SearchResult<{}>[]} citations - References used for the research.
|
|
1712
|
+
*/
|
|
1713
|
+
type ResearchTaskResponse = {
|
|
1714
|
+
id: string;
|
|
1715
|
+
status: ResearchStatus | string;
|
|
1716
|
+
output: Record<string, any> | null;
|
|
1717
|
+
citations: SearchResult<{}>[];
|
|
1718
|
+
};
|
|
1693
1719
|
|
|
1694
1720
|
/**
|
|
1695
1721
|
* The Exa class encapsulates the API's endpoints.
|
|
@@ -1804,8 +1830,45 @@ declare class Exa {
|
|
|
1804
1830
|
text?: boolean;
|
|
1805
1831
|
model?: "exa" | "exa-pro";
|
|
1806
1832
|
systemPrompt?: string;
|
|
1833
|
+
outputSchema?: Record<string, unknown>;
|
|
1807
1834
|
}): AsyncGenerator<AnswerStreamChunk>;
|
|
1808
1835
|
private processChunk;
|
|
1836
|
+
/**
|
|
1837
|
+
* Creates and runs a research task in a blocking manner.
|
|
1838
|
+
*
|
|
1839
|
+
* Both parameters are required and have fixed shapes:
|
|
1840
|
+
* 1. `input`
|
|
1841
|
+
* `{ instructions: string }`
|
|
1842
|
+
* • `instructions` – High-level guidance that tells the research agent what to do.
|
|
1843
|
+
* 2. `output`
|
|
1844
|
+
* defines the exact structure you expect back, and guides the research conducted by the agent.
|
|
1845
|
+
* `{ schema: JSONSchema }`.
|
|
1846
|
+
* The agent’s response will be validated against this schema.
|
|
1847
|
+
*
|
|
1848
|
+
* @param {{ instructions: string }} input The research prompt.
|
|
1849
|
+
* @param {{ schema: JSONSchema }} output The desired output schema.
|
|
1850
|
+
* @returns {Promise<ResearchTaskResponse>} The research response.
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* const response = await exa.researchTask(
|
|
1854
|
+
* { instructions: "I need a few key facts about honey pot ants." },
|
|
1855
|
+
* {
|
|
1856
|
+
* schema: {
|
|
1857
|
+
* type: "object",
|
|
1858
|
+
* required: ["scientificName", "primaryRegions"],
|
|
1859
|
+
* properties: {
|
|
1860
|
+
* scientificName: { type: "string" },
|
|
1861
|
+
* primaryRegions: { type: "string" },
|
|
1862
|
+
* },
|
|
1863
|
+
* },
|
|
1864
|
+
* },
|
|
1865
|
+
* );
|
|
1866
|
+
*/
|
|
1867
|
+
researchTask(input: {
|
|
1868
|
+
instructions: string;
|
|
1869
|
+
}, output: {
|
|
1870
|
+
schema: JSONSchema;
|
|
1871
|
+
}): Promise<ResearchTaskResponse>;
|
|
1809
1872
|
}
|
|
1810
1873
|
|
|
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 };
|
|
1874
|
+
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
|
|
32
|
-
__export(
|
|
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: () =>
|
|
53
|
+
default: () => index_default
|
|
53
54
|
});
|
|
54
|
-
module.exports = __toCommonJS(
|
|
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
|
-
|
|
116
|
-
if (pagination.
|
|
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
|
-
|
|
720
|
-
if (
|
|
721
|
-
|
|
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
|
-
|
|
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 {
|
|
@@ -918,7 +915,8 @@ var Exa2 = class {
|
|
|
918
915
|
stream: false,
|
|
919
916
|
text: options?.text ?? false,
|
|
920
917
|
model: options?.model ?? "exa",
|
|
921
|
-
systemPrompt: options?.systemPrompt
|
|
918
|
+
systemPrompt: options?.systemPrompt,
|
|
919
|
+
outputSchema: options?.outputSchema
|
|
922
920
|
};
|
|
923
921
|
return await this.request("/answer", "POST", requestBody);
|
|
924
922
|
}
|
|
@@ -947,7 +945,8 @@ var Exa2 = class {
|
|
|
947
945
|
text: options?.text ?? false,
|
|
948
946
|
stream: true,
|
|
949
947
|
model: options?.model ?? "exa",
|
|
950
|
-
systemPrompt: options?.systemPrompt
|
|
948
|
+
systemPrompt: options?.systemPrompt,
|
|
949
|
+
outputSchema: options?.outputSchema
|
|
951
950
|
};
|
|
952
951
|
const response = await fetchImpl(this.baseURL + "/answer", {
|
|
953
952
|
method: "POST",
|
|
@@ -971,14 +970,12 @@ var Exa2 = class {
|
|
|
971
970
|
try {
|
|
972
971
|
while (true) {
|
|
973
972
|
const { done, value } = await reader.read();
|
|
974
|
-
if (done)
|
|
975
|
-
break;
|
|
973
|
+
if (done) break;
|
|
976
974
|
buffer += decoder.decode(value, { stream: true });
|
|
977
975
|
const lines = buffer.split("\n");
|
|
978
976
|
buffer = lines.pop() || "";
|
|
979
977
|
for (const line of lines) {
|
|
980
|
-
if (!line.startsWith("data: "))
|
|
981
|
-
continue;
|
|
978
|
+
if (!line.startsWith("data: ")) continue;
|
|
982
979
|
const jsonStr = line.replace(/^data:\s*/, "").trim();
|
|
983
980
|
if (!jsonStr || jsonStr === "[DONE]") {
|
|
984
981
|
continue;
|
|
@@ -1030,8 +1027,50 @@ var Exa2 = class {
|
|
|
1030
1027
|
}
|
|
1031
1028
|
return { content, citations };
|
|
1032
1029
|
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Creates and runs a research task in a blocking manner.
|
|
1032
|
+
*
|
|
1033
|
+
* Both parameters are required and have fixed shapes:
|
|
1034
|
+
* 1. `input`
|
|
1035
|
+
* `{ instructions: string }`
|
|
1036
|
+
* • `instructions` – High-level guidance that tells the research agent what to do.
|
|
1037
|
+
* 2. `output`
|
|
1038
|
+
* defines the exact structure you expect back, and guides the research conducted by the agent.
|
|
1039
|
+
* `{ schema: JSONSchema }`.
|
|
1040
|
+
* The agent’s response will be validated against this schema.
|
|
1041
|
+
*
|
|
1042
|
+
* @param {{ instructions: string }} input The research prompt.
|
|
1043
|
+
* @param {{ schema: JSONSchema }} output The desired output schema.
|
|
1044
|
+
* @returns {Promise<ResearchTaskResponse>} The research response.
|
|
1045
|
+
*
|
|
1046
|
+
* @example
|
|
1047
|
+
* const response = await exa.researchTask(
|
|
1048
|
+
* { instructions: "I need a few key facts about honey pot ants." },
|
|
1049
|
+
* {
|
|
1050
|
+
* schema: {
|
|
1051
|
+
* type: "object",
|
|
1052
|
+
* required: ["scientificName", "primaryRegions"],
|
|
1053
|
+
* properties: {
|
|
1054
|
+
* scientificName: { type: "string" },
|
|
1055
|
+
* primaryRegions: { type: "string" },
|
|
1056
|
+
* },
|
|
1057
|
+
* },
|
|
1058
|
+
* },
|
|
1059
|
+
* );
|
|
1060
|
+
*/
|
|
1061
|
+
async researchTask(input, output) {
|
|
1062
|
+
const body = {
|
|
1063
|
+
input,
|
|
1064
|
+
output
|
|
1065
|
+
};
|
|
1066
|
+
return await this.request(
|
|
1067
|
+
"/research/tasks",
|
|
1068
|
+
"POST",
|
|
1069
|
+
body
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1033
1072
|
};
|
|
1034
|
-
var
|
|
1073
|
+
var index_default = Exa2;
|
|
1035
1074
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1036
1075
|
0 && (module.exports = {
|
|
1037
1076
|
CreateEnrichmentParametersFormat,
|
|
@@ -1040,6 +1079,7 @@ var src_default = Exa2;
|
|
|
1040
1079
|
Exa,
|
|
1041
1080
|
ExaError,
|
|
1042
1081
|
HttpStatusCode,
|
|
1082
|
+
ResearchStatus,
|
|
1043
1083
|
WebhookStatus,
|
|
1044
1084
|
WebsetEnrichmentFormat,
|
|
1045
1085
|
WebsetEnrichmentStatus,
|