exa-js 2.10.2 → 2.11.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/README.md +21 -9
- package/dist/index.d.mts +32 -18
- package/dist/index.d.ts +32 -18
- package/dist/index.js +43 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import fetch2, { Headers } from "cross-fetch";
|
|
|
4
4
|
// package.json
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "exa-js",
|
|
7
|
-
version: "2.
|
|
7
|
+
version: "2.11.0",
|
|
8
8
|
description: "Exa SDK for Node.js and the browser",
|
|
9
9
|
publishConfig: {
|
|
10
10
|
access: "public"
|
|
@@ -1599,6 +1599,22 @@ var Exa2 = class {
|
|
|
1599
1599
|
restOptions: rest
|
|
1600
1600
|
};
|
|
1601
1601
|
}
|
|
1602
|
+
buildSearchRequestBody(query, options) {
|
|
1603
|
+
const requestOptions = { ...options ?? {} };
|
|
1604
|
+
delete requestOptions.stream;
|
|
1605
|
+
if (options === void 0 || !("contents" in options)) {
|
|
1606
|
+
return {
|
|
1607
|
+
query,
|
|
1608
|
+
...requestOptions,
|
|
1609
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
1613
|
+
delete requestOptions.contents;
|
|
1614
|
+
return { query, ...requestOptions };
|
|
1615
|
+
}
|
|
1616
|
+
return { query, ...requestOptions };
|
|
1617
|
+
}
|
|
1602
1618
|
/**
|
|
1603
1619
|
* Constructs the Exa API client.
|
|
1604
1620
|
* @param {string} apiKey - The API key for authentication.
|
|
@@ -1715,18 +1731,29 @@ var Exa2 = class {
|
|
|
1715
1731
|
return response;
|
|
1716
1732
|
}
|
|
1717
1733
|
async search(query, options) {
|
|
1718
|
-
if (options
|
|
1719
|
-
|
|
1720
|
-
query,
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
});
|
|
1724
|
-
}
|
|
1725
|
-
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
1726
|
-
const { contents, ...restOptions } = options;
|
|
1727
|
-
return await this.request("/search", "POST", { query, ...restOptions });
|
|
1734
|
+
if (options?.stream) {
|
|
1735
|
+
throw new ExaError(
|
|
1736
|
+
"For streaming responses, please use streamSearch() instead:\n\nfor await (const chunk of exa.streamSearch(query)) {\n // Handle chunks\n}",
|
|
1737
|
+
400 /* BadRequest */
|
|
1738
|
+
);
|
|
1728
1739
|
}
|
|
1729
|
-
return await this.request(
|
|
1740
|
+
return await this.request(
|
|
1741
|
+
"/search",
|
|
1742
|
+
"POST",
|
|
1743
|
+
this.buildSearchRequestBody(query, options)
|
|
1744
|
+
);
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Stream a search response as an async generator of OpenAI-style chat completion chunks.
|
|
1748
|
+
*
|
|
1749
|
+
* Each iteration yields a chunk with partial text (`content`) or new citations.
|
|
1750
|
+
* Use this if you'd like to read synthesized search output incrementally.
|
|
1751
|
+
*/
|
|
1752
|
+
streamSearch(query, options) {
|
|
1753
|
+
return this.streamChatCompletions("/search", {
|
|
1754
|
+
...this.buildSearchRequestBody(query, options),
|
|
1755
|
+
stream: true
|
|
1756
|
+
});
|
|
1730
1757
|
}
|
|
1731
1758
|
/**
|
|
1732
1759
|
* @deprecated Use `search()` instead. The search method now returns text contents by default.
|
|
@@ -1861,11 +1888,10 @@ var Exa2 = class {
|
|
|
1861
1888
|
outputSchema,
|
|
1862
1889
|
userLocation: options?.userLocation
|
|
1863
1890
|
};
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
});
|
|
1891
|
+
yield* this.streamChatCompletions("/answer", body);
|
|
1892
|
+
}
|
|
1893
|
+
async *streamChatCompletions(endpoint, body) {
|
|
1894
|
+
const response = await this.rawRequest(endpoint, "POST", body);
|
|
1869
1895
|
if (!response.ok) {
|
|
1870
1896
|
const message = await response.text();
|
|
1871
1897
|
throw new ExaError(message, response.status, (/* @__PURE__ */ new Date()).toISOString());
|