exa-js 2.5.1-beta.2 → 2.6.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 +7 -1
- package/dist/index.d.mts +277 -8666
- package/dist/index.d.ts +277 -8666
- package/dist/index.js +64 -683
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -680
- 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.6.0",
|
|
8
8
|
description: "Exa SDK for Node.js and the browser",
|
|
9
9
|
publishConfig: {
|
|
10
10
|
access: "public"
|
|
@@ -88,639 +88,6 @@ var package_default = {
|
|
|
88
88
|
homepage: "https://github.com/exa-labs/exa-js#readme"
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
// src/nova/websets-client.ts
|
|
92
|
-
var WebsetsBaseClient = class {
|
|
93
|
-
constructor(client) {
|
|
94
|
-
this.client = client;
|
|
95
|
-
}
|
|
96
|
-
/** Make a request to the API, prepending `/websets` to the path. */
|
|
97
|
-
async request(endpoint, method = "POST", data, params, headers) {
|
|
98
|
-
return this.client.request(`/websets${endpoint}`, method, data, params, headers);
|
|
99
|
-
}
|
|
100
|
-
buildPaginationParams(pagination) {
|
|
101
|
-
const params = {};
|
|
102
|
-
if (!pagination) return params;
|
|
103
|
-
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
104
|
-
if (pagination.limit) params.limit = pagination.limit;
|
|
105
|
-
return params;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
109
|
-
async get(websetId, id) {
|
|
110
|
-
return this.request(`/v0/websets/${websetId}/items/${id}`, "GET");
|
|
111
|
-
}
|
|
112
|
-
async delete(websetId, id) {
|
|
113
|
-
return this.request(`/v0/websets/${websetId}/items/${id}`, "DELETE");
|
|
114
|
-
}
|
|
115
|
-
async list(websetId, options) {
|
|
116
|
-
const queryParams = { ...this.buildPaginationParams(options), sourceId: options?.sourceId };
|
|
117
|
-
return this.request(`/v0/websets/${websetId}/items`, "GET", void 0, queryParams);
|
|
118
|
-
}
|
|
119
|
-
/** Iterate through all items in a Webset, handling pagination automatically. */
|
|
120
|
-
async *listAll(websetId, options) {
|
|
121
|
-
let cursor = void 0;
|
|
122
|
-
const pageOptions = options ? { ...options } : {};
|
|
123
|
-
while (true) {
|
|
124
|
-
const response = await this.list(websetId, { ...pageOptions, cursor });
|
|
125
|
-
for (const item of response.data) {
|
|
126
|
-
yield item;
|
|
127
|
-
}
|
|
128
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
cursor = response.nextCursor;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/** Collect all items from a Webset into an array. */
|
|
135
|
-
async getAll(websetId, options) {
|
|
136
|
-
const items = [];
|
|
137
|
-
for await (const item of this.listAll(websetId, options)) {
|
|
138
|
-
items.push(item);
|
|
139
|
-
}
|
|
140
|
-
return items;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
var WebsetSearchesClient = class extends WebsetsBaseClient {
|
|
144
|
-
async create(websetId, params, options) {
|
|
145
|
-
return this.request(`/v0/websets/${websetId}/searches`, "POST", { ...params }, void 0, options?.headers);
|
|
146
|
-
}
|
|
147
|
-
async get(websetId, id) {
|
|
148
|
-
return this.request(`/v0/websets/${websetId}/searches/${id}`, "GET");
|
|
149
|
-
}
|
|
150
|
-
async cancel(websetId, id) {
|
|
151
|
-
return this.request(`/v0/websets/${websetId}/searches/${id}/cancel`, "POST");
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
155
|
-
async create(websetId, params) {
|
|
156
|
-
return this.request(`/v0/websets/${websetId}/enrichments`, "POST", { ...params });
|
|
157
|
-
}
|
|
158
|
-
async update(websetId, id, params) {
|
|
159
|
-
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "PATCH", { ...params });
|
|
160
|
-
}
|
|
161
|
-
async get(websetId, id) {
|
|
162
|
-
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "GET");
|
|
163
|
-
}
|
|
164
|
-
async delete(websetId, id) {
|
|
165
|
-
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "DELETE");
|
|
166
|
-
}
|
|
167
|
-
async cancel(websetId, id) {
|
|
168
|
-
return this.request(`/v0/websets/${websetId}/enrichments/${id}/cancel`, "POST");
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
var EventsClient = class extends WebsetsBaseClient {
|
|
172
|
-
async list(options) {
|
|
173
|
-
const queryParams = { ...this.buildPaginationParams(options), types: options?.types, createdBefore: options?.createdBefore, createdAfter: options?.createdAfter };
|
|
174
|
-
return this.request("/v0/events", "GET", void 0, queryParams);
|
|
175
|
-
}
|
|
176
|
-
async get(id) {
|
|
177
|
-
return this.request(`/v0/events/${id}`, "GET");
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
181
|
-
async list(monitorId) {
|
|
182
|
-
return this.request(`/v0/monitors/${monitorId}/runs`, "GET");
|
|
183
|
-
}
|
|
184
|
-
async get(monitorId, id) {
|
|
185
|
-
return this.request(`/v0/monitors/${monitorId}/runs/${id}`, "GET");
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
189
|
-
constructor(client) {
|
|
190
|
-
super(client);
|
|
191
|
-
this.runs = new WebsetMonitorRunsClient(client);
|
|
192
|
-
}
|
|
193
|
-
async create(params) {
|
|
194
|
-
return this.request("/v0/monitors", "POST", { ...params });
|
|
195
|
-
}
|
|
196
|
-
async list(options) {
|
|
197
|
-
const queryParams = { ...this.buildPaginationParams(options), websetId: options?.websetId };
|
|
198
|
-
return this.request("/v0/monitors", "GET", void 0, queryParams);
|
|
199
|
-
}
|
|
200
|
-
async get(id) {
|
|
201
|
-
return this.request(`/v0/monitors/${id}`, "GET");
|
|
202
|
-
}
|
|
203
|
-
async update(id, params) {
|
|
204
|
-
return this.request(`/v0/monitors/${id}`, "PATCH", { ...params });
|
|
205
|
-
}
|
|
206
|
-
async delete(id) {
|
|
207
|
-
return this.request(`/v0/monitors/${id}`, "DELETE");
|
|
208
|
-
}
|
|
209
|
-
/** Iterate through all monitors, handling pagination automatically. */
|
|
210
|
-
async *listAll(options) {
|
|
211
|
-
let cursor = void 0;
|
|
212
|
-
const pageOptions = options ? { ...options } : {};
|
|
213
|
-
while (true) {
|
|
214
|
-
const response = await this.list({ ...pageOptions, cursor });
|
|
215
|
-
for (const monitor of response.data) {
|
|
216
|
-
yield monitor;
|
|
217
|
-
}
|
|
218
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
cursor = response.nextCursor;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/** Collect all monitors into an array. */
|
|
225
|
-
async getAll(options) {
|
|
226
|
-
const monitors = [];
|
|
227
|
-
for await (const monitor of this.listAll(options)) {
|
|
228
|
-
monitors.push(monitor);
|
|
229
|
-
}
|
|
230
|
-
return monitors;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
234
|
-
async create(params) {
|
|
235
|
-
return this.request("/v0/webhooks", "POST", { ...params });
|
|
236
|
-
}
|
|
237
|
-
async list(options) {
|
|
238
|
-
const queryParams = this.buildPaginationParams(options);
|
|
239
|
-
return this.request("/v0/webhooks", "GET", void 0, queryParams);
|
|
240
|
-
}
|
|
241
|
-
async get(id) {
|
|
242
|
-
return this.request(`/v0/webhooks/${id}`, "GET");
|
|
243
|
-
}
|
|
244
|
-
async update(id, params) {
|
|
245
|
-
return this.request(`/v0/webhooks/${id}`, "PATCH", { ...params });
|
|
246
|
-
}
|
|
247
|
-
async delete(id) {
|
|
248
|
-
return this.request(`/v0/webhooks/${id}`, "DELETE");
|
|
249
|
-
}
|
|
250
|
-
async listAttempts(id, options) {
|
|
251
|
-
const queryParams = { ...this.buildPaginationParams(options), eventType: options?.eventType, successful: options?.successful };
|
|
252
|
-
return this.request(`/v0/webhooks/${id}/attempts`, "GET", void 0, queryParams);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
var ImportsClient = class extends WebsetsBaseClient {
|
|
256
|
-
async create(params) {
|
|
257
|
-
return this.request("/v0/imports", "POST", { ...params });
|
|
258
|
-
}
|
|
259
|
-
async list(options) {
|
|
260
|
-
const queryParams = this.buildPaginationParams(options);
|
|
261
|
-
return this.request("/v0/imports", "GET", void 0, queryParams);
|
|
262
|
-
}
|
|
263
|
-
async get(id) {
|
|
264
|
-
return this.request(`/v0/imports/${id}`, "GET");
|
|
265
|
-
}
|
|
266
|
-
async update(id, params) {
|
|
267
|
-
return this.request(`/v0/imports/${id}`, "PATCH", { ...params });
|
|
268
|
-
}
|
|
269
|
-
async delete(id) {
|
|
270
|
-
return this.request(`/v0/imports/${id}`, "DELETE");
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
var WebsetsClient = class extends WebsetsBaseClient {
|
|
274
|
-
constructor(client) {
|
|
275
|
-
super(client);
|
|
276
|
-
this.items = new WebsetItemsClient(client);
|
|
277
|
-
this.searches = new WebsetSearchesClient(client);
|
|
278
|
-
this.enrichments = new WebsetEnrichmentsClient(client);
|
|
279
|
-
this.events = new EventsClient(client);
|
|
280
|
-
this.monitors = new WebsetMonitorsClient(client);
|
|
281
|
-
this.webhooks = new WebsetWebhooksClient(client);
|
|
282
|
-
this.imports = new ImportsClient(client);
|
|
283
|
-
}
|
|
284
|
-
async create(params, options) {
|
|
285
|
-
return this.request("/v0/websets", "POST", { ...params }, void 0, options?.headers);
|
|
286
|
-
}
|
|
287
|
-
async list(options) {
|
|
288
|
-
const queryParams = { ...this.buildPaginationParams(options), search: options?.search };
|
|
289
|
-
return this.request("/v0/websets", "GET", void 0, queryParams);
|
|
290
|
-
}
|
|
291
|
-
async get(id, options) {
|
|
292
|
-
const queryParams = { expand: options?.expand };
|
|
293
|
-
return this.request(`/v0/websets/${id}`, "GET", void 0, queryParams);
|
|
294
|
-
}
|
|
295
|
-
async update(id, params) {
|
|
296
|
-
return this.request(`/v0/websets/${id}`, "POST", { ...params });
|
|
297
|
-
}
|
|
298
|
-
async delete(id) {
|
|
299
|
-
return this.request(`/v0/websets/${id}`, "DELETE");
|
|
300
|
-
}
|
|
301
|
-
async cancel(id) {
|
|
302
|
-
return this.request(`/v0/websets/${id}/cancel`, "POST");
|
|
303
|
-
}
|
|
304
|
-
async preview(params, options) {
|
|
305
|
-
const queryParams = { search: options?.search };
|
|
306
|
-
return this.request("/v0/websets/preview", "POST", { ...params }, queryParams);
|
|
307
|
-
}
|
|
308
|
-
/** Iterate through all Websets, handling pagination automatically. */
|
|
309
|
-
async *listAll(options) {
|
|
310
|
-
let cursor = void 0;
|
|
311
|
-
const pageOptions = options ? { ...options } : {};
|
|
312
|
-
while (true) {
|
|
313
|
-
const response = await this.list({ ...pageOptions, cursor });
|
|
314
|
-
for (const webset of response.data) {
|
|
315
|
-
yield webset;
|
|
316
|
-
}
|
|
317
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
cursor = response.nextCursor;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
/** Collect all Websets into an array. */
|
|
324
|
-
async getAll(options) {
|
|
325
|
-
const websets = [];
|
|
326
|
-
for await (const webset of this.listAll(options)) {
|
|
327
|
-
websets.push(webset);
|
|
328
|
-
}
|
|
329
|
-
return websets;
|
|
330
|
-
}
|
|
331
|
-
/** Poll until a Webset reaches idle status. */
|
|
332
|
-
async waitUntilIdle(id, options) {
|
|
333
|
-
let timeout;
|
|
334
|
-
let pollInterval = 1e3;
|
|
335
|
-
let onPoll;
|
|
336
|
-
if (typeof options === "number") {
|
|
337
|
-
timeout = options;
|
|
338
|
-
} else if (options) {
|
|
339
|
-
timeout = options.timeout;
|
|
340
|
-
pollInterval = options.pollInterval || 1e3;
|
|
341
|
-
onPoll = options.onPoll;
|
|
342
|
-
}
|
|
343
|
-
const startTime = Date.now();
|
|
344
|
-
while (true) {
|
|
345
|
-
const webset = await this.get(id);
|
|
346
|
-
if (onPoll) onPoll(webset.status);
|
|
347
|
-
if (webset.status === "idle") return webset;
|
|
348
|
-
if (timeout && Date.now() - startTime > timeout) {
|
|
349
|
-
throw new Error(`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`);
|
|
350
|
-
}
|
|
351
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
// src/nova/research-client.ts
|
|
357
|
-
import { ZodType } from "zod";
|
|
358
|
-
import { zodToJsonSchema as zodToJsonSchemaLib } from "zod-to-json-schema";
|
|
359
|
-
function zodToJsonSchema(schema) {
|
|
360
|
-
return zodToJsonSchemaLib(schema, { $refStrategy: "none" });
|
|
361
|
-
}
|
|
362
|
-
var ResearchBaseClient = class {
|
|
363
|
-
constructor(client) {
|
|
364
|
-
this.client = client;
|
|
365
|
-
}
|
|
366
|
-
/** Make a request to the API, prepending `/research/v1` to the path. */
|
|
367
|
-
async request(endpoint, method = "POST", data, params) {
|
|
368
|
-
return this.client.request(`/research/v1${endpoint}`, method, data, params);
|
|
369
|
-
}
|
|
370
|
-
buildPaginationParams(pagination) {
|
|
371
|
-
const params = {};
|
|
372
|
-
if (!pagination) return params;
|
|
373
|
-
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
374
|
-
if (pagination.limit) params.limit = pagination.limit;
|
|
375
|
-
return params;
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
var ResearchClient = class extends ResearchBaseClient {
|
|
379
|
-
/** List research requests. */
|
|
380
|
-
async list(options) {
|
|
381
|
-
const params = this.buildPaginationParams(options);
|
|
382
|
-
return this.client.request("/research/v1", "GET", void 0, params);
|
|
383
|
-
}
|
|
384
|
-
/** Create a new research request. Defaults model to "exa-research-fast" if not provided. */
|
|
385
|
-
async create(params) {
|
|
386
|
-
let schema = params.outputSchema;
|
|
387
|
-
if (schema instanceof ZodType) {
|
|
388
|
-
schema = zodToJsonSchema(schema);
|
|
389
|
-
}
|
|
390
|
-
const payload = {
|
|
391
|
-
instructions: params.instructions,
|
|
392
|
-
model: params.model ?? "exa-research-fast"
|
|
393
|
-
};
|
|
394
|
-
if (schema) {
|
|
395
|
-
payload.outputSchema = schema;
|
|
396
|
-
}
|
|
397
|
-
return this.client.request("/research/v1", "POST", payload, void 0);
|
|
398
|
-
}
|
|
399
|
-
/** Get a research request by ID. */
|
|
400
|
-
async get(researchId, options) {
|
|
401
|
-
const params = {};
|
|
402
|
-
if (options?.events !== void 0) params.events = options.events.toString();
|
|
403
|
-
return this.client.request(`/research/v1/${researchId}`, "GET", void 0, params);
|
|
404
|
-
}
|
|
405
|
-
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
406
|
-
async pollUntilFinished(researchId, options) {
|
|
407
|
-
const pollInterval = options?.pollInterval ?? 1e3;
|
|
408
|
-
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
409
|
-
const maxConsecutiveFailures = 5;
|
|
410
|
-
const startTime = Date.now();
|
|
411
|
-
let consecutiveFailures = 0;
|
|
412
|
-
while (true) {
|
|
413
|
-
try {
|
|
414
|
-
const research = await this.get(researchId, { events: options?.events });
|
|
415
|
-
consecutiveFailures = 0;
|
|
416
|
-
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
417
|
-
return research;
|
|
418
|
-
}
|
|
419
|
-
} catch (err) {
|
|
420
|
-
consecutiveFailures += 1;
|
|
421
|
-
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
422
|
-
throw new Error(`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (Date.now() - startTime > timeoutMs) {
|
|
426
|
-
throw new Error(`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`);
|
|
427
|
-
}
|
|
428
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
// src/nova/client.ts
|
|
434
|
-
function isRecord(value) {
|
|
435
|
-
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
436
|
-
}
|
|
437
|
-
var ExaError = class extends Error {
|
|
438
|
-
constructor(message, statusCode, timestamp, path, details) {
|
|
439
|
-
super(message);
|
|
440
|
-
this.name = "ExaError";
|
|
441
|
-
this.statusCode = statusCode;
|
|
442
|
-
this.timestamp = timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
443
|
-
this.path = path;
|
|
444
|
-
this.details = details;
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
var CONTENTS_FIELDS = /* @__PURE__ */ new Set(["text", "highlights", "summary", "subpages", "subpageTarget", "extras", "livecrawl", "livecrawlTimeout", "maxAgeHours", "filterEmptyResults", "context"]);
|
|
448
|
-
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
449
|
-
var Exa = class {
|
|
450
|
-
constructor(apiKey, baseURL = "https://api.exa.ai") {
|
|
451
|
-
this.baseURL = baseURL;
|
|
452
|
-
if (!apiKey) {
|
|
453
|
-
apiKey = typeof process !== "undefined" ? process.env?.EXA_API_KEY : void 0;
|
|
454
|
-
if (!apiKey) {
|
|
455
|
-
throw new ExaError(
|
|
456
|
-
"API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
|
|
457
|
-
401
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
this.headers = {
|
|
462
|
-
"x-api-key": apiKey,
|
|
463
|
-
"Content-Type": "application/json"
|
|
464
|
-
};
|
|
465
|
-
this.websets = new WebsetsClient(this);
|
|
466
|
-
this.research = new ResearchClient(this);
|
|
467
|
-
}
|
|
468
|
-
/** Make a request to the Exa API. Used by sub-clients and available for direct use. */
|
|
469
|
-
async request(endpoint, method, body, params, headers) {
|
|
470
|
-
const url = this.buildRequestUrl(endpoint, params);
|
|
471
|
-
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
472
|
-
const combinedHeaders = headers ? { ...this.headers, ...headers } : this.headers;
|
|
473
|
-
const response = await fetch(url, {
|
|
474
|
-
method,
|
|
475
|
-
headers: combinedHeaders,
|
|
476
|
-
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
477
|
-
});
|
|
478
|
-
if (!response.ok) {
|
|
479
|
-
throw await this.toExaError(response, endpoint);
|
|
480
|
-
}
|
|
481
|
-
return await response.json();
|
|
482
|
-
}
|
|
483
|
-
/** Make a raw request returning the Response object directly. */
|
|
484
|
-
async rawRequest(endpoint, method = "POST", body, params) {
|
|
485
|
-
const url = this.buildRequestUrl(endpoint, params);
|
|
486
|
-
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
487
|
-
return fetch(url, {
|
|
488
|
-
method,
|
|
489
|
-
headers: this.headers,
|
|
490
|
-
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
/** Normalize category values to underscore form. */
|
|
494
|
-
normalizeCategoryInBody(body) {
|
|
495
|
-
if (body == null || typeof body.category !== "string") {
|
|
496
|
-
return body;
|
|
497
|
-
}
|
|
498
|
-
return { ...body, category: body.category.replace(/ /g, "_") };
|
|
499
|
-
}
|
|
500
|
-
buildRequestUrl(endpoint, params) {
|
|
501
|
-
let url = `${this.baseURL}${endpoint}`;
|
|
502
|
-
if (params == null || Object.keys(params).length === 0) {
|
|
503
|
-
return url;
|
|
504
|
-
}
|
|
505
|
-
const searchParams = new URLSearchParams();
|
|
506
|
-
for (const [key, value] of Object.entries(params)) {
|
|
507
|
-
if (Array.isArray(value)) {
|
|
508
|
-
for (const item of value) {
|
|
509
|
-
searchParams.append(key, item);
|
|
510
|
-
}
|
|
511
|
-
} else if (value !== void 0) {
|
|
512
|
-
searchParams.append(key, String(value));
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
url += `?${searchParams.toString()}`;
|
|
516
|
-
return url;
|
|
517
|
-
}
|
|
518
|
-
tryParseJsonRecord(text) {
|
|
519
|
-
if (text.length === 0) {
|
|
520
|
-
return null;
|
|
521
|
-
}
|
|
522
|
-
try {
|
|
523
|
-
const parsed = JSON.parse(text);
|
|
524
|
-
return isRecord(parsed) ? parsed : null;
|
|
525
|
-
} catch {
|
|
526
|
-
return null;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
async toExaError(response, endpoint) {
|
|
530
|
-
const text = await response.text();
|
|
531
|
-
const parsed = this.tryParseJsonRecord(text);
|
|
532
|
-
const statusCode = parsed != null && typeof parsed.statusCode === "number" ? parsed.statusCode : response.status;
|
|
533
|
-
const timestamp = parsed != null && typeof parsed.timestamp === "string" ? parsed.timestamp : void 0;
|
|
534
|
-
const path = parsed != null && typeof parsed.path === "string" ? parsed.path : endpoint;
|
|
535
|
-
const errorMessage = parsed != null && typeof parsed.error === "string" ? parsed.error : void 0;
|
|
536
|
-
const detailMessage = parsed != null && typeof parsed.message === "string" ? parsed.message : void 0;
|
|
537
|
-
let message;
|
|
538
|
-
if (errorMessage != null && detailMessage != null) {
|
|
539
|
-
message = `${errorMessage}. ${detailMessage}`;
|
|
540
|
-
} else if (errorMessage != null) {
|
|
541
|
-
message = errorMessage;
|
|
542
|
-
} else if (detailMessage != null) {
|
|
543
|
-
message = detailMessage;
|
|
544
|
-
} else if (text.length > 0) {
|
|
545
|
-
message = text;
|
|
546
|
-
} else {
|
|
547
|
-
message = `Exa API error ${response.status}`;
|
|
548
|
-
}
|
|
549
|
-
return new ExaError(message, statusCode, timestamp, path, parsed ?? text);
|
|
550
|
-
}
|
|
551
|
-
parseAnswerStreamLine(line) {
|
|
552
|
-
if (!line.startsWith("data:")) {
|
|
553
|
-
return null;
|
|
554
|
-
}
|
|
555
|
-
const jsonStr = line.replace(/^data:\s*/, "").trim();
|
|
556
|
-
if (jsonStr.length === 0 || jsonStr === "[DONE]") {
|
|
557
|
-
return null;
|
|
558
|
-
}
|
|
559
|
-
let parsedChunk;
|
|
560
|
-
try {
|
|
561
|
-
parsedChunk = JSON.parse(jsonStr);
|
|
562
|
-
} catch {
|
|
563
|
-
return null;
|
|
564
|
-
}
|
|
565
|
-
if (!isRecord(parsedChunk)) {
|
|
566
|
-
return null;
|
|
567
|
-
}
|
|
568
|
-
let content;
|
|
569
|
-
const choices = parsedChunk.choices;
|
|
570
|
-
if (Array.isArray(choices) && choices.length > 0 && isRecord(choices[0])) {
|
|
571
|
-
const delta = choices[0].delta;
|
|
572
|
-
if (isRecord(delta) && typeof delta.content === "string") {
|
|
573
|
-
content = delta.content;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
let citations;
|
|
577
|
-
if (Array.isArray(parsedChunk.citations)) {
|
|
578
|
-
const normalized = [];
|
|
579
|
-
for (const citation of parsedChunk.citations) {
|
|
580
|
-
if (!isRecord(citation)) {
|
|
581
|
-
continue;
|
|
582
|
-
}
|
|
583
|
-
const id = typeof citation.id === "string" ? citation.id : void 0;
|
|
584
|
-
const url = typeof citation.url === "string" ? citation.url : void 0;
|
|
585
|
-
const title = typeof citation.title === "string" ? citation.title : void 0;
|
|
586
|
-
const publishedDate = typeof citation.publishedDate === "string" ? citation.publishedDate : void 0;
|
|
587
|
-
const author = typeof citation.author === "string" ? citation.author : void 0;
|
|
588
|
-
const text = typeof citation.text === "string" ? citation.text : void 0;
|
|
589
|
-
normalized.push({
|
|
590
|
-
...id != null ? { id } : {},
|
|
591
|
-
...url != null ? { url } : {},
|
|
592
|
-
...title != null ? { title } : {},
|
|
593
|
-
...publishedDate != null ? { publishedDate } : {},
|
|
594
|
-
...author != null ? { author } : {},
|
|
595
|
-
...text != null ? { text } : {}
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
if (normalized.length > 0) {
|
|
599
|
-
citations = normalized;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
if (content == null && (citations == null || citations.length === 0)) {
|
|
603
|
-
return null;
|
|
604
|
-
}
|
|
605
|
-
return {
|
|
606
|
-
...content != null ? { content } : {},
|
|
607
|
-
...citations != null ? { citations } : {}
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
/** Separate content-specific options from search/filter options. */
|
|
611
|
-
extractContentsOptions(options) {
|
|
612
|
-
const contentsOptions = {};
|
|
613
|
-
const restOptions = {};
|
|
614
|
-
let hasContentField = false;
|
|
615
|
-
for (const [key, value] of Object.entries(options)) {
|
|
616
|
-
if (CONTENTS_FIELDS.has(key)) {
|
|
617
|
-
contentsOptions[key] = value;
|
|
618
|
-
hasContentField = true;
|
|
619
|
-
} else {
|
|
620
|
-
restOptions[key] = value;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
if (!hasContentField) {
|
|
624
|
-
contentsOptions.text = { maxCharacters: DEFAULT_MAX_CHARACTERS };
|
|
625
|
-
}
|
|
626
|
-
return { contentsOptions, restOptions };
|
|
627
|
-
}
|
|
628
|
-
search(query, options) {
|
|
629
|
-
let body;
|
|
630
|
-
if (options === void 0 || !("contents" in options)) {
|
|
631
|
-
body = { query, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
|
|
632
|
-
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
633
|
-
const { contents, ...restOptions } = options;
|
|
634
|
-
body = { query, ...restOptions };
|
|
635
|
-
} else {
|
|
636
|
-
body = { query, ...options };
|
|
637
|
-
}
|
|
638
|
-
return this.request("/search", "POST", body);
|
|
639
|
-
}
|
|
640
|
-
findSimilar(url, options) {
|
|
641
|
-
let body;
|
|
642
|
-
if (options === void 0 || !("contents" in options)) {
|
|
643
|
-
body = { url, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
|
|
644
|
-
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
645
|
-
const { contents, ...restOptions } = options;
|
|
646
|
-
body = { url, ...restOptions };
|
|
647
|
-
} else {
|
|
648
|
-
body = { url, ...options };
|
|
649
|
-
}
|
|
650
|
-
return this.request("/findSimilar", "POST", body);
|
|
651
|
-
}
|
|
652
|
-
getContents(urls, options) {
|
|
653
|
-
return this.request("/contents", "POST", { urls, ...options });
|
|
654
|
-
}
|
|
655
|
-
answer(query, options) {
|
|
656
|
-
if (options?.stream) {
|
|
657
|
-
throw new ExaError("For streaming responses, please use streamAnswer() instead:\n\nfor await (const chunk of exa.streamAnswer(query)) {\n // Handle chunks\n}", 400);
|
|
658
|
-
}
|
|
659
|
-
return this.request("/answer", "POST", { query, model: "exa", stream: false, text: false, ...options });
|
|
660
|
-
}
|
|
661
|
-
async *streamAnswer(query, options) {
|
|
662
|
-
const response = await this.rawRequest("/answer", "POST", { query, model: "exa", text: false, ...options, stream: true });
|
|
663
|
-
if (!response.ok) {
|
|
664
|
-
throw await this.toExaError(response, "/answer");
|
|
665
|
-
}
|
|
666
|
-
const reader = response.body?.getReader();
|
|
667
|
-
if (!reader) {
|
|
668
|
-
throw new ExaError("No response body available for streaming.", 500, (/* @__PURE__ */ new Date()).toISOString(), "/answer");
|
|
669
|
-
}
|
|
670
|
-
const decoder = new TextDecoder();
|
|
671
|
-
let buffer = "";
|
|
672
|
-
try {
|
|
673
|
-
while (true) {
|
|
674
|
-
const { done, value } = await reader.read();
|
|
675
|
-
if (done) break;
|
|
676
|
-
buffer += decoder.decode(value, { stream: true });
|
|
677
|
-
const lines = buffer.split("\n");
|
|
678
|
-
buffer = lines.pop() ?? "";
|
|
679
|
-
for (const line of lines) {
|
|
680
|
-
const chunk = this.parseAnswerStreamLine(line);
|
|
681
|
-
if (chunk != null) {
|
|
682
|
-
yield chunk;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
const trailingChunk = this.parseAnswerStreamLine(buffer);
|
|
687
|
-
if (trailingChunk != null) {
|
|
688
|
-
yield trailingChunk;
|
|
689
|
-
}
|
|
690
|
-
} finally {
|
|
691
|
-
reader.releaseLock();
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* @deprecated Use `search()` instead. The search method now returns text contents by default.
|
|
696
|
-
* Search with contents. Extracts content fields (text, highlights, summary, etc.) into a `contents` wrapper.
|
|
697
|
-
*/
|
|
698
|
-
async searchAndContents(query, options) {
|
|
699
|
-
if (options === void 0) {
|
|
700
|
-
return this.request("/search", "POST", {
|
|
701
|
-
query,
|
|
702
|
-
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
706
|
-
return this.request("/search", "POST", { query, contents: contentsOptions, ...restOptions });
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
|
|
710
|
-
* Find similar with contents. Extracts content fields into a `contents` wrapper.
|
|
711
|
-
*/
|
|
712
|
-
async findSimilarAndContents(url, options) {
|
|
713
|
-
if (options === void 0) {
|
|
714
|
-
return this.request("/findSimilar", "POST", {
|
|
715
|
-
url,
|
|
716
|
-
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
720
|
-
return this.request("/findSimilar", "POST", { url, contents: contentsOptions, ...restOptions });
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
|
|
724
91
|
// src/errors.ts
|
|
725
92
|
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
726
93
|
HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
|
|
@@ -733,21 +100,37 @@ var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
|
733
100
|
HttpStatusCode2[HttpStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
734
101
|
return HttpStatusCode2;
|
|
735
102
|
})(HttpStatusCode || {});
|
|
103
|
+
var ExaError = class extends Error {
|
|
104
|
+
/**
|
|
105
|
+
* Create a new ExaError
|
|
106
|
+
* @param message Error message
|
|
107
|
+
* @param statusCode HTTP status code
|
|
108
|
+
* @param timestamp ISO timestamp from API
|
|
109
|
+
* @param path Path that caused the error
|
|
110
|
+
*/
|
|
111
|
+
constructor(message, statusCode, timestamp, path) {
|
|
112
|
+
super(message);
|
|
113
|
+
this.name = "ExaError";
|
|
114
|
+
this.statusCode = statusCode;
|
|
115
|
+
this.timestamp = timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
116
|
+
this.path = path;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
736
119
|
|
|
737
120
|
// src/zod-utils.ts
|
|
738
|
-
import { ZodType
|
|
121
|
+
import { ZodType } from "zod";
|
|
739
122
|
import { zodToJsonSchema as convertZodToJsonSchema } from "zod-to-json-schema";
|
|
740
123
|
function isZodSchema(obj) {
|
|
741
|
-
return obj instanceof
|
|
124
|
+
return obj instanceof ZodType;
|
|
742
125
|
}
|
|
743
|
-
function
|
|
126
|
+
function zodToJsonSchema(schema) {
|
|
744
127
|
return convertZodToJsonSchema(schema, {
|
|
745
128
|
$refStrategy: "none"
|
|
746
129
|
});
|
|
747
130
|
}
|
|
748
131
|
|
|
749
132
|
// src/research/base.ts
|
|
750
|
-
var
|
|
133
|
+
var ResearchBaseClient = class {
|
|
751
134
|
constructor(client) {
|
|
752
135
|
this.client = client;
|
|
753
136
|
}
|
|
@@ -777,7 +160,7 @@ var ResearchBaseClient2 = class {
|
|
|
777
160
|
};
|
|
778
161
|
|
|
779
162
|
// src/research/client.ts
|
|
780
|
-
var
|
|
163
|
+
var ResearchClient = class extends ResearchBaseClient {
|
|
781
164
|
constructor(client) {
|
|
782
165
|
super(client);
|
|
783
166
|
}
|
|
@@ -785,7 +168,7 @@ var ResearchClient2 = class extends ResearchBaseClient2 {
|
|
|
785
168
|
const { instructions, model, outputSchema } = params;
|
|
786
169
|
let schema = outputSchema;
|
|
787
170
|
if (schema && isZodSchema(schema)) {
|
|
788
|
-
schema =
|
|
171
|
+
schema = zodToJsonSchema(schema);
|
|
789
172
|
}
|
|
790
173
|
const payload = {
|
|
791
174
|
instructions,
|
|
@@ -902,7 +285,7 @@ var ResearchClient2 = class extends ResearchBaseClient2 {
|
|
|
902
285
|
};
|
|
903
286
|
|
|
904
287
|
// src/websets/base.ts
|
|
905
|
-
var
|
|
288
|
+
var WebsetsBaseClient = class {
|
|
906
289
|
/**
|
|
907
290
|
* Initialize a new Websets base client
|
|
908
291
|
* @param client The Exa client instance
|
|
@@ -943,7 +326,7 @@ var WebsetsBaseClient2 = class {
|
|
|
943
326
|
};
|
|
944
327
|
|
|
945
328
|
// src/websets/enrichments.ts
|
|
946
|
-
var
|
|
329
|
+
var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
947
330
|
/**
|
|
948
331
|
* Create an Enrichment for a Webset
|
|
949
332
|
* @param websetId The ID of the Webset
|
|
@@ -1010,7 +393,7 @@ var WebsetEnrichmentsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1010
393
|
};
|
|
1011
394
|
|
|
1012
395
|
// src/websets/events.ts
|
|
1013
|
-
var
|
|
396
|
+
var EventsClient = class extends WebsetsBaseClient {
|
|
1014
397
|
/**
|
|
1015
398
|
* Initialize a new Events client
|
|
1016
399
|
* @param client The Exa client instance
|
|
@@ -1242,7 +625,7 @@ var WebsetSearchCanceledReason = /* @__PURE__ */ ((WebsetSearchCanceledReason2)
|
|
|
1242
625
|
})(WebsetSearchCanceledReason || {});
|
|
1243
626
|
|
|
1244
627
|
// src/websets/imports.ts
|
|
1245
|
-
var
|
|
628
|
+
var ImportsClient = class extends WebsetsBaseClient {
|
|
1246
629
|
async create(params, csv) {
|
|
1247
630
|
if (csv === void 0) {
|
|
1248
631
|
return this.request(
|
|
@@ -1425,7 +808,7 @@ var ImportsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1425
808
|
};
|
|
1426
809
|
|
|
1427
810
|
// src/websets/items.ts
|
|
1428
|
-
var
|
|
811
|
+
var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
1429
812
|
/**
|
|
1430
813
|
* List all Items for a Webset
|
|
1431
814
|
* @param websetId The ID of the Webset
|
|
@@ -1505,7 +888,7 @@ var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1505
888
|
};
|
|
1506
889
|
|
|
1507
890
|
// src/websets/monitors.ts
|
|
1508
|
-
var
|
|
891
|
+
var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
1509
892
|
/**
|
|
1510
893
|
* List all runs for a Monitor
|
|
1511
894
|
* @param monitorId The ID of the Monitor
|
|
@@ -1534,10 +917,10 @@ var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1534
917
|
);
|
|
1535
918
|
}
|
|
1536
919
|
};
|
|
1537
|
-
var
|
|
920
|
+
var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
1538
921
|
constructor(client) {
|
|
1539
922
|
super(client);
|
|
1540
|
-
this.runs = new
|
|
923
|
+
this.runs = new WebsetMonitorRunsClient(client);
|
|
1541
924
|
}
|
|
1542
925
|
/**
|
|
1543
926
|
* Create a Monitor
|
|
@@ -1625,7 +1008,7 @@ var WebsetMonitorsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1625
1008
|
};
|
|
1626
1009
|
|
|
1627
1010
|
// src/websets/searches.ts
|
|
1628
|
-
var
|
|
1011
|
+
var WebsetSearchesClient = class extends WebsetsBaseClient {
|
|
1629
1012
|
/**
|
|
1630
1013
|
* Create a new Search for the Webset
|
|
1631
1014
|
* @param websetId The ID of the Webset
|
|
@@ -1668,7 +1051,7 @@ var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
|
|
|
1668
1051
|
};
|
|
1669
1052
|
|
|
1670
1053
|
// src/websets/webhooks.ts
|
|
1671
|
-
var
|
|
1054
|
+
var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
1672
1055
|
/**
|
|
1673
1056
|
* Create a Webhook
|
|
1674
1057
|
* @param params The webhook parameters
|
|
@@ -1805,20 +1188,20 @@ var WebsetWebhooksClient2 = class extends WebsetsBaseClient2 {
|
|
|
1805
1188
|
};
|
|
1806
1189
|
|
|
1807
1190
|
// src/websets/client.ts
|
|
1808
|
-
var
|
|
1191
|
+
var WebsetsClient = class extends WebsetsBaseClient {
|
|
1809
1192
|
/**
|
|
1810
1193
|
* Initialize a new Websets client
|
|
1811
1194
|
* @param client The Exa client instance
|
|
1812
1195
|
*/
|
|
1813
1196
|
constructor(client) {
|
|
1814
1197
|
super(client);
|
|
1815
|
-
this.events = new
|
|
1816
|
-
this.imports = new
|
|
1817
|
-
this.items = new
|
|
1818
|
-
this.searches = new
|
|
1819
|
-
this.enrichments = new
|
|
1820
|
-
this.monitors = new
|
|
1821
|
-
this.webhooks = new
|
|
1198
|
+
this.events = new EventsClient(client);
|
|
1199
|
+
this.imports = new ImportsClient(client);
|
|
1200
|
+
this.items = new WebsetItemsClient(client);
|
|
1201
|
+
this.searches = new WebsetSearchesClient(client);
|
|
1202
|
+
this.enrichments = new WebsetEnrichmentsClient(client);
|
|
1203
|
+
this.monitors = new WebsetMonitorsClient(client);
|
|
1204
|
+
this.webhooks = new WebsetWebhooksClient(client);
|
|
1822
1205
|
}
|
|
1823
1206
|
/**
|
|
1824
1207
|
* Create a new Webset
|
|
@@ -1982,8 +1365,8 @@ var WebsetsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1982
1365
|
// src/index.ts
|
|
1983
1366
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch2;
|
|
1984
1367
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
|
|
1985
|
-
var
|
|
1986
|
-
var
|
|
1368
|
+
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
1369
|
+
var Exa2 = class {
|
|
1987
1370
|
/**
|
|
1988
1371
|
* Helper method to separate out the contents-specific options from the rest.
|
|
1989
1372
|
*/
|
|
@@ -2011,7 +1394,7 @@ var Exa3 = class {
|
|
|
2011
1394
|
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema(summary.schema)) {
|
|
2012
1395
|
contentsOptions.summary = {
|
|
2013
1396
|
...summary,
|
|
2014
|
-
schema:
|
|
1397
|
+
schema: zodToJsonSchema(summary.schema)
|
|
2015
1398
|
};
|
|
2016
1399
|
} else {
|
|
2017
1400
|
contentsOptions.summary = summary;
|
|
@@ -2052,8 +1435,8 @@ var Exa3 = class {
|
|
|
2052
1435
|
"Content-Type": "application/json",
|
|
2053
1436
|
"User-Agent": `exa-node ${package_default.version}`
|
|
2054
1437
|
});
|
|
2055
|
-
this.websets = new
|
|
2056
|
-
this.research = new
|
|
1438
|
+
this.websets = new WebsetsClient(this);
|
|
1439
|
+
this.research = new ResearchClient(this);
|
|
2057
1440
|
}
|
|
2058
1441
|
/**
|
|
2059
1442
|
* Makes a request to the Exa API.
|
|
@@ -2150,7 +1533,7 @@ var Exa3 = class {
|
|
|
2150
1533
|
return await this.request("/search", "POST", {
|
|
2151
1534
|
query,
|
|
2152
1535
|
...options,
|
|
2153
|
-
contents: { text: { maxCharacters:
|
|
1536
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
2154
1537
|
});
|
|
2155
1538
|
}
|
|
2156
1539
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
@@ -2176,7 +1559,7 @@ var Exa3 = class {
|
|
|
2176
1559
|
async searchAndContents(query, options) {
|
|
2177
1560
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
2178
1561
|
contentsOptions: {
|
|
2179
|
-
text: { maxCharacters:
|
|
1562
|
+
text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
|
|
2180
1563
|
},
|
|
2181
1564
|
restOptions: {}
|
|
2182
1565
|
} : this.extractContentsOptions(options);
|
|
@@ -2191,7 +1574,7 @@ var Exa3 = class {
|
|
|
2191
1574
|
return await this.request("/findSimilar", "POST", {
|
|
2192
1575
|
url,
|
|
2193
1576
|
...options,
|
|
2194
|
-
contents: { text: { maxCharacters:
|
|
1577
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
2195
1578
|
});
|
|
2196
1579
|
}
|
|
2197
1580
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
@@ -2219,7 +1602,7 @@ var Exa3 = class {
|
|
|
2219
1602
|
async findSimilarAndContents(url, options) {
|
|
2220
1603
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
2221
1604
|
contentsOptions: {
|
|
2222
|
-
text: { maxCharacters:
|
|
1605
|
+
text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
|
|
2223
1606
|
},
|
|
2224
1607
|
restOptions: {}
|
|
2225
1608
|
} : this.extractContentsOptions(options);
|
|
@@ -2265,7 +1648,7 @@ var Exa3 = class {
|
|
|
2265
1648
|
}
|
|
2266
1649
|
let outputSchema = options?.outputSchema;
|
|
2267
1650
|
if (outputSchema && isZodSchema(outputSchema)) {
|
|
2268
|
-
outputSchema =
|
|
1651
|
+
outputSchema = zodToJsonSchema(outputSchema);
|
|
2269
1652
|
}
|
|
2270
1653
|
const requestBody = {
|
|
2271
1654
|
query,
|
|
@@ -2281,7 +1664,7 @@ var Exa3 = class {
|
|
|
2281
1664
|
async *streamAnswer(query, options) {
|
|
2282
1665
|
let outputSchema = options?.outputSchema;
|
|
2283
1666
|
if (outputSchema && isZodSchema(outputSchema)) {
|
|
2284
|
-
outputSchema =
|
|
1667
|
+
outputSchema = zodToJsonSchema(outputSchema);
|
|
2285
1668
|
}
|
|
2286
1669
|
const body = {
|
|
2287
1670
|
query,
|
|
@@ -2443,21 +1826,20 @@ var Exa3 = class {
|
|
|
2443
1826
|
});
|
|
2444
1827
|
}
|
|
2445
1828
|
};
|
|
2446
|
-
var index_default =
|
|
1829
|
+
var index_default = Exa2;
|
|
2447
1830
|
export {
|
|
2448
1831
|
CreateEnrichmentParametersFormat,
|
|
2449
1832
|
CreateImportParametersFormat,
|
|
2450
1833
|
EventType,
|
|
2451
|
-
|
|
2452
|
-
|
|
1834
|
+
EventsClient,
|
|
1835
|
+
Exa2 as Exa,
|
|
2453
1836
|
ExaError,
|
|
2454
|
-
Exa as ExaNova,
|
|
2455
1837
|
HttpStatusCode,
|
|
2456
1838
|
ImportFailedReason,
|
|
2457
1839
|
ImportFormat,
|
|
2458
1840
|
ImportObject,
|
|
2459
1841
|
ImportStatus,
|
|
2460
|
-
|
|
1842
|
+
ImportsClient,
|
|
2461
1843
|
MonitorObject,
|
|
2462
1844
|
MonitorRunObject,
|
|
2463
1845
|
MonitorRunStatus,
|
|
@@ -2467,21 +1849,21 @@ export {
|
|
|
2467
1849
|
WebhookStatus,
|
|
2468
1850
|
WebsetEnrichmentFormat,
|
|
2469
1851
|
WebsetEnrichmentStatus,
|
|
2470
|
-
|
|
1852
|
+
WebsetEnrichmentsClient,
|
|
2471
1853
|
WebsetExcludeSource,
|
|
2472
1854
|
WebsetImportSource,
|
|
2473
1855
|
WebsetItemEvaluationSatisfied,
|
|
2474
1856
|
WebsetItemSource,
|
|
2475
|
-
|
|
2476
|
-
|
|
1857
|
+
WebsetItemsClient,
|
|
1858
|
+
WebsetMonitorsClient,
|
|
2477
1859
|
WebsetSearchBehavior,
|
|
2478
1860
|
WebsetSearchCanceledReason,
|
|
2479
1861
|
WebsetSearchScopeSource,
|
|
2480
1862
|
WebsetSearchStatus,
|
|
2481
|
-
|
|
1863
|
+
WebsetSearchesClient,
|
|
2482
1864
|
WebsetStatus,
|
|
2483
|
-
|
|
2484
|
-
|
|
1865
|
+
WebsetWebhooksClient,
|
|
1866
|
+
WebsetsClient,
|
|
2485
1867
|
index_default as default
|
|
2486
1868
|
};
|
|
2487
1869
|
//# sourceMappingURL=index.mjs.map
|