exa-js 1.8.17 → 1.8.19

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 CHANGED
@@ -1,3 +1,5 @@
1
+ import { ZodSchema } from 'zod';
2
+
1
3
  /**
2
4
  * Base client for Websets API
3
5
  */
@@ -287,6 +289,8 @@ interface components$1 {
287
289
  *
288
290
  * Any URLs provided will be crawled and used as additional context for the search. */
289
291
  query: string;
292
+ /** @description Whether to compute recall metrics for the search */
293
+ recall?: boolean;
290
294
  };
291
295
  };
292
296
  CreateWebsetSearchParameters: {
@@ -327,12 +331,11 @@ interface components$1 {
327
331
  *
328
332
  * Any URLs provided will be crawled and used as additional context for the search. */
329
333
  query: string;
334
+ /** @description Whether to compute recall metrics for the search */
335
+ recall?: boolean;
330
336
  };
331
337
  /** Custom */
332
338
  CustomEntity: {
333
- /** @description When you decide to use a custom entity, this is the description of the entity.
334
- *
335
- * The entity represents what type of results the will return. For example, if you want results to be Job Postings, you might use "Job Postings" as the entity description. */
336
339
  description: string;
337
340
  /**
338
341
  * @default custom
@@ -362,6 +365,11 @@ interface components$1 {
362
365
  }[];
363
366
  /** @description The result of the enrichment. */
364
367
  result: string[] | null;
368
+ /**
369
+ * @description The status of the enrichment result.
370
+ * @enum {string}
371
+ */
372
+ status: EnrichmentResultStatus;
365
373
  };
366
374
  Entity: components$1["schemas"]["CompanyEntity"] | components$1["schemas"]["PersonEntity"] | components$1["schemas"]["ArticleEntity"] | components$1["schemas"]["ResearchPaperEntity"] | components$1["schemas"]["CustomEntity"];
367
375
  /** Event */
@@ -557,6 +565,7 @@ interface components$1 {
557
565
  type: "webset.search.completed";
558
566
  };
559
567
  /** @enum {string} */
568
+ EventType: EventType;
560
569
  GetWebsetResponse: components$1["schemas"]["Webset"] & {
561
570
  /** @description When expand query parameter contains `items`, this will contain the items in the webset */
562
571
  items?: components$1["schemas"]["WebsetItem"][];
@@ -1332,13 +1341,37 @@ interface components$1 {
1332
1341
  object: "webset_search";
1333
1342
  /** @description The progress of the search */
1334
1343
  progress: {
1344
+ /** @description The number of results analyzed so far */
1345
+ analyzed: number;
1335
1346
  /** @description The completion percentage of the search */
1336
1347
  completion: number;
1337
1348
  /** @description The number of results found so far */
1338
1349
  found: number;
1350
+ /** @description The estimated time remaining in seconds, null if unknown */
1351
+ timeLeft: number | null;
1339
1352
  };
1340
1353
  /** @description The query used to create the search. */
1341
1354
  query: string;
1355
+ /** @description Recall metrics for the search, null if not yet computed or requested. */
1356
+ recall: {
1357
+ expected: {
1358
+ bounds: {
1359
+ /** @description The maximum estimated total number of potential matches */
1360
+ max: number;
1361
+ /** @description The minimum estimated total number of potential matches */
1362
+ min: number;
1363
+ };
1364
+ /**
1365
+ * @description The confidence in the estimate
1366
+ * @enum {string}
1367
+ */
1368
+ confidence: WebsetSearchRecallExpectedConfidence;
1369
+ /** @description The estimated total number of potential matches */
1370
+ total: number;
1371
+ };
1372
+ /** @description The reasoning for the estimate */
1373
+ reasoning: string;
1374
+ } | null;
1342
1375
  /**
1343
1376
  * WebsetSearchStatus
1344
1377
  * @description The status of the search
@@ -1449,6 +1482,11 @@ declare enum CreateWebsetSearchParametersExcludeSource {
1449
1482
  import = "import",
1450
1483
  webset = "webset"
1451
1484
  }
1485
+ declare enum EnrichmentResultStatus {
1486
+ pending = "pending",
1487
+ completed = "completed",
1488
+ canceled = "canceled"
1489
+ }
1452
1490
  declare enum EventType {
1453
1491
  webset_created = "webset.created",
1454
1492
  webset_deleted = "webset.deleted",
@@ -1564,6 +1602,11 @@ declare enum WebsetSearchExcludeSource {
1564
1602
  import = "import",
1565
1603
  webset = "webset"
1566
1604
  }
1605
+ declare enum WebsetSearchRecallExpectedConfidence {
1606
+ high = "high",
1607
+ medium = "medium",
1608
+ low = "low"
1609
+ }
1567
1610
  declare enum WebsetSearchStatus {
1568
1611
  created = "created",
1569
1612
  running = "running",
@@ -2144,6 +2187,10 @@ declare class ResearchBaseClient {
2144
2187
  */
2145
2188
  declare class ResearchClient extends ResearchBaseClient {
2146
2189
  constructor(client: Exa);
2190
+ /**
2191
+ * Create a new research task with Zod schema for strongly typed output
2192
+ */
2193
+ createTask<T>(params: ResearchCreateTaskParamsTyped<ZodSchema<T>>): Promise<SchemaResearchCreateTaskResponseDto>;
2147
2194
  /**
2148
2195
  * Create a new research task.
2149
2196
  *
@@ -2697,29 +2744,12 @@ type HighlightsContentsOptions = {
2697
2744
  */
2698
2745
  type SummaryContentsOptions = {
2699
2746
  query?: string;
2700
- schema?: JSONSchema;
2747
+ schema?: Record<string, unknown> | ZodSchema;
2701
2748
  };
2702
2749
  /**
2703
- * Represents a JSON Schema definition used for structured summary output.
2704
- * To learn more visit https://json-schema.org/overview/what-is-jsonschema.
2750
+ * @deprecated Use Record<string, unknown> instead.
2705
2751
  */
2706
- type JSONSchema = {
2707
- $schema?: string;
2708
- title?: string;
2709
- description?: string;
2710
- type: "object" | "array" | "string" | "number" | "boolean" | "null" | "integer";
2711
- properties?: Record<string, JSONSchema>;
2712
- items?: JSONSchema | JSONSchema[];
2713
- required?: string[];
2714
- enum?: any[];
2715
- additionalProperties?: boolean | JSONSchema;
2716
- definitions?: Record<string, JSONSchema>;
2717
- patternProperties?: Record<string, JSONSchema>;
2718
- allOf?: JSONSchema[];
2719
- anyOf?: JSONSchema[];
2720
- oneOf?: JSONSchema[];
2721
- not?: JSONSchema;
2722
- };
2752
+ type JSONSchema = Record<string, unknown>;
2723
2753
  /**
2724
2754
  * Options for retrieving the context from a list of search results. The context is a string
2725
2755
  * representation of all the search results.
@@ -2917,6 +2947,39 @@ type AnswerStreamResponse = {
2917
2947
  answer?: string;
2918
2948
  citations?: SearchResult<{}>[];
2919
2949
  };
2950
+ /**
2951
+ * Enhanced answer options that accepts either JSON schema or Zod schema
2952
+ */
2953
+ type AnswerOptionsTyped<T> = Omit<AnswerOptions, "outputSchema"> & {
2954
+ outputSchema: T;
2955
+ };
2956
+ /**
2957
+ * Enhanced answer response with strongly typed answer when using Zod
2958
+ */
2959
+ type AnswerResponseTyped<T> = Omit<AnswerResponse, "answer"> & {
2960
+ answer: T;
2961
+ };
2962
+ /**
2963
+ * Enhanced summary contents options that accepts either JSON schema or Zod schema
2964
+ */
2965
+ type SummaryContentsOptionsTyped<T> = Omit<SummaryContentsOptions, "schema"> & {
2966
+ schema: T;
2967
+ };
2968
+ /**
2969
+ * Enhanced research task output options that accepts either JSON schema or Zod schema
2970
+ */
2971
+ type ResearchTaskOutputTyped<T> = {
2972
+ inferSchema?: boolean;
2973
+ schema: T;
2974
+ };
2975
+ /**
2976
+ * Enhanced research task creation params with zod schema support
2977
+ */
2978
+ type ResearchCreateTaskParamsTyped<T> = {
2979
+ instructions: string;
2980
+ model?: "exa-research" | "exa-research-pro";
2981
+ output?: ResearchTaskOutputTyped<T>;
2982
+ };
2920
2983
  /**
2921
2984
  * The Exa class encapsulates the API's endpoints.
2922
2985
  */
@@ -2989,6 +3052,10 @@ declare class Exa {
2989
3052
  * @returns {Promise<SearchResponse<T>>} A list of document contents for the requested URLs.
2990
3053
  */
2991
3054
  getContents<T extends ContentsOptions>(urls: string | string[] | SearchResult<T>[], options?: T): Promise<SearchResponse<T>>;
3055
+ /**
3056
+ * Generate an answer with Zod schema for strongly typed output
3057
+ */
3058
+ answer<T>(query: string, options: AnswerOptionsTyped<ZodSchema<T>>): Promise<AnswerResponseTyped<T>>;
2992
3059
  /**
2993
3060
  * Generate an answer to a query.
2994
3061
  * @param {string} query - The question or query to answer.
@@ -3012,6 +3079,16 @@ declare class Exa {
3012
3079
  * ```
3013
3080
  */
3014
3081
  answer(query: string, options?: AnswerOptions): Promise<AnswerResponse>;
3082
+ /**
3083
+ * Stream an answer with Zod schema for structured output (non-streaming content)
3084
+ * Note: Structured output works only with non-streaming content, not with streaming chunks
3085
+ */
3086
+ streamAnswer<T>(query: string, options: {
3087
+ text?: boolean;
3088
+ model?: "exa" | "exa-pro";
3089
+ systemPrompt?: string;
3090
+ outputSchema: ZodSchema<T>;
3091
+ }): AsyncGenerator<AnswerStreamChunk>;
3015
3092
  /**
3016
3093
  * Stream an answer as an async generator
3017
3094
  *
@@ -3041,4 +3118,4 @@ declare class Exa {
3041
3118
  private parseSSEStream;
3042
3119
  }
3043
3120
 
3044
- export { type AnswerOptions, type AnswerResponse, type AnswerStreamChunk, type AnswerStreamResponse, type ArticleEntity, type BaseSearchOptions, type CompanyEntity, type ContentsOptions, type ContentsResultComponent, type ContextOptions, type CostDollars, type CostDollarsContents, type CostDollarsSeearch, type CreateCriterionParameters, type CreateEnrichmentParameters, CreateEnrichmentParametersFormat, type CreateImportParameters, CreateImportParametersFormat, type CreateImportResponse, type CreateImportWithCsvParameters, type CreateMonitorParameters, type CreateWebhookParameters, type CreateWebsetParameters, CreateWebsetParametersImportSource, CreateWebsetParametersSearchExcludeSource, type CreateWebsetSearchParameters, CreateWebsetSearchParametersExcludeSource, type CsvDataInput, type CustomEntity, type Default, type EnrichmentResult, type Entity, type Event, EventType, EventsClient, Exa, ExaError, type ExtrasOptions, type ExtrasResponse, type FindSimilarOptions, type GetWebsetResponse, type HighlightsContentsOptions, type HighlightsResponse, HttpStatusCode, type Import, ImportFailedReason, ImportFormat, ImportObject, ImportStatus, ImportsClient, type JSONSchema, type ListEventsResponse, type ListImportsResponse, type ListMonitorRunsResponse, type ListMonitorsOptions, type ListMonitorsResponse, type SchemaListResearchTasksRequestDto as ListResearchTasksRequest, type SchemaListResearchTasksResponseDto as ListResearchTasksResponse, type ListWebhookAttemptsResponse, type ListWebhooksResponse, type ListWebsetItemResponse, type ListWebsetsResponse, type LivecrawlOptions, type Monitor, type MonitorBehavior, type MonitorCadence, MonitorObject, type MonitorRun, MonitorRunObject, MonitorRunStatus, MonitorRunType, MonitorStatus, type PersonEntity, type RegularSearchOptions, ResearchClient, type SchemaResearchCreateTaskRequestDto as ResearchCreateTaskRequest, type SchemaResearchCreateTaskResponseDto as ResearchCreateTaskResponse, type ResearchPaperEntity, type SchemaResearchTaskDto as ResearchTask, type ResearchTaskEvent, type ResearchTaskOperation, type SearchResponse, type SearchResult, type Status, type SubpagesResponse, type SummaryContentsOptions, type SummaryResponse, type TextContentsOptions, type TextResponse, type UpdateImport, type UpdateMonitor, UpdateMonitorStatus, type UpdateWebhookParameters, type UpdateWebsetRequest, type WaitUntilCompletedOptions, type Webhook, type WebhookAttempt, WebhookStatus, type Webset, type WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, type WebsetItem, type WebsetItemArticleProperties, type WebsetItemCompanyProperties, type WebsetItemCustomProperties, type WebsetItemEvaluation, WebsetItemEvaluationSatisfied, type WebsetItemPersonProperties, type WebsetItemResearchPaperProperties, WebsetItemSource, WebsetItemsClient, WebsetMonitorsClient, type WebsetSearch, WebsetSearchBehavior, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
3121
+ export { type AnswerOptions, type AnswerOptionsTyped, type AnswerResponse, type AnswerResponseTyped, type AnswerStreamChunk, type AnswerStreamResponse, type ArticleEntity, type BaseSearchOptions, type CompanyEntity, type ContentsOptions, type ContentsResultComponent, type ContextOptions, type CostDollars, type CostDollarsContents, type CostDollarsSeearch, type CreateCriterionParameters, type CreateEnrichmentParameters, CreateEnrichmentParametersFormat, type CreateImportParameters, CreateImportParametersFormat, type CreateImportResponse, type CreateImportWithCsvParameters, type CreateMonitorParameters, type CreateWebhookParameters, type CreateWebsetParameters, CreateWebsetParametersImportSource, CreateWebsetParametersSearchExcludeSource, type CreateWebsetSearchParameters, CreateWebsetSearchParametersExcludeSource, type CsvDataInput, type CustomEntity, type Default, type EnrichmentResult, type Entity, type Event, EventType, EventsClient, Exa, ExaError, type ExtrasOptions, type ExtrasResponse, type FindSimilarOptions, type GetWebsetResponse, type HighlightsContentsOptions, type HighlightsResponse, HttpStatusCode, type Import, ImportFailedReason, ImportFormat, ImportObject, ImportStatus, ImportsClient, type JSONSchema, type ListEventsResponse, type ListImportsResponse, type ListMonitorRunsResponse, type ListMonitorsOptions, type ListMonitorsResponse, type SchemaListResearchTasksRequestDto as ListResearchTasksRequest, type SchemaListResearchTasksResponseDto as ListResearchTasksResponse, type ListWebhookAttemptsResponse, type ListWebhooksResponse, type ListWebsetItemResponse, type ListWebsetsResponse, type LivecrawlOptions, type Monitor, type MonitorBehavior, type MonitorCadence, MonitorObject, type MonitorRun, MonitorRunObject, MonitorRunStatus, MonitorRunType, MonitorStatus, type PersonEntity, type RegularSearchOptions, ResearchClient, type ResearchCreateTaskParamsTyped, type SchemaResearchCreateTaskRequestDto as ResearchCreateTaskRequest, type SchemaResearchCreateTaskResponseDto as ResearchCreateTaskResponse, type ResearchPaperEntity, type SchemaResearchTaskDto as ResearchTask, type ResearchTaskEvent, type ResearchTaskOperation, type ResearchTaskOutputTyped, type SearchResponse, type SearchResult, type Status, type SubpagesResponse, type SummaryContentsOptions, type SummaryContentsOptionsTyped, type SummaryResponse, type TextContentsOptions, type TextResponse, type UpdateImport, type UpdateMonitor, UpdateMonitorStatus, type UpdateWebhookParameters, type UpdateWebsetRequest, type WaitUntilCompletedOptions, type Webhook, type WebhookAttempt, WebhookStatus, type Webset, type WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, type WebsetItem, type WebsetItemArticleProperties, type WebsetItemCompanyProperties, type WebsetItemCustomProperties, type WebsetItemEvaluation, WebsetItemEvaluationSatisfied, type WebsetItemPersonProperties, type WebsetItemResearchPaperProperties, WebsetItemSource, WebsetItemsClient, WebsetMonitorsClient, type WebsetSearch, WebsetSearchBehavior, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ZodSchema } from 'zod';
2
+
1
3
  /**
2
4
  * Base client for Websets API
3
5
  */
@@ -287,6 +289,8 @@ interface components$1 {
287
289
  *
288
290
  * Any URLs provided will be crawled and used as additional context for the search. */
289
291
  query: string;
292
+ /** @description Whether to compute recall metrics for the search */
293
+ recall?: boolean;
290
294
  };
291
295
  };
292
296
  CreateWebsetSearchParameters: {
@@ -327,12 +331,11 @@ interface components$1 {
327
331
  *
328
332
  * Any URLs provided will be crawled and used as additional context for the search. */
329
333
  query: string;
334
+ /** @description Whether to compute recall metrics for the search */
335
+ recall?: boolean;
330
336
  };
331
337
  /** Custom */
332
338
  CustomEntity: {
333
- /** @description When you decide to use a custom entity, this is the description of the entity.
334
- *
335
- * The entity represents what type of results the will return. For example, if you want results to be Job Postings, you might use "Job Postings" as the entity description. */
336
339
  description: string;
337
340
  /**
338
341
  * @default custom
@@ -362,6 +365,11 @@ interface components$1 {
362
365
  }[];
363
366
  /** @description The result of the enrichment. */
364
367
  result: string[] | null;
368
+ /**
369
+ * @description The status of the enrichment result.
370
+ * @enum {string}
371
+ */
372
+ status: EnrichmentResultStatus;
365
373
  };
366
374
  Entity: components$1["schemas"]["CompanyEntity"] | components$1["schemas"]["PersonEntity"] | components$1["schemas"]["ArticleEntity"] | components$1["schemas"]["ResearchPaperEntity"] | components$1["schemas"]["CustomEntity"];
367
375
  /** Event */
@@ -557,6 +565,7 @@ interface components$1 {
557
565
  type: "webset.search.completed";
558
566
  };
559
567
  /** @enum {string} */
568
+ EventType: EventType;
560
569
  GetWebsetResponse: components$1["schemas"]["Webset"] & {
561
570
  /** @description When expand query parameter contains `items`, this will contain the items in the webset */
562
571
  items?: components$1["schemas"]["WebsetItem"][];
@@ -1332,13 +1341,37 @@ interface components$1 {
1332
1341
  object: "webset_search";
1333
1342
  /** @description The progress of the search */
1334
1343
  progress: {
1344
+ /** @description The number of results analyzed so far */
1345
+ analyzed: number;
1335
1346
  /** @description The completion percentage of the search */
1336
1347
  completion: number;
1337
1348
  /** @description The number of results found so far */
1338
1349
  found: number;
1350
+ /** @description The estimated time remaining in seconds, null if unknown */
1351
+ timeLeft: number | null;
1339
1352
  };
1340
1353
  /** @description The query used to create the search. */
1341
1354
  query: string;
1355
+ /** @description Recall metrics for the search, null if not yet computed or requested. */
1356
+ recall: {
1357
+ expected: {
1358
+ bounds: {
1359
+ /** @description The maximum estimated total number of potential matches */
1360
+ max: number;
1361
+ /** @description The minimum estimated total number of potential matches */
1362
+ min: number;
1363
+ };
1364
+ /**
1365
+ * @description The confidence in the estimate
1366
+ * @enum {string}
1367
+ */
1368
+ confidence: WebsetSearchRecallExpectedConfidence;
1369
+ /** @description The estimated total number of potential matches */
1370
+ total: number;
1371
+ };
1372
+ /** @description The reasoning for the estimate */
1373
+ reasoning: string;
1374
+ } | null;
1342
1375
  /**
1343
1376
  * WebsetSearchStatus
1344
1377
  * @description The status of the search
@@ -1449,6 +1482,11 @@ declare enum CreateWebsetSearchParametersExcludeSource {
1449
1482
  import = "import",
1450
1483
  webset = "webset"
1451
1484
  }
1485
+ declare enum EnrichmentResultStatus {
1486
+ pending = "pending",
1487
+ completed = "completed",
1488
+ canceled = "canceled"
1489
+ }
1452
1490
  declare enum EventType {
1453
1491
  webset_created = "webset.created",
1454
1492
  webset_deleted = "webset.deleted",
@@ -1564,6 +1602,11 @@ declare enum WebsetSearchExcludeSource {
1564
1602
  import = "import",
1565
1603
  webset = "webset"
1566
1604
  }
1605
+ declare enum WebsetSearchRecallExpectedConfidence {
1606
+ high = "high",
1607
+ medium = "medium",
1608
+ low = "low"
1609
+ }
1567
1610
  declare enum WebsetSearchStatus {
1568
1611
  created = "created",
1569
1612
  running = "running",
@@ -2144,6 +2187,10 @@ declare class ResearchBaseClient {
2144
2187
  */
2145
2188
  declare class ResearchClient extends ResearchBaseClient {
2146
2189
  constructor(client: Exa);
2190
+ /**
2191
+ * Create a new research task with Zod schema for strongly typed output
2192
+ */
2193
+ createTask<T>(params: ResearchCreateTaskParamsTyped<ZodSchema<T>>): Promise<SchemaResearchCreateTaskResponseDto>;
2147
2194
  /**
2148
2195
  * Create a new research task.
2149
2196
  *
@@ -2697,29 +2744,12 @@ type HighlightsContentsOptions = {
2697
2744
  */
2698
2745
  type SummaryContentsOptions = {
2699
2746
  query?: string;
2700
- schema?: JSONSchema;
2747
+ schema?: Record<string, unknown> | ZodSchema;
2701
2748
  };
2702
2749
  /**
2703
- * Represents a JSON Schema definition used for structured summary output.
2704
- * To learn more visit https://json-schema.org/overview/what-is-jsonschema.
2750
+ * @deprecated Use Record<string, unknown> instead.
2705
2751
  */
2706
- type JSONSchema = {
2707
- $schema?: string;
2708
- title?: string;
2709
- description?: string;
2710
- type: "object" | "array" | "string" | "number" | "boolean" | "null" | "integer";
2711
- properties?: Record<string, JSONSchema>;
2712
- items?: JSONSchema | JSONSchema[];
2713
- required?: string[];
2714
- enum?: any[];
2715
- additionalProperties?: boolean | JSONSchema;
2716
- definitions?: Record<string, JSONSchema>;
2717
- patternProperties?: Record<string, JSONSchema>;
2718
- allOf?: JSONSchema[];
2719
- anyOf?: JSONSchema[];
2720
- oneOf?: JSONSchema[];
2721
- not?: JSONSchema;
2722
- };
2752
+ type JSONSchema = Record<string, unknown>;
2723
2753
  /**
2724
2754
  * Options for retrieving the context from a list of search results. The context is a string
2725
2755
  * representation of all the search results.
@@ -2917,6 +2947,39 @@ type AnswerStreamResponse = {
2917
2947
  answer?: string;
2918
2948
  citations?: SearchResult<{}>[];
2919
2949
  };
2950
+ /**
2951
+ * Enhanced answer options that accepts either JSON schema or Zod schema
2952
+ */
2953
+ type AnswerOptionsTyped<T> = Omit<AnswerOptions, "outputSchema"> & {
2954
+ outputSchema: T;
2955
+ };
2956
+ /**
2957
+ * Enhanced answer response with strongly typed answer when using Zod
2958
+ */
2959
+ type AnswerResponseTyped<T> = Omit<AnswerResponse, "answer"> & {
2960
+ answer: T;
2961
+ };
2962
+ /**
2963
+ * Enhanced summary contents options that accepts either JSON schema or Zod schema
2964
+ */
2965
+ type SummaryContentsOptionsTyped<T> = Omit<SummaryContentsOptions, "schema"> & {
2966
+ schema: T;
2967
+ };
2968
+ /**
2969
+ * Enhanced research task output options that accepts either JSON schema or Zod schema
2970
+ */
2971
+ type ResearchTaskOutputTyped<T> = {
2972
+ inferSchema?: boolean;
2973
+ schema: T;
2974
+ };
2975
+ /**
2976
+ * Enhanced research task creation params with zod schema support
2977
+ */
2978
+ type ResearchCreateTaskParamsTyped<T> = {
2979
+ instructions: string;
2980
+ model?: "exa-research" | "exa-research-pro";
2981
+ output?: ResearchTaskOutputTyped<T>;
2982
+ };
2920
2983
  /**
2921
2984
  * The Exa class encapsulates the API's endpoints.
2922
2985
  */
@@ -2989,6 +3052,10 @@ declare class Exa {
2989
3052
  * @returns {Promise<SearchResponse<T>>} A list of document contents for the requested URLs.
2990
3053
  */
2991
3054
  getContents<T extends ContentsOptions>(urls: string | string[] | SearchResult<T>[], options?: T): Promise<SearchResponse<T>>;
3055
+ /**
3056
+ * Generate an answer with Zod schema for strongly typed output
3057
+ */
3058
+ answer<T>(query: string, options: AnswerOptionsTyped<ZodSchema<T>>): Promise<AnswerResponseTyped<T>>;
2992
3059
  /**
2993
3060
  * Generate an answer to a query.
2994
3061
  * @param {string} query - The question or query to answer.
@@ -3012,6 +3079,16 @@ declare class Exa {
3012
3079
  * ```
3013
3080
  */
3014
3081
  answer(query: string, options?: AnswerOptions): Promise<AnswerResponse>;
3082
+ /**
3083
+ * Stream an answer with Zod schema for structured output (non-streaming content)
3084
+ * Note: Structured output works only with non-streaming content, not with streaming chunks
3085
+ */
3086
+ streamAnswer<T>(query: string, options: {
3087
+ text?: boolean;
3088
+ model?: "exa" | "exa-pro";
3089
+ systemPrompt?: string;
3090
+ outputSchema: ZodSchema<T>;
3091
+ }): AsyncGenerator<AnswerStreamChunk>;
3015
3092
  /**
3016
3093
  * Stream an answer as an async generator
3017
3094
  *
@@ -3041,4 +3118,4 @@ declare class Exa {
3041
3118
  private parseSSEStream;
3042
3119
  }
3043
3120
 
3044
- export { type AnswerOptions, type AnswerResponse, type AnswerStreamChunk, type AnswerStreamResponse, type ArticleEntity, type BaseSearchOptions, type CompanyEntity, type ContentsOptions, type ContentsResultComponent, type ContextOptions, type CostDollars, type CostDollarsContents, type CostDollarsSeearch, type CreateCriterionParameters, type CreateEnrichmentParameters, CreateEnrichmentParametersFormat, type CreateImportParameters, CreateImportParametersFormat, type CreateImportResponse, type CreateImportWithCsvParameters, type CreateMonitorParameters, type CreateWebhookParameters, type CreateWebsetParameters, CreateWebsetParametersImportSource, CreateWebsetParametersSearchExcludeSource, type CreateWebsetSearchParameters, CreateWebsetSearchParametersExcludeSource, type CsvDataInput, type CustomEntity, type Default, type EnrichmentResult, type Entity, type Event, EventType, EventsClient, Exa, ExaError, type ExtrasOptions, type ExtrasResponse, type FindSimilarOptions, type GetWebsetResponse, type HighlightsContentsOptions, type HighlightsResponse, HttpStatusCode, type Import, ImportFailedReason, ImportFormat, ImportObject, ImportStatus, ImportsClient, type JSONSchema, type ListEventsResponse, type ListImportsResponse, type ListMonitorRunsResponse, type ListMonitorsOptions, type ListMonitorsResponse, type SchemaListResearchTasksRequestDto as ListResearchTasksRequest, type SchemaListResearchTasksResponseDto as ListResearchTasksResponse, type ListWebhookAttemptsResponse, type ListWebhooksResponse, type ListWebsetItemResponse, type ListWebsetsResponse, type LivecrawlOptions, type Monitor, type MonitorBehavior, type MonitorCadence, MonitorObject, type MonitorRun, MonitorRunObject, MonitorRunStatus, MonitorRunType, MonitorStatus, type PersonEntity, type RegularSearchOptions, ResearchClient, type SchemaResearchCreateTaskRequestDto as ResearchCreateTaskRequest, type SchemaResearchCreateTaskResponseDto as ResearchCreateTaskResponse, type ResearchPaperEntity, type SchemaResearchTaskDto as ResearchTask, type ResearchTaskEvent, type ResearchTaskOperation, type SearchResponse, type SearchResult, type Status, type SubpagesResponse, type SummaryContentsOptions, type SummaryResponse, type TextContentsOptions, type TextResponse, type UpdateImport, type UpdateMonitor, UpdateMonitorStatus, type UpdateWebhookParameters, type UpdateWebsetRequest, type WaitUntilCompletedOptions, type Webhook, type WebhookAttempt, WebhookStatus, type Webset, type WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, type WebsetItem, type WebsetItemArticleProperties, type WebsetItemCompanyProperties, type WebsetItemCustomProperties, type WebsetItemEvaluation, WebsetItemEvaluationSatisfied, type WebsetItemPersonProperties, type WebsetItemResearchPaperProperties, WebsetItemSource, WebsetItemsClient, WebsetMonitorsClient, type WebsetSearch, WebsetSearchBehavior, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
3121
+ export { type AnswerOptions, type AnswerOptionsTyped, type AnswerResponse, type AnswerResponseTyped, type AnswerStreamChunk, type AnswerStreamResponse, type ArticleEntity, type BaseSearchOptions, type CompanyEntity, type ContentsOptions, type ContentsResultComponent, type ContextOptions, type CostDollars, type CostDollarsContents, type CostDollarsSeearch, type CreateCriterionParameters, type CreateEnrichmentParameters, CreateEnrichmentParametersFormat, type CreateImportParameters, CreateImportParametersFormat, type CreateImportResponse, type CreateImportWithCsvParameters, type CreateMonitorParameters, type CreateWebhookParameters, type CreateWebsetParameters, CreateWebsetParametersImportSource, CreateWebsetParametersSearchExcludeSource, type CreateWebsetSearchParameters, CreateWebsetSearchParametersExcludeSource, type CsvDataInput, type CustomEntity, type Default, type EnrichmentResult, type Entity, type Event, EventType, EventsClient, Exa, ExaError, type ExtrasOptions, type ExtrasResponse, type FindSimilarOptions, type GetWebsetResponse, type HighlightsContentsOptions, type HighlightsResponse, HttpStatusCode, type Import, ImportFailedReason, ImportFormat, ImportObject, ImportStatus, ImportsClient, type JSONSchema, type ListEventsResponse, type ListImportsResponse, type ListMonitorRunsResponse, type ListMonitorsOptions, type ListMonitorsResponse, type SchemaListResearchTasksRequestDto as ListResearchTasksRequest, type SchemaListResearchTasksResponseDto as ListResearchTasksResponse, type ListWebhookAttemptsResponse, type ListWebhooksResponse, type ListWebsetItemResponse, type ListWebsetsResponse, type LivecrawlOptions, type Monitor, type MonitorBehavior, type MonitorCadence, MonitorObject, type MonitorRun, MonitorRunObject, MonitorRunStatus, MonitorRunType, MonitorStatus, type PersonEntity, type RegularSearchOptions, ResearchClient, type ResearchCreateTaskParamsTyped, type SchemaResearchCreateTaskRequestDto as ResearchCreateTaskRequest, type SchemaResearchCreateTaskResponseDto as ResearchCreateTaskResponse, type ResearchPaperEntity, type SchemaResearchTaskDto as ResearchTask, type ResearchTaskEvent, type ResearchTaskOperation, type ResearchTaskOutputTyped, type SearchResponse, type SearchResult, type Status, type SubpagesResponse, type SummaryContentsOptions, type SummaryContentsOptionsTyped, type SummaryResponse, type TextContentsOptions, type TextResponse, type UpdateImport, type UpdateMonitor, UpdateMonitorStatus, type UpdateWebhookParameters, type UpdateWebsetRequest, type WaitUntilCompletedOptions, type Webhook, type WebhookAttempt, WebhookStatus, type Webset, type WebsetEnrichment, WebsetEnrichmentFormat, WebsetEnrichmentStatus, WebsetEnrichmentsClient, type WebsetItem, type WebsetItemArticleProperties, type WebsetItemCompanyProperties, type WebsetItemCustomProperties, type WebsetItemEvaluation, WebsetItemEvaluationSatisfied, type WebsetItemPersonProperties, type WebsetItemResearchPaperProperties, WebsetItemSource, WebsetItemsClient, WebsetMonitorsClient, type WebsetSearch, WebsetSearchBehavior, WebsetSearchCanceledReason, WebsetSearchStatus, WebsetSearchesClient, WebsetStatus, WebsetWebhooksClient, WebsetsClient, Exa as default };
package/dist/index.js CHANGED
@@ -1024,6 +1024,18 @@ var WebsetsClient = class extends WebsetsBaseClient {
1024
1024
  }
1025
1025
  };
1026
1026
 
1027
+ // src/zod-utils.ts
1028
+ var import_zod = require("zod");
1029
+ var import_zod_to_json_schema = require("zod-to-json-schema");
1030
+ function isZodSchema(obj) {
1031
+ return obj instanceof import_zod.ZodType;
1032
+ }
1033
+ function zodToJsonSchema(schema) {
1034
+ return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, {
1035
+ $refStrategy: "none"
1036
+ });
1037
+ }
1038
+
1027
1039
  // src/research/base.ts
1028
1040
  var ResearchBaseClient = class {
1029
1041
  /**
@@ -1084,23 +1096,17 @@ var ResearchClient = class extends ResearchBaseClient {
1084
1096
  constructor(client) {
1085
1097
  super(client);
1086
1098
  }
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
1099
  async createTask(params) {
1098
1100
  const { instructions, model, output } = params;
1101
+ let schema = output?.schema;
1102
+ if (schema && isZodSchema(schema)) {
1103
+ schema = zodToJsonSchema(schema);
1104
+ }
1099
1105
  const payload = {
1100
1106
  instructions,
1101
1107
  model: model ?? "exa-research",
1102
1108
  output: output ? {
1103
- schema: output.schema,
1109
+ schema,
1104
1110
  inferSchema: output.inferSchema ?? true
1105
1111
  } : { inferSchema: true }
1106
1112
  };
@@ -1233,7 +1239,16 @@ var Exa2 = class {
1233
1239
  contentsOptions.text = true;
1234
1240
  }
1235
1241
  if (text !== void 0) contentsOptions.text = text;
1236
- if (summary !== void 0) contentsOptions.summary = summary;
1242
+ if (summary !== void 0) {
1243
+ if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema(summary.schema)) {
1244
+ contentsOptions.summary = {
1245
+ ...summary,
1246
+ schema: zodToJsonSchema(summary.schema)
1247
+ };
1248
+ } else {
1249
+ contentsOptions.summary = summary;
1250
+ }
1251
+ }
1237
1252
  if (highlights !== void 0) contentsOptions.highlights = highlights;
1238
1253
  if (subpages !== void 0) contentsOptions.subpages = subpages;
1239
1254
  if (subpageTarget !== void 0)
@@ -1426,28 +1441,6 @@ var Exa2 = class {
1426
1441
  };
1427
1442
  return await this.request("/contents", "POST", payload);
1428
1443
  }
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
1444
  async answer(query, options) {
1452
1445
  if (options?.stream) {
1453
1446
  throw new ExaError(
@@ -1455,43 +1448,32 @@ var Exa2 = class {
1455
1448
  400 /* BadRequest */
1456
1449
  );
1457
1450
  }
1451
+ let outputSchema = options?.outputSchema;
1452
+ if (outputSchema && isZodSchema(outputSchema)) {
1453
+ outputSchema = zodToJsonSchema(outputSchema);
1454
+ }
1458
1455
  const requestBody = {
1459
1456
  query,
1460
1457
  stream: false,
1461
1458
  text: options?.text ?? false,
1462
1459
  model: options?.model ?? "exa",
1463
1460
  systemPrompt: options?.systemPrompt,
1464
- outputSchema: options?.outputSchema
1461
+ outputSchema
1465
1462
  };
1466
1463
  return await this.request("/answer", "POST", requestBody);
1467
1464
  }
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
1465
  async *streamAnswer(query, options) {
1466
+ let outputSchema = options?.outputSchema;
1467
+ if (outputSchema && isZodSchema(outputSchema)) {
1468
+ outputSchema = zodToJsonSchema(outputSchema);
1469
+ }
1488
1470
  const body = {
1489
1471
  query,
1490
1472
  text: options?.text ?? false,
1491
1473
  stream: true,
1492
1474
  model: options?.model ?? "exa",
1493
1475
  systemPrompt: options?.systemPrompt,
1494
- outputSchema: options?.outputSchema
1476
+ outputSchema
1495
1477
  };
1496
1478
  const response = await fetchImpl(this.baseURL + "/answer", {
1497
1479
  method: "POST",