exa-js 2.5.1-beta.2 → 2.5.1-beta.3
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 +79 -2
- package/dist/index.d.ts +79 -2
- package/dist/index.js +245 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3286,6 +3286,8 @@ interface AnswerResponse$1 {
|
|
|
3286
3286
|
};
|
|
3287
3287
|
};
|
|
3288
3288
|
}
|
|
3289
|
+
type CompanyEntity$1 = unknown;
|
|
3290
|
+
type PersonEntity$1 = unknown;
|
|
3289
3291
|
type WebsetStatus = "idle" | "pending" | "running" | "paused";
|
|
3290
3292
|
declare const WebsetStatus: {
|
|
3291
3293
|
idle: "idle";
|
|
@@ -11173,6 +11175,18 @@ declare class EventsClient extends WebsetsBaseClient {
|
|
|
11173
11175
|
createdAfter?: string;
|
|
11174
11176
|
}): Promise<ListEventsResponse>;
|
|
11175
11177
|
get(id: string): Promise<Event>;
|
|
11178
|
+
/** Iterate through all events, handling pagination automatically. */
|
|
11179
|
+
listAll(options?: PaginationParams & {
|
|
11180
|
+
types?: Array<"webset.created" | "webset.deleted" | "webset.paused" | "webset.idle" | "webset.search.created" | "webset.search.canceled" | "webset.search.completed" | "webset.search.updated" | "import.created" | "import.completed" | "webset.item.created" | "webset.item.enriched" | "monitor.created" | "monitor.updated" | "monitor.deleted" | "monitor.run.created" | "monitor.run.completed" | "webset.export.created" | "webset.export.completed">;
|
|
11181
|
+
createdBefore?: string;
|
|
11182
|
+
createdAfter?: string;
|
|
11183
|
+
}): AsyncGenerator<Event>;
|
|
11184
|
+
/** Collect all events into an array. */
|
|
11185
|
+
getAll(options?: PaginationParams & {
|
|
11186
|
+
types?: Array<"webset.created" | "webset.deleted" | "webset.paused" | "webset.idle" | "webset.search.created" | "webset.search.canceled" | "webset.search.completed" | "webset.search.updated" | "import.created" | "import.completed" | "webset.item.created" | "webset.item.enriched" | "monitor.created" | "monitor.updated" | "monitor.deleted" | "monitor.run.created" | "monitor.run.completed" | "webset.export.created" | "webset.export.completed">;
|
|
11187
|
+
createdBefore?: string;
|
|
11188
|
+
createdAfter?: string;
|
|
11189
|
+
}): Promise<Event[]>;
|
|
11176
11190
|
}
|
|
11177
11191
|
/** Client for managing Monitor Runs. */
|
|
11178
11192
|
declare class WebsetMonitorRunsClient extends WebsetsBaseClient {
|
|
@@ -11210,6 +11224,20 @@ declare class WebsetWebhooksClient extends WebsetsBaseClient {
|
|
|
11210
11224
|
eventType?: string;
|
|
11211
11225
|
successful?: boolean;
|
|
11212
11226
|
}): Promise<ListWebhookAttemptsResponse>;
|
|
11227
|
+
/** Iterate through all webhooks, handling pagination automatically. */
|
|
11228
|
+
listAll(options?: PaginationParams): AsyncGenerator<Webhook>;
|
|
11229
|
+
/** Collect all webhooks into an array. */
|
|
11230
|
+
getAll(options?: PaginationParams): Promise<Webhook[]>;
|
|
11231
|
+
/** Iterate through all webhook attempts, handling pagination automatically. */
|
|
11232
|
+
listAllAttempts(id: string, options?: PaginationParams & {
|
|
11233
|
+
eventType?: string;
|
|
11234
|
+
successful?: boolean;
|
|
11235
|
+
}): AsyncGenerator<ListWebhookAttemptsResponse["data"][number]>;
|
|
11236
|
+
/** Collect all webhook attempts into an array. */
|
|
11237
|
+
getAllAttempts(id: string, options?: PaginationParams & {
|
|
11238
|
+
eventType?: string;
|
|
11239
|
+
successful?: boolean;
|
|
11240
|
+
}): Promise<ListWebhookAttemptsResponse["data"]>;
|
|
11213
11241
|
}
|
|
11214
11242
|
/** Client for managing Imports. */
|
|
11215
11243
|
declare class ImportsClient extends WebsetsBaseClient {
|
|
@@ -11218,6 +11246,16 @@ declare class ImportsClient extends WebsetsBaseClient {
|
|
|
11218
11246
|
get(id: string): Promise<Import>;
|
|
11219
11247
|
update(id: string, params: UpdateImport): Promise<Import>;
|
|
11220
11248
|
delete(id: string): Promise<Import>;
|
|
11249
|
+
/** Wait for an import to reach a terminal status. */
|
|
11250
|
+
waitUntilCompleted(id: string, options?: {
|
|
11251
|
+
timeout?: number;
|
|
11252
|
+
pollInterval?: number;
|
|
11253
|
+
onPoll?: (status: Import["status"]) => void;
|
|
11254
|
+
}): Promise<Import>;
|
|
11255
|
+
/** Iterate through all imports, handling pagination automatically. */
|
|
11256
|
+
listAll(options?: PaginationParams): AsyncGenerator<Import>;
|
|
11257
|
+
/** Collect all imports into an array. */
|
|
11258
|
+
getAll(options?: PaginationParams): Promise<Import[]>;
|
|
11221
11259
|
}
|
|
11222
11260
|
/** Main client for managing Websets, with sub-clients for each resource. */
|
|
11223
11261
|
declare class WebsetsClient extends WebsetsBaseClient {
|
|
@@ -11282,9 +11320,15 @@ declare class ResearchClient extends ResearchBaseClient {
|
|
|
11282
11320
|
outputSchema?: Record<string, unknown> | ZodSchema<any>;
|
|
11283
11321
|
}): Promise<ResearchDtoClass>;
|
|
11284
11322
|
/** Get a research request by ID. */
|
|
11285
|
-
get(researchId: string
|
|
11323
|
+
get(researchId: string): Promise<ResearchDtoClass>;
|
|
11324
|
+
get(researchId: string, options: {
|
|
11325
|
+
stream?: false;
|
|
11286
11326
|
events?: boolean;
|
|
11287
11327
|
}): Promise<ResearchDtoClass>;
|
|
11328
|
+
get(researchId: string, options: {
|
|
11329
|
+
stream: true;
|
|
11330
|
+
events?: boolean;
|
|
11331
|
+
}): Promise<AsyncGenerator<Record<string, unknown>>>;
|
|
11288
11332
|
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
11289
11333
|
pollUntilFinished(researchId: string, options?: {
|
|
11290
11334
|
pollInterval?: number;
|
|
@@ -11323,6 +11367,22 @@ type CompanySearchOptions = Omit<SearchCommonOptions, "category" | "type" | "exc
|
|
|
11323
11367
|
category: "company";
|
|
11324
11368
|
type?: "neural" | "auto" | "fast" | "hybrid" | null;
|
|
11325
11369
|
};
|
|
11370
|
+
type TweetSearchResult = SearchResult$1;
|
|
11371
|
+
type TweetSearchResponse = Omit<SearchResponse$1, "results"> & {
|
|
11372
|
+
results: TweetSearchResult[];
|
|
11373
|
+
};
|
|
11374
|
+
type PeopleSearchResult = SearchResult$1 & {
|
|
11375
|
+
entities?: PersonEntity$1[];
|
|
11376
|
+
};
|
|
11377
|
+
type PeopleSearchResponse = Omit<SearchResponse$1, "results"> & {
|
|
11378
|
+
results: PeopleSearchResult[];
|
|
11379
|
+
};
|
|
11380
|
+
type CompanySearchResult = SearchResult$1 & {
|
|
11381
|
+
entities?: CompanyEntity$1[];
|
|
11382
|
+
};
|
|
11383
|
+
type CompanySearchResponse = Omit<SearchResponse$1, "results"> & {
|
|
11384
|
+
results: CompanySearchResult[];
|
|
11385
|
+
};
|
|
11326
11386
|
type SearchOptions = BaseSearchOptions$1 | DeepSearchOptions$1 | TweetSearchOptions | PeopleSearchOptions | CompanySearchOptions;
|
|
11327
11387
|
type FindSimilarOptions$1 = Omit<FindSimilarRequest, "url">;
|
|
11328
11388
|
type GetContentsOptions = Omit<ContentsRequest, "urls">;
|
|
@@ -11332,6 +11392,12 @@ type AnswerStreamChunk$1 = {
|
|
|
11332
11392
|
content?: string;
|
|
11333
11393
|
citations?: AnswerStreamCitation[];
|
|
11334
11394
|
};
|
|
11395
|
+
type AnswerOptionsTyped$1<T> = Omit<AnswerOptions$1, "outputSchema"> & {
|
|
11396
|
+
outputSchema: T;
|
|
11397
|
+
};
|
|
11398
|
+
type AnswerResponseTyped$1<T> = Omit<AnswerResponse$1, "answer"> & {
|
|
11399
|
+
answer: T;
|
|
11400
|
+
};
|
|
11335
11401
|
declare class ExaError extends Error {
|
|
11336
11402
|
statusCode: number;
|
|
11337
11403
|
timestamp?: string;
|
|
@@ -11363,14 +11429,25 @@ declare class Exa$1 {
|
|
|
11363
11429
|
private parseAnswerStreamLine;
|
|
11364
11430
|
/** Separate content-specific options from search/filter options. */
|
|
11365
11431
|
private extractContentsOptions;
|
|
11432
|
+
search(query: string, options: PeopleSearchOptions & {
|
|
11433
|
+
contents?: Record<string, unknown> | false | null;
|
|
11434
|
+
}): Promise<PeopleSearchResponse>;
|
|
11435
|
+
search(query: string, options: CompanySearchOptions & {
|
|
11436
|
+
contents?: Record<string, unknown> | false | null;
|
|
11437
|
+
}): Promise<CompanySearchResponse>;
|
|
11438
|
+
search(query: string, options: TweetSearchOptions & {
|
|
11439
|
+
contents?: Record<string, unknown> | false | null;
|
|
11440
|
+
}): Promise<TweetSearchResponse>;
|
|
11366
11441
|
search(query: string, options?: SearchOptions & {
|
|
11367
11442
|
contents?: Record<string, unknown> | false | null;
|
|
11368
11443
|
}): Promise<SearchResponse$1>;
|
|
11369
11444
|
findSimilar(url: string, options?: FindSimilarOptions$1 & {
|
|
11370
11445
|
contents?: Record<string, unknown> | false | null;
|
|
11371
11446
|
}): Promise<FindSimilarResponse>;
|
|
11372
|
-
getContents(urls
|
|
11447
|
+
getContents(urls: string | string[] | SearchResult$1[], options?: GetContentsOptions): Promise<ContentsResponse>;
|
|
11448
|
+
answer<T>(query: string, options: AnswerOptionsTyped$1<ZodSchema<T>>): Promise<AnswerResponseTyped$1<T>>;
|
|
11373
11449
|
answer(query: string, options?: AnswerOptions$1): Promise<AnswerResponse$1>;
|
|
11450
|
+
streamAnswer<T>(query: string, options: Omit<AnswerOptionsTyped$1<ZodSchema<T>>, "stream">): AsyncGenerator<AnswerStreamChunk$1>;
|
|
11374
11451
|
streamAnswer(query: string, options?: Omit<AnswerOptions$1, "stream">): AsyncGenerator<AnswerStreamChunk$1>;
|
|
11375
11452
|
/**
|
|
11376
11453
|
* @deprecated Use `search()` instead. The search method now returns text contents by default.
|
package/dist/index.d.ts
CHANGED
|
@@ -3286,6 +3286,8 @@ interface AnswerResponse$1 {
|
|
|
3286
3286
|
};
|
|
3287
3287
|
};
|
|
3288
3288
|
}
|
|
3289
|
+
type CompanyEntity$1 = unknown;
|
|
3290
|
+
type PersonEntity$1 = unknown;
|
|
3289
3291
|
type WebsetStatus = "idle" | "pending" | "running" | "paused";
|
|
3290
3292
|
declare const WebsetStatus: {
|
|
3291
3293
|
idle: "idle";
|
|
@@ -11173,6 +11175,18 @@ declare class EventsClient extends WebsetsBaseClient {
|
|
|
11173
11175
|
createdAfter?: string;
|
|
11174
11176
|
}): Promise<ListEventsResponse>;
|
|
11175
11177
|
get(id: string): Promise<Event>;
|
|
11178
|
+
/** Iterate through all events, handling pagination automatically. */
|
|
11179
|
+
listAll(options?: PaginationParams & {
|
|
11180
|
+
types?: Array<"webset.created" | "webset.deleted" | "webset.paused" | "webset.idle" | "webset.search.created" | "webset.search.canceled" | "webset.search.completed" | "webset.search.updated" | "import.created" | "import.completed" | "webset.item.created" | "webset.item.enriched" | "monitor.created" | "monitor.updated" | "monitor.deleted" | "monitor.run.created" | "monitor.run.completed" | "webset.export.created" | "webset.export.completed">;
|
|
11181
|
+
createdBefore?: string;
|
|
11182
|
+
createdAfter?: string;
|
|
11183
|
+
}): AsyncGenerator<Event>;
|
|
11184
|
+
/** Collect all events into an array. */
|
|
11185
|
+
getAll(options?: PaginationParams & {
|
|
11186
|
+
types?: Array<"webset.created" | "webset.deleted" | "webset.paused" | "webset.idle" | "webset.search.created" | "webset.search.canceled" | "webset.search.completed" | "webset.search.updated" | "import.created" | "import.completed" | "webset.item.created" | "webset.item.enriched" | "monitor.created" | "monitor.updated" | "monitor.deleted" | "monitor.run.created" | "monitor.run.completed" | "webset.export.created" | "webset.export.completed">;
|
|
11187
|
+
createdBefore?: string;
|
|
11188
|
+
createdAfter?: string;
|
|
11189
|
+
}): Promise<Event[]>;
|
|
11176
11190
|
}
|
|
11177
11191
|
/** Client for managing Monitor Runs. */
|
|
11178
11192
|
declare class WebsetMonitorRunsClient extends WebsetsBaseClient {
|
|
@@ -11210,6 +11224,20 @@ declare class WebsetWebhooksClient extends WebsetsBaseClient {
|
|
|
11210
11224
|
eventType?: string;
|
|
11211
11225
|
successful?: boolean;
|
|
11212
11226
|
}): Promise<ListWebhookAttemptsResponse>;
|
|
11227
|
+
/** Iterate through all webhooks, handling pagination automatically. */
|
|
11228
|
+
listAll(options?: PaginationParams): AsyncGenerator<Webhook>;
|
|
11229
|
+
/** Collect all webhooks into an array. */
|
|
11230
|
+
getAll(options?: PaginationParams): Promise<Webhook[]>;
|
|
11231
|
+
/** Iterate through all webhook attempts, handling pagination automatically. */
|
|
11232
|
+
listAllAttempts(id: string, options?: PaginationParams & {
|
|
11233
|
+
eventType?: string;
|
|
11234
|
+
successful?: boolean;
|
|
11235
|
+
}): AsyncGenerator<ListWebhookAttemptsResponse["data"][number]>;
|
|
11236
|
+
/** Collect all webhook attempts into an array. */
|
|
11237
|
+
getAllAttempts(id: string, options?: PaginationParams & {
|
|
11238
|
+
eventType?: string;
|
|
11239
|
+
successful?: boolean;
|
|
11240
|
+
}): Promise<ListWebhookAttemptsResponse["data"]>;
|
|
11213
11241
|
}
|
|
11214
11242
|
/** Client for managing Imports. */
|
|
11215
11243
|
declare class ImportsClient extends WebsetsBaseClient {
|
|
@@ -11218,6 +11246,16 @@ declare class ImportsClient extends WebsetsBaseClient {
|
|
|
11218
11246
|
get(id: string): Promise<Import>;
|
|
11219
11247
|
update(id: string, params: UpdateImport): Promise<Import>;
|
|
11220
11248
|
delete(id: string): Promise<Import>;
|
|
11249
|
+
/** Wait for an import to reach a terminal status. */
|
|
11250
|
+
waitUntilCompleted(id: string, options?: {
|
|
11251
|
+
timeout?: number;
|
|
11252
|
+
pollInterval?: number;
|
|
11253
|
+
onPoll?: (status: Import["status"]) => void;
|
|
11254
|
+
}): Promise<Import>;
|
|
11255
|
+
/** Iterate through all imports, handling pagination automatically. */
|
|
11256
|
+
listAll(options?: PaginationParams): AsyncGenerator<Import>;
|
|
11257
|
+
/** Collect all imports into an array. */
|
|
11258
|
+
getAll(options?: PaginationParams): Promise<Import[]>;
|
|
11221
11259
|
}
|
|
11222
11260
|
/** Main client for managing Websets, with sub-clients for each resource. */
|
|
11223
11261
|
declare class WebsetsClient extends WebsetsBaseClient {
|
|
@@ -11282,9 +11320,15 @@ declare class ResearchClient extends ResearchBaseClient {
|
|
|
11282
11320
|
outputSchema?: Record<string, unknown> | ZodSchema<any>;
|
|
11283
11321
|
}): Promise<ResearchDtoClass>;
|
|
11284
11322
|
/** Get a research request by ID. */
|
|
11285
|
-
get(researchId: string
|
|
11323
|
+
get(researchId: string): Promise<ResearchDtoClass>;
|
|
11324
|
+
get(researchId: string, options: {
|
|
11325
|
+
stream?: false;
|
|
11286
11326
|
events?: boolean;
|
|
11287
11327
|
}): Promise<ResearchDtoClass>;
|
|
11328
|
+
get(researchId: string, options: {
|
|
11329
|
+
stream: true;
|
|
11330
|
+
events?: boolean;
|
|
11331
|
+
}): Promise<AsyncGenerator<Record<string, unknown>>>;
|
|
11288
11332
|
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
11289
11333
|
pollUntilFinished(researchId: string, options?: {
|
|
11290
11334
|
pollInterval?: number;
|
|
@@ -11323,6 +11367,22 @@ type CompanySearchOptions = Omit<SearchCommonOptions, "category" | "type" | "exc
|
|
|
11323
11367
|
category: "company";
|
|
11324
11368
|
type?: "neural" | "auto" | "fast" | "hybrid" | null;
|
|
11325
11369
|
};
|
|
11370
|
+
type TweetSearchResult = SearchResult$1;
|
|
11371
|
+
type TweetSearchResponse = Omit<SearchResponse$1, "results"> & {
|
|
11372
|
+
results: TweetSearchResult[];
|
|
11373
|
+
};
|
|
11374
|
+
type PeopleSearchResult = SearchResult$1 & {
|
|
11375
|
+
entities?: PersonEntity$1[];
|
|
11376
|
+
};
|
|
11377
|
+
type PeopleSearchResponse = Omit<SearchResponse$1, "results"> & {
|
|
11378
|
+
results: PeopleSearchResult[];
|
|
11379
|
+
};
|
|
11380
|
+
type CompanySearchResult = SearchResult$1 & {
|
|
11381
|
+
entities?: CompanyEntity$1[];
|
|
11382
|
+
};
|
|
11383
|
+
type CompanySearchResponse = Omit<SearchResponse$1, "results"> & {
|
|
11384
|
+
results: CompanySearchResult[];
|
|
11385
|
+
};
|
|
11326
11386
|
type SearchOptions = BaseSearchOptions$1 | DeepSearchOptions$1 | TweetSearchOptions | PeopleSearchOptions | CompanySearchOptions;
|
|
11327
11387
|
type FindSimilarOptions$1 = Omit<FindSimilarRequest, "url">;
|
|
11328
11388
|
type GetContentsOptions = Omit<ContentsRequest, "urls">;
|
|
@@ -11332,6 +11392,12 @@ type AnswerStreamChunk$1 = {
|
|
|
11332
11392
|
content?: string;
|
|
11333
11393
|
citations?: AnswerStreamCitation[];
|
|
11334
11394
|
};
|
|
11395
|
+
type AnswerOptionsTyped$1<T> = Omit<AnswerOptions$1, "outputSchema"> & {
|
|
11396
|
+
outputSchema: T;
|
|
11397
|
+
};
|
|
11398
|
+
type AnswerResponseTyped$1<T> = Omit<AnswerResponse$1, "answer"> & {
|
|
11399
|
+
answer: T;
|
|
11400
|
+
};
|
|
11335
11401
|
declare class ExaError extends Error {
|
|
11336
11402
|
statusCode: number;
|
|
11337
11403
|
timestamp?: string;
|
|
@@ -11363,14 +11429,25 @@ declare class Exa$1 {
|
|
|
11363
11429
|
private parseAnswerStreamLine;
|
|
11364
11430
|
/** Separate content-specific options from search/filter options. */
|
|
11365
11431
|
private extractContentsOptions;
|
|
11432
|
+
search(query: string, options: PeopleSearchOptions & {
|
|
11433
|
+
contents?: Record<string, unknown> | false | null;
|
|
11434
|
+
}): Promise<PeopleSearchResponse>;
|
|
11435
|
+
search(query: string, options: CompanySearchOptions & {
|
|
11436
|
+
contents?: Record<string, unknown> | false | null;
|
|
11437
|
+
}): Promise<CompanySearchResponse>;
|
|
11438
|
+
search(query: string, options: TweetSearchOptions & {
|
|
11439
|
+
contents?: Record<string, unknown> | false | null;
|
|
11440
|
+
}): Promise<TweetSearchResponse>;
|
|
11366
11441
|
search(query: string, options?: SearchOptions & {
|
|
11367
11442
|
contents?: Record<string, unknown> | false | null;
|
|
11368
11443
|
}): Promise<SearchResponse$1>;
|
|
11369
11444
|
findSimilar(url: string, options?: FindSimilarOptions$1 & {
|
|
11370
11445
|
contents?: Record<string, unknown> | false | null;
|
|
11371
11446
|
}): Promise<FindSimilarResponse>;
|
|
11372
|
-
getContents(urls
|
|
11447
|
+
getContents(urls: string | string[] | SearchResult$1[], options?: GetContentsOptions): Promise<ContentsResponse>;
|
|
11448
|
+
answer<T>(query: string, options: AnswerOptionsTyped$1<ZodSchema<T>>): Promise<AnswerResponseTyped$1<T>>;
|
|
11373
11449
|
answer(query: string, options?: AnswerOptions$1): Promise<AnswerResponse$1>;
|
|
11450
|
+
streamAnswer<T>(query: string, options: Omit<AnswerOptionsTyped$1<ZodSchema<T>>, "stream">): AsyncGenerator<AnswerStreamChunk$1>;
|
|
11374
11451
|
streamAnswer(query: string, options?: Omit<AnswerOptions$1, "stream">): AsyncGenerator<AnswerStreamChunk$1>;
|
|
11375
11452
|
/**
|
|
11376
11453
|
* @deprecated Use `search()` instead. The search method now returns text contents by default.
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
|
75
75
|
// package.json
|
|
76
76
|
var package_default = {
|
|
77
77
|
name: "exa-js",
|
|
78
|
-
version: "2.5.1-beta.
|
|
78
|
+
version: "2.5.1-beta.3",
|
|
79
79
|
description: "Exa SDK for Node.js and the browser",
|
|
80
80
|
publishConfig: {
|
|
81
81
|
access: "public"
|
|
@@ -247,6 +247,29 @@ var EventsClient = class extends WebsetsBaseClient {
|
|
|
247
247
|
async get(id) {
|
|
248
248
|
return this.request(`/v0/events/${id}`, "GET");
|
|
249
249
|
}
|
|
250
|
+
/** Iterate through all events, handling pagination automatically. */
|
|
251
|
+
async *listAll(options) {
|
|
252
|
+
let cursor = void 0;
|
|
253
|
+
const pageOptions = options ? { ...options } : {};
|
|
254
|
+
while (true) {
|
|
255
|
+
const response = await this.list({ ...pageOptions, cursor });
|
|
256
|
+
for (const event of response.data) {
|
|
257
|
+
yield event;
|
|
258
|
+
}
|
|
259
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
cursor = response.nextCursor;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/** Collect all events into an array. */
|
|
266
|
+
async getAll(options) {
|
|
267
|
+
const events = [];
|
|
268
|
+
for await (const event of this.listAll(options)) {
|
|
269
|
+
events.push(event);
|
|
270
|
+
}
|
|
271
|
+
return events;
|
|
272
|
+
}
|
|
250
273
|
};
|
|
251
274
|
var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
252
275
|
async list(monitorId) {
|
|
@@ -322,6 +345,52 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
322
345
|
const queryParams = { ...this.buildPaginationParams(options), eventType: options?.eventType, successful: options?.successful };
|
|
323
346
|
return this.request(`/v0/webhooks/${id}/attempts`, "GET", void 0, queryParams);
|
|
324
347
|
}
|
|
348
|
+
/** Iterate through all webhooks, handling pagination automatically. */
|
|
349
|
+
async *listAll(options) {
|
|
350
|
+
let cursor = void 0;
|
|
351
|
+
const pageOptions = options ? { ...options } : {};
|
|
352
|
+
while (true) {
|
|
353
|
+
const response = await this.list({ ...pageOptions, cursor });
|
|
354
|
+
for (const webhook of response.data) {
|
|
355
|
+
yield webhook;
|
|
356
|
+
}
|
|
357
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
cursor = response.nextCursor;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/** Collect all webhooks into an array. */
|
|
364
|
+
async getAll(options) {
|
|
365
|
+
const webhooks = [];
|
|
366
|
+
for await (const webhook of this.listAll(options)) {
|
|
367
|
+
webhooks.push(webhook);
|
|
368
|
+
}
|
|
369
|
+
return webhooks;
|
|
370
|
+
}
|
|
371
|
+
/** Iterate through all webhook attempts, handling pagination automatically. */
|
|
372
|
+
async *listAllAttempts(id, options) {
|
|
373
|
+
let cursor = void 0;
|
|
374
|
+
const pageOptions = options ? { ...options } : {};
|
|
375
|
+
while (true) {
|
|
376
|
+
const response = await this.listAttempts(id, { ...pageOptions, cursor });
|
|
377
|
+
for (const attempt of response.data) {
|
|
378
|
+
yield attempt;
|
|
379
|
+
}
|
|
380
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
cursor = response.nextCursor;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/** Collect all webhook attempts into an array. */
|
|
387
|
+
async getAllAttempts(id, options) {
|
|
388
|
+
const attempts = [];
|
|
389
|
+
for await (const attempt of this.listAllAttempts(id, options)) {
|
|
390
|
+
attempts.push(attempt);
|
|
391
|
+
}
|
|
392
|
+
return attempts;
|
|
393
|
+
}
|
|
325
394
|
};
|
|
326
395
|
var ImportsClient = class extends WebsetsBaseClient {
|
|
327
396
|
async create(params) {
|
|
@@ -340,6 +409,51 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
340
409
|
async delete(id) {
|
|
341
410
|
return this.request(`/v0/imports/${id}`, "DELETE");
|
|
342
411
|
}
|
|
412
|
+
/** Wait for an import to reach a terminal status. */
|
|
413
|
+
async waitUntilCompleted(id, options) {
|
|
414
|
+
const timeout = options?.timeout ?? 30 * 60 * 1e3;
|
|
415
|
+
const pollInterval = options?.pollInterval ?? 2e3;
|
|
416
|
+
const startTime = Date.now();
|
|
417
|
+
while (true) {
|
|
418
|
+
const importItem = await this.get(id);
|
|
419
|
+
if (options?.onPoll) {
|
|
420
|
+
options.onPoll(importItem.status);
|
|
421
|
+
}
|
|
422
|
+
if (importItem.status === "completed") {
|
|
423
|
+
return importItem;
|
|
424
|
+
}
|
|
425
|
+
if (importItem.status === "failed") {
|
|
426
|
+
throw new Error(`Import ${id} failed: ${importItem.failedMessage ?? "Unknown error"}`);
|
|
427
|
+
}
|
|
428
|
+
if (Date.now() - startTime > timeout) {
|
|
429
|
+
throw new Error(`Import ${id} did not complete within ${timeout}ms. Current status: ${importItem.status}`);
|
|
430
|
+
}
|
|
431
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/** Iterate through all imports, handling pagination automatically. */
|
|
435
|
+
async *listAll(options) {
|
|
436
|
+
let cursor = void 0;
|
|
437
|
+
const pageOptions = options ? { ...options } : {};
|
|
438
|
+
while (true) {
|
|
439
|
+
const response = await this.list({ ...pageOptions, cursor });
|
|
440
|
+
for (const importItem of response.data) {
|
|
441
|
+
yield importItem;
|
|
442
|
+
}
|
|
443
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
cursor = response.nextCursor;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/** Collect all imports into an array. */
|
|
450
|
+
async getAll(options) {
|
|
451
|
+
const imports = [];
|
|
452
|
+
for await (const importItem of this.listAll(options)) {
|
|
453
|
+
imports.push(importItem);
|
|
454
|
+
}
|
|
455
|
+
return imports;
|
|
456
|
+
}
|
|
343
457
|
};
|
|
344
458
|
var WebsetsClient = class extends WebsetsBaseClient {
|
|
345
459
|
constructor(client) {
|
|
@@ -467,10 +581,75 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
467
581
|
}
|
|
468
582
|
return this.client.request("/research/v1", "POST", payload, void 0);
|
|
469
583
|
}
|
|
470
|
-
/** Get a research request by ID. */
|
|
471
584
|
async get(researchId, options) {
|
|
472
585
|
const params = {};
|
|
473
586
|
if (options?.events !== void 0) params.events = options.events.toString();
|
|
587
|
+
if (options?.stream) {
|
|
588
|
+
params.stream = "true";
|
|
589
|
+
const response = await this.client.rawRequest(`/research/v1/${researchId}`, "GET", void 0, params);
|
|
590
|
+
if (!response.ok) {
|
|
591
|
+
const message = await response.text();
|
|
592
|
+
throw new Error(`Research stream request failed (${response.status}): ${message}`);
|
|
593
|
+
}
|
|
594
|
+
const reader = response.body?.getReader();
|
|
595
|
+
if (!reader) {
|
|
596
|
+
throw new Error("No response body for SSE stream");
|
|
597
|
+
}
|
|
598
|
+
const streamReader = reader;
|
|
599
|
+
const decoder = new TextDecoder();
|
|
600
|
+
let buffer = "";
|
|
601
|
+
const parseSseChunk = (chunk) => {
|
|
602
|
+
const lines = chunk.split("\n");
|
|
603
|
+
const dataLines = [];
|
|
604
|
+
for (const line of lines) {
|
|
605
|
+
if (line.startsWith("data:")) {
|
|
606
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const payload = dataLines.join("\n").trim();
|
|
610
|
+
if (payload.length === 0 || payload === "[DONE]") {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
try {
|
|
614
|
+
const parsed = JSON.parse(payload);
|
|
615
|
+
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
const event = {};
|
|
619
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
620
|
+
event[key] = value;
|
|
621
|
+
}
|
|
622
|
+
return event;
|
|
623
|
+
} catch {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
async function* streamEvents() {
|
|
628
|
+
while (true) {
|
|
629
|
+
const { done, value } = await streamReader.read();
|
|
630
|
+
if (done) break;
|
|
631
|
+
buffer += decoder.decode(value, { stream: true });
|
|
632
|
+
const parts = buffer.split("\n\n");
|
|
633
|
+
buffer = parts.pop() ?? "";
|
|
634
|
+
for (const part of parts) {
|
|
635
|
+
const event = parseSseChunk(part);
|
|
636
|
+
if (event != null) {
|
|
637
|
+
yield event;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (buffer.trim().length > 0) {
|
|
642
|
+
const event = parseSseChunk(buffer.trim());
|
|
643
|
+
if (event != null) {
|
|
644
|
+
yield event;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return streamEvents();
|
|
649
|
+
}
|
|
650
|
+
if (options?.stream === false) {
|
|
651
|
+
params.stream = "false";
|
|
652
|
+
}
|
|
474
653
|
return this.client.request(`/research/v1/${researchId}`, "GET", void 0, params);
|
|
475
654
|
}
|
|
476
655
|
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
@@ -502,9 +681,21 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
502
681
|
};
|
|
503
682
|
|
|
504
683
|
// src/nova/client.ts
|
|
684
|
+
var import_zod2 = require("zod");
|
|
685
|
+
var import_zod_to_json_schema2 = require("zod-to-json-schema");
|
|
505
686
|
function isRecord(value) {
|
|
506
687
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
507
688
|
}
|
|
689
|
+
function isZodSchema(value) {
|
|
690
|
+
return value instanceof import_zod2.ZodType;
|
|
691
|
+
}
|
|
692
|
+
function zodToJsonSchema2(schema) {
|
|
693
|
+
const converted = (0, import_zod_to_json_schema2.zodToJsonSchema)(schema, { $refStrategy: "none" });
|
|
694
|
+
if (!isRecord(converted)) {
|
|
695
|
+
throw new Error("Failed to convert Zod schema to JSON Schema.");
|
|
696
|
+
}
|
|
697
|
+
return converted;
|
|
698
|
+
}
|
|
508
699
|
var ExaError = class extends Error {
|
|
509
700
|
constructor(message, statusCode, timestamp, path, details) {
|
|
510
701
|
super(message);
|
|
@@ -673,10 +864,7 @@ var Exa = class {
|
|
|
673
864
|
if (content == null && (citations == null || citations.length === 0)) {
|
|
674
865
|
return null;
|
|
675
866
|
}
|
|
676
|
-
return {
|
|
677
|
-
...content != null ? { content } : {},
|
|
678
|
-
...citations != null ? { citations } : {}
|
|
679
|
-
};
|
|
867
|
+
return { content, citations };
|
|
680
868
|
}
|
|
681
869
|
/** Separate content-specific options from search/filter options. */
|
|
682
870
|
extractContentsOptions(options) {
|
|
@@ -721,16 +909,49 @@ var Exa = class {
|
|
|
721
909
|
return this.request("/findSimilar", "POST", body);
|
|
722
910
|
}
|
|
723
911
|
getContents(urls, options) {
|
|
724
|
-
|
|
912
|
+
let requestUrls;
|
|
913
|
+
if (typeof urls === "string") {
|
|
914
|
+
requestUrls = [urls];
|
|
915
|
+
} else if (urls.length === 0) {
|
|
916
|
+
throw new ExaError("Must provide at least one URL", 400);
|
|
917
|
+
} else if (typeof urls[0] === "string") {
|
|
918
|
+
requestUrls = [];
|
|
919
|
+
for (const url of urls) {
|
|
920
|
+
if (typeof url !== "string") {
|
|
921
|
+
throw new ExaError("Expected all URLs to be strings or SearchResult objects with a url field", 400);
|
|
922
|
+
}
|
|
923
|
+
requestUrls.push(url);
|
|
924
|
+
}
|
|
925
|
+
} else {
|
|
926
|
+
requestUrls = [];
|
|
927
|
+
for (const result of urls) {
|
|
928
|
+
if (!isRecord(result) || typeof result.url !== "string") {
|
|
929
|
+
throw new ExaError("Expected all entries to have a string url field", 400);
|
|
930
|
+
}
|
|
931
|
+
requestUrls.push(result.url);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (requestUrls.length === 0) {
|
|
935
|
+
throw new ExaError("Must provide at least one URL", 400);
|
|
936
|
+
}
|
|
937
|
+
return this.request("/contents", "POST", { urls: requestUrls, ...options });
|
|
725
938
|
}
|
|
726
|
-
answer(query, options) {
|
|
939
|
+
async answer(query, options) {
|
|
727
940
|
if (options?.stream) {
|
|
728
941
|
throw new ExaError("For streaming responses, please use streamAnswer() instead:\n\nfor await (const chunk of exa.streamAnswer(query)) {\n // Handle chunks\n}", 400);
|
|
729
942
|
}
|
|
730
|
-
|
|
943
|
+
let outputSchema = options?.outputSchema;
|
|
944
|
+
if (outputSchema != null && isZodSchema(outputSchema)) {
|
|
945
|
+
outputSchema = zodToJsonSchema2(outputSchema);
|
|
946
|
+
}
|
|
947
|
+
return this.request("/answer", "POST", { query, model: "exa", stream: false, text: false, ...options, outputSchema });
|
|
731
948
|
}
|
|
732
949
|
async *streamAnswer(query, options) {
|
|
733
|
-
|
|
950
|
+
let outputSchema = options?.outputSchema;
|
|
951
|
+
if (outputSchema != null && isZodSchema(outputSchema)) {
|
|
952
|
+
outputSchema = zodToJsonSchema2(outputSchema);
|
|
953
|
+
}
|
|
954
|
+
const response = await this.rawRequest("/answer", "POST", { query, model: "exa", text: false, ...options, outputSchema, stream: true });
|
|
734
955
|
if (!response.ok) {
|
|
735
956
|
throw await this.toExaError(response, "/answer");
|
|
736
957
|
}
|
|
@@ -806,13 +1027,13 @@ var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
|
806
1027
|
})(HttpStatusCode || {});
|
|
807
1028
|
|
|
808
1029
|
// src/zod-utils.ts
|
|
809
|
-
var
|
|
810
|
-
var
|
|
811
|
-
function
|
|
812
|
-
return obj instanceof
|
|
1030
|
+
var import_zod3 = require("zod");
|
|
1031
|
+
var import_zod_to_json_schema3 = require("zod-to-json-schema");
|
|
1032
|
+
function isZodSchema2(obj) {
|
|
1033
|
+
return obj instanceof import_zod3.ZodType;
|
|
813
1034
|
}
|
|
814
|
-
function
|
|
815
|
-
return (0,
|
|
1035
|
+
function zodToJsonSchema3(schema) {
|
|
1036
|
+
return (0, import_zod_to_json_schema3.zodToJsonSchema)(schema, {
|
|
816
1037
|
$refStrategy: "none"
|
|
817
1038
|
});
|
|
818
1039
|
}
|
|
@@ -855,8 +1076,8 @@ var ResearchClient2 = class extends ResearchBaseClient2 {
|
|
|
855
1076
|
async create(params) {
|
|
856
1077
|
const { instructions, model, outputSchema } = params;
|
|
857
1078
|
let schema = outputSchema;
|
|
858
|
-
if (schema &&
|
|
859
|
-
schema =
|
|
1079
|
+
if (schema && isZodSchema2(schema)) {
|
|
1080
|
+
schema = zodToJsonSchema3(schema);
|
|
860
1081
|
}
|
|
861
1082
|
const payload = {
|
|
862
1083
|
instructions,
|
|
@@ -2079,10 +2300,10 @@ var Exa3 = class {
|
|
|
2079
2300
|
if (text !== void 0) contentsOptions.text = text;
|
|
2080
2301
|
if (highlights !== void 0) contentsOptions.highlights = highlights;
|
|
2081
2302
|
if (summary !== void 0) {
|
|
2082
|
-
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema &&
|
|
2303
|
+
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema2(summary.schema)) {
|
|
2083
2304
|
contentsOptions.summary = {
|
|
2084
2305
|
...summary,
|
|
2085
|
-
schema:
|
|
2306
|
+
schema: zodToJsonSchema3(summary.schema)
|
|
2086
2307
|
};
|
|
2087
2308
|
} else {
|
|
2088
2309
|
contentsOptions.summary = summary;
|
|
@@ -2335,8 +2556,8 @@ var Exa3 = class {
|
|
|
2335
2556
|
);
|
|
2336
2557
|
}
|
|
2337
2558
|
let outputSchema = options?.outputSchema;
|
|
2338
|
-
if (outputSchema &&
|
|
2339
|
-
outputSchema =
|
|
2559
|
+
if (outputSchema && isZodSchema2(outputSchema)) {
|
|
2560
|
+
outputSchema = zodToJsonSchema3(outputSchema);
|
|
2340
2561
|
}
|
|
2341
2562
|
const requestBody = {
|
|
2342
2563
|
query,
|
|
@@ -2351,8 +2572,8 @@ var Exa3 = class {
|
|
|
2351
2572
|
}
|
|
2352
2573
|
async *streamAnswer(query, options) {
|
|
2353
2574
|
let outputSchema = options?.outputSchema;
|
|
2354
|
-
if (outputSchema &&
|
|
2355
|
-
outputSchema =
|
|
2575
|
+
if (outputSchema && isZodSchema2(outputSchema)) {
|
|
2576
|
+
outputSchema = zodToJsonSchema3(outputSchema);
|
|
2356
2577
|
}
|
|
2357
2578
|
const body = {
|
|
2358
2579
|
query,
|