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.js
CHANGED
|
@@ -313,6 +313,7 @@ var MonitorRunStatus = /* @__PURE__ */ ((MonitorRunStatus2) => {
|
|
|
313
313
|
MonitorRunStatus2["running"] = "running";
|
|
314
314
|
MonitorRunStatus2["completed"] = "completed";
|
|
315
315
|
MonitorRunStatus2["canceled"] = "canceled";
|
|
316
|
+
MonitorRunStatus2["failed"] = "failed";
|
|
316
317
|
return MonitorRunStatus2;
|
|
317
318
|
})(MonitorRunStatus || {});
|
|
318
319
|
var MonitorRunType = /* @__PURE__ */ ((MonitorRunType2) => {
|
|
@@ -536,11 +537,14 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
536
537
|
/**
|
|
537
538
|
* List all Items for a Webset
|
|
538
539
|
* @param websetId The ID of the Webset
|
|
539
|
-
* @param params - Optional pagination parameters
|
|
540
|
+
* @param params - Optional pagination and filtering parameters
|
|
540
541
|
* @returns A promise that resolves with the list of Items
|
|
541
542
|
*/
|
|
542
543
|
list(websetId, params) {
|
|
543
|
-
const queryParams =
|
|
544
|
+
const queryParams = {
|
|
545
|
+
...this.buildPaginationParams(params),
|
|
546
|
+
sourceId: params?.sourceId
|
|
547
|
+
};
|
|
544
548
|
return this.request(
|
|
545
549
|
`/v0/websets/${websetId}/items`,
|
|
546
550
|
"GET",
|
|
@@ -828,7 +832,8 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
828
832
|
const params = {
|
|
829
833
|
cursor: options?.cursor,
|
|
830
834
|
limit: options?.limit,
|
|
831
|
-
eventType: options?.eventType
|
|
835
|
+
eventType: options?.eventType,
|
|
836
|
+
successful: options?.successful
|
|
832
837
|
};
|
|
833
838
|
return this.request(
|
|
834
839
|
`/v0/webhooks/${id}/attempts`,
|
|
@@ -1024,6 +1029,18 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
1024
1029
|
}
|
|
1025
1030
|
};
|
|
1026
1031
|
|
|
1032
|
+
// src/zod-utils.ts
|
|
1033
|
+
var import_zod = require("zod");
|
|
1034
|
+
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
1035
|
+
function isZodSchema(obj) {
|
|
1036
|
+
return obj instanceof import_zod.ZodType;
|
|
1037
|
+
}
|
|
1038
|
+
function zodToJsonSchema(schema) {
|
|
1039
|
+
return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, {
|
|
1040
|
+
$refStrategy: "none"
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1027
1044
|
// src/research/base.ts
|
|
1028
1045
|
var ResearchBaseClient = class {
|
|
1029
1046
|
/**
|
|
@@ -1084,23 +1101,17 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1084
1101
|
constructor(client) {
|
|
1085
1102
|
super(client);
|
|
1086
1103
|
}
|
|
1087
|
-
/**
|
|
1088
|
-
* Create a new research task.
|
|
1089
|
-
*
|
|
1090
|
-
* @param params Object containing:
|
|
1091
|
-
* - model: The research model to use (e.g., ResearchModel.ExaResearch).
|
|
1092
|
-
* - instructions: High-level guidance for the research agent.
|
|
1093
|
-
* - output: An object with a `schema` property (JSONSchema) that defines the expected output structure.
|
|
1094
|
-
*
|
|
1095
|
-
* @returns An object containing the unique ID of the created research task.
|
|
1096
|
-
*/
|
|
1097
1104
|
async createTask(params) {
|
|
1098
1105
|
const { instructions, model, output } = params;
|
|
1106
|
+
let schema = output?.schema;
|
|
1107
|
+
if (schema && isZodSchema(schema)) {
|
|
1108
|
+
schema = zodToJsonSchema(schema);
|
|
1109
|
+
}
|
|
1099
1110
|
const payload = {
|
|
1100
1111
|
instructions,
|
|
1101
1112
|
model: model ?? "exa-research",
|
|
1102
1113
|
output: output ? {
|
|
1103
|
-
schema
|
|
1114
|
+
schema,
|
|
1104
1115
|
inferSchema: output.inferSchema ?? true
|
|
1105
1116
|
} : { inferSchema: true }
|
|
1106
1117
|
};
|
|
@@ -1233,7 +1244,16 @@ var Exa2 = class {
|
|
|
1233
1244
|
contentsOptions.text = true;
|
|
1234
1245
|
}
|
|
1235
1246
|
if (text !== void 0) contentsOptions.text = text;
|
|
1236
|
-
if (summary !== void 0)
|
|
1247
|
+
if (summary !== void 0) {
|
|
1248
|
+
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema(summary.schema)) {
|
|
1249
|
+
contentsOptions.summary = {
|
|
1250
|
+
...summary,
|
|
1251
|
+
schema: zodToJsonSchema(summary.schema)
|
|
1252
|
+
};
|
|
1253
|
+
} else {
|
|
1254
|
+
contentsOptions.summary = summary;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1237
1257
|
if (highlights !== void 0) contentsOptions.highlights = highlights;
|
|
1238
1258
|
if (subpages !== void 0) contentsOptions.subpages = subpages;
|
|
1239
1259
|
if (subpageTarget !== void 0)
|
|
@@ -1426,28 +1446,6 @@ var Exa2 = class {
|
|
|
1426
1446
|
};
|
|
1427
1447
|
return await this.request("/contents", "POST", payload);
|
|
1428
1448
|
}
|
|
1429
|
-
/**
|
|
1430
|
-
* Generate an answer to a query.
|
|
1431
|
-
* @param {string} query - The question or query to answer.
|
|
1432
|
-
* @param {AnswerOptions} [options] - Additional options for answer generation.
|
|
1433
|
-
* @returns {Promise<AnswerResponse>} The generated answer and source references.
|
|
1434
|
-
*
|
|
1435
|
-
* Example with systemPrompt:
|
|
1436
|
-
* ```ts
|
|
1437
|
-
* const answer = await exa.answer("What is quantum computing?", {
|
|
1438
|
-
* text: true,
|
|
1439
|
-
* model: "exa",
|
|
1440
|
-
* systemPrompt: "Answer in a technical manner suitable for experts."
|
|
1441
|
-
* });
|
|
1442
|
-
* ```
|
|
1443
|
-
*
|
|
1444
|
-
* Note: For streaming responses, use the `streamAnswer` method:
|
|
1445
|
-
* ```ts
|
|
1446
|
-
* for await (const chunk of exa.streamAnswer(query)) {
|
|
1447
|
-
* // Handle chunks
|
|
1448
|
-
* }
|
|
1449
|
-
* ```
|
|
1450
|
-
*/
|
|
1451
1449
|
async answer(query, options) {
|
|
1452
1450
|
if (options?.stream) {
|
|
1453
1451
|
throw new ExaError(
|
|
@@ -1455,43 +1453,32 @@ var Exa2 = class {
|
|
|
1455
1453
|
400 /* BadRequest */
|
|
1456
1454
|
);
|
|
1457
1455
|
}
|
|
1456
|
+
let outputSchema = options?.outputSchema;
|
|
1457
|
+
if (outputSchema && isZodSchema(outputSchema)) {
|
|
1458
|
+
outputSchema = zodToJsonSchema(outputSchema);
|
|
1459
|
+
}
|
|
1458
1460
|
const requestBody = {
|
|
1459
1461
|
query,
|
|
1460
1462
|
stream: false,
|
|
1461
1463
|
text: options?.text ?? false,
|
|
1462
1464
|
model: options?.model ?? "exa",
|
|
1463
1465
|
systemPrompt: options?.systemPrompt,
|
|
1464
|
-
outputSchema
|
|
1466
|
+
outputSchema
|
|
1465
1467
|
};
|
|
1466
1468
|
return await this.request("/answer", "POST", requestBody);
|
|
1467
1469
|
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Stream an answer as an async generator
|
|
1470
|
-
*
|
|
1471
|
-
* Each iteration yields a chunk with partial text (`content`) or new citations.
|
|
1472
|
-
* Use this if you'd like to read the answer incrementally, e.g. in a chat UI.
|
|
1473
|
-
*
|
|
1474
|
-
* Example usage:
|
|
1475
|
-
* ```ts
|
|
1476
|
-
* for await (const chunk of exa.streamAnswer("What is quantum computing?", {
|
|
1477
|
-
* text: false,
|
|
1478
|
-
* systemPrompt: "Answer in a concise manner suitable for beginners."
|
|
1479
|
-
* })) {
|
|
1480
|
-
* if (chunk.content) process.stdout.write(chunk.content);
|
|
1481
|
-
* if (chunk.citations) {
|
|
1482
|
-
* console.log("\nCitations: ", chunk.citations);
|
|
1483
|
-
* }
|
|
1484
|
-
* }
|
|
1485
|
-
* ```
|
|
1486
|
-
*/
|
|
1487
1470
|
async *streamAnswer(query, options) {
|
|
1471
|
+
let outputSchema = options?.outputSchema;
|
|
1472
|
+
if (outputSchema && isZodSchema(outputSchema)) {
|
|
1473
|
+
outputSchema = zodToJsonSchema(outputSchema);
|
|
1474
|
+
}
|
|
1488
1475
|
const body = {
|
|
1489
1476
|
query,
|
|
1490
1477
|
text: options?.text ?? false,
|
|
1491
1478
|
stream: true,
|
|
1492
1479
|
model: options?.model ?? "exa",
|
|
1493
1480
|
systemPrompt: options?.systemPrompt,
|
|
1494
|
-
outputSchema
|
|
1481
|
+
outputSchema
|
|
1495
1482
|
};
|
|
1496
1483
|
const response = await fetchImpl(this.baseURL + "/answer", {
|
|
1497
1484
|
method: "POST",
|