exa-js 1.8.18 → 1.8.20
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.mts +94 -36
- package/dist/index.d.ts +94 -36
- package/dist/index.js +45 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -3
package/dist/index.mjs
CHANGED
|
@@ -242,6 +242,7 @@ var MonitorRunStatus = /* @__PURE__ */ ((MonitorRunStatus2) => {
|
|
|
242
242
|
MonitorRunStatus2["running"] = "running";
|
|
243
243
|
MonitorRunStatus2["completed"] = "completed";
|
|
244
244
|
MonitorRunStatus2["canceled"] = "canceled";
|
|
245
|
+
MonitorRunStatus2["failed"] = "failed";
|
|
245
246
|
return MonitorRunStatus2;
|
|
246
247
|
})(MonitorRunStatus || {});
|
|
247
248
|
var MonitorRunType = /* @__PURE__ */ ((MonitorRunType2) => {
|
|
@@ -465,11 +466,14 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
465
466
|
/**
|
|
466
467
|
* List all Items for a Webset
|
|
467
468
|
* @param websetId The ID of the Webset
|
|
468
|
-
* @param params - Optional pagination parameters
|
|
469
|
+
* @param params - Optional pagination and filtering parameters
|
|
469
470
|
* @returns A promise that resolves with the list of Items
|
|
470
471
|
*/
|
|
471
472
|
list(websetId, params) {
|
|
472
|
-
const queryParams =
|
|
473
|
+
const queryParams = {
|
|
474
|
+
...this.buildPaginationParams(params),
|
|
475
|
+
sourceId: params?.sourceId
|
|
476
|
+
};
|
|
473
477
|
return this.request(
|
|
474
478
|
`/v0/websets/${websetId}/items`,
|
|
475
479
|
"GET",
|
|
@@ -757,7 +761,8 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
757
761
|
const params = {
|
|
758
762
|
cursor: options?.cursor,
|
|
759
763
|
limit: options?.limit,
|
|
760
|
-
eventType: options?.eventType
|
|
764
|
+
eventType: options?.eventType,
|
|
765
|
+
successful: options?.successful
|
|
761
766
|
};
|
|
762
767
|
return this.request(
|
|
763
768
|
`/v0/webhooks/${id}/attempts`,
|
|
@@ -953,6 +958,18 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
953
958
|
}
|
|
954
959
|
};
|
|
955
960
|
|
|
961
|
+
// src/zod-utils.ts
|
|
962
|
+
import { ZodType } from "zod";
|
|
963
|
+
import { zodToJsonSchema as convertZodToJsonSchema } from "zod-to-json-schema";
|
|
964
|
+
function isZodSchema(obj) {
|
|
965
|
+
return obj instanceof ZodType;
|
|
966
|
+
}
|
|
967
|
+
function zodToJsonSchema(schema) {
|
|
968
|
+
return convertZodToJsonSchema(schema, {
|
|
969
|
+
$refStrategy: "none"
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
|
|
956
973
|
// src/research/base.ts
|
|
957
974
|
var ResearchBaseClient = class {
|
|
958
975
|
/**
|
|
@@ -1013,23 +1030,17 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1013
1030
|
constructor(client) {
|
|
1014
1031
|
super(client);
|
|
1015
1032
|
}
|
|
1016
|
-
/**
|
|
1017
|
-
* Create a new research task.
|
|
1018
|
-
*
|
|
1019
|
-
* @param params Object containing:
|
|
1020
|
-
* - model: The research model to use (e.g., ResearchModel.ExaResearch).
|
|
1021
|
-
* - instructions: High-level guidance for the research agent.
|
|
1022
|
-
* - output: An object with a `schema` property (JSONSchema) that defines the expected output structure.
|
|
1023
|
-
*
|
|
1024
|
-
* @returns An object containing the unique ID of the created research task.
|
|
1025
|
-
*/
|
|
1026
1033
|
async createTask(params) {
|
|
1027
1034
|
const { instructions, model, output } = params;
|
|
1035
|
+
let schema = output?.schema;
|
|
1036
|
+
if (schema && isZodSchema(schema)) {
|
|
1037
|
+
schema = zodToJsonSchema(schema);
|
|
1038
|
+
}
|
|
1028
1039
|
const payload = {
|
|
1029
1040
|
instructions,
|
|
1030
1041
|
model: model ?? "exa-research",
|
|
1031
1042
|
output: output ? {
|
|
1032
|
-
schema
|
|
1043
|
+
schema,
|
|
1033
1044
|
inferSchema: output.inferSchema ?? true
|
|
1034
1045
|
} : { inferSchema: true }
|
|
1035
1046
|
};
|
|
@@ -1162,7 +1173,16 @@ var Exa2 = class {
|
|
|
1162
1173
|
contentsOptions.text = true;
|
|
1163
1174
|
}
|
|
1164
1175
|
if (text !== void 0) contentsOptions.text = text;
|
|
1165
|
-
if (summary !== void 0)
|
|
1176
|
+
if (summary !== void 0) {
|
|
1177
|
+
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema(summary.schema)) {
|
|
1178
|
+
contentsOptions.summary = {
|
|
1179
|
+
...summary,
|
|
1180
|
+
schema: zodToJsonSchema(summary.schema)
|
|
1181
|
+
};
|
|
1182
|
+
} else {
|
|
1183
|
+
contentsOptions.summary = summary;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1166
1186
|
if (highlights !== void 0) contentsOptions.highlights = highlights;
|
|
1167
1187
|
if (subpages !== void 0) contentsOptions.subpages = subpages;
|
|
1168
1188
|
if (subpageTarget !== void 0)
|
|
@@ -1355,28 +1375,6 @@ var Exa2 = class {
|
|
|
1355
1375
|
};
|
|
1356
1376
|
return await this.request("/contents", "POST", payload);
|
|
1357
1377
|
}
|
|
1358
|
-
/**
|
|
1359
|
-
* Generate an answer to a query.
|
|
1360
|
-
* @param {string} query - The question or query to answer.
|
|
1361
|
-
* @param {AnswerOptions} [options] - Additional options for answer generation.
|
|
1362
|
-
* @returns {Promise<AnswerResponse>} The generated answer and source references.
|
|
1363
|
-
*
|
|
1364
|
-
* Example with systemPrompt:
|
|
1365
|
-
* ```ts
|
|
1366
|
-
* const answer = await exa.answer("What is quantum computing?", {
|
|
1367
|
-
* text: true,
|
|
1368
|
-
* model: "exa",
|
|
1369
|
-
* systemPrompt: "Answer in a technical manner suitable for experts."
|
|
1370
|
-
* });
|
|
1371
|
-
* ```
|
|
1372
|
-
*
|
|
1373
|
-
* Note: For streaming responses, use the `streamAnswer` method:
|
|
1374
|
-
* ```ts
|
|
1375
|
-
* for await (const chunk of exa.streamAnswer(query)) {
|
|
1376
|
-
* // Handle chunks
|
|
1377
|
-
* }
|
|
1378
|
-
* ```
|
|
1379
|
-
*/
|
|
1380
1378
|
async answer(query, options) {
|
|
1381
1379
|
if (options?.stream) {
|
|
1382
1380
|
throw new ExaError(
|
|
@@ -1384,43 +1382,32 @@ var Exa2 = class {
|
|
|
1384
1382
|
400 /* BadRequest */
|
|
1385
1383
|
);
|
|
1386
1384
|
}
|
|
1385
|
+
let outputSchema = options?.outputSchema;
|
|
1386
|
+
if (outputSchema && isZodSchema(outputSchema)) {
|
|
1387
|
+
outputSchema = zodToJsonSchema(outputSchema);
|
|
1388
|
+
}
|
|
1387
1389
|
const requestBody = {
|
|
1388
1390
|
query,
|
|
1389
1391
|
stream: false,
|
|
1390
1392
|
text: options?.text ?? false,
|
|
1391
1393
|
model: options?.model ?? "exa",
|
|
1392
1394
|
systemPrompt: options?.systemPrompt,
|
|
1393
|
-
outputSchema
|
|
1395
|
+
outputSchema
|
|
1394
1396
|
};
|
|
1395
1397
|
return await this.request("/answer", "POST", requestBody);
|
|
1396
1398
|
}
|
|
1397
|
-
/**
|
|
1398
|
-
* Stream an answer as an async generator
|
|
1399
|
-
*
|
|
1400
|
-
* Each iteration yields a chunk with partial text (`content`) or new citations.
|
|
1401
|
-
* Use this if you'd like to read the answer incrementally, e.g. in a chat UI.
|
|
1402
|
-
*
|
|
1403
|
-
* Example usage:
|
|
1404
|
-
* ```ts
|
|
1405
|
-
* for await (const chunk of exa.streamAnswer("What is quantum computing?", {
|
|
1406
|
-
* text: false,
|
|
1407
|
-
* systemPrompt: "Answer in a concise manner suitable for beginners."
|
|
1408
|
-
* })) {
|
|
1409
|
-
* if (chunk.content) process.stdout.write(chunk.content);
|
|
1410
|
-
* if (chunk.citations) {
|
|
1411
|
-
* console.log("\nCitations: ", chunk.citations);
|
|
1412
|
-
* }
|
|
1413
|
-
* }
|
|
1414
|
-
* ```
|
|
1415
|
-
*/
|
|
1416
1399
|
async *streamAnswer(query, options) {
|
|
1400
|
+
let outputSchema = options?.outputSchema;
|
|
1401
|
+
if (outputSchema && isZodSchema(outputSchema)) {
|
|
1402
|
+
outputSchema = zodToJsonSchema(outputSchema);
|
|
1403
|
+
}
|
|
1417
1404
|
const body = {
|
|
1418
1405
|
query,
|
|
1419
1406
|
text: options?.text ?? false,
|
|
1420
1407
|
stream: true,
|
|
1421
1408
|
model: options?.model ?? "exa",
|
|
1422
1409
|
systemPrompt: options?.systemPrompt,
|
|
1423
|
-
outputSchema
|
|
1410
|
+
outputSchema
|
|
1424
1411
|
};
|
|
1425
1412
|
const response = await fetchImpl(this.baseURL + "/answer", {
|
|
1426
1413
|
method: "POST",
|