exa-js 1.8.18 → 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
  */
@@ -2185,6 +2187,10 @@ declare class ResearchBaseClient {
2185
2187
  */
2186
2188
  declare class ResearchClient extends ResearchBaseClient {
2187
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>;
2188
2194
  /**
2189
2195
  * Create a new research task.
2190
2196
  *
@@ -2738,29 +2744,12 @@ type HighlightsContentsOptions = {
2738
2744
  */
2739
2745
  type SummaryContentsOptions = {
2740
2746
  query?: string;
2741
- schema?: JSONSchema;
2747
+ schema?: Record<string, unknown> | ZodSchema;
2742
2748
  };
2743
2749
  /**
2744
- * Represents a JSON Schema definition used for structured summary output.
2745
- * To learn more visit https://json-schema.org/overview/what-is-jsonschema.
2750
+ * @deprecated Use Record<string, unknown> instead.
2746
2751
  */
2747
- type JSONSchema = {
2748
- $schema?: string;
2749
- title?: string;
2750
- description?: string;
2751
- type: "object" | "array" | "string" | "number" | "boolean" | "null" | "integer";
2752
- properties?: Record<string, JSONSchema>;
2753
- items?: JSONSchema | JSONSchema[];
2754
- required?: string[];
2755
- enum?: any[];
2756
- additionalProperties?: boolean | JSONSchema;
2757
- definitions?: Record<string, JSONSchema>;
2758
- patternProperties?: Record<string, JSONSchema>;
2759
- allOf?: JSONSchema[];
2760
- anyOf?: JSONSchema[];
2761
- oneOf?: JSONSchema[];
2762
- not?: JSONSchema;
2763
- };
2752
+ type JSONSchema = Record<string, unknown>;
2764
2753
  /**
2765
2754
  * Options for retrieving the context from a list of search results. The context is a string
2766
2755
  * representation of all the search results.
@@ -2958,6 +2947,39 @@ type AnswerStreamResponse = {
2958
2947
  answer?: string;
2959
2948
  citations?: SearchResult<{}>[];
2960
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
+ };
2961
2983
  /**
2962
2984
  * The Exa class encapsulates the API's endpoints.
2963
2985
  */
@@ -3030,6 +3052,10 @@ declare class Exa {
3030
3052
  * @returns {Promise<SearchResponse<T>>} A list of document contents for the requested URLs.
3031
3053
  */
3032
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>>;
3033
3059
  /**
3034
3060
  * Generate an answer to a query.
3035
3061
  * @param {string} query - The question or query to answer.
@@ -3053,6 +3079,16 @@ declare class Exa {
3053
3079
  * ```
3054
3080
  */
3055
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>;
3056
3092
  /**
3057
3093
  * Stream an answer as an async generator
3058
3094
  *
@@ -3082,4 +3118,4 @@ declare class Exa {
3082
3118
  private parseSSEStream;
3083
3119
  }
3084
3120
 
3085
- 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
  */
@@ -2185,6 +2187,10 @@ declare class ResearchBaseClient {
2185
2187
  */
2186
2188
  declare class ResearchClient extends ResearchBaseClient {
2187
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>;
2188
2194
  /**
2189
2195
  * Create a new research task.
2190
2196
  *
@@ -2738,29 +2744,12 @@ type HighlightsContentsOptions = {
2738
2744
  */
2739
2745
  type SummaryContentsOptions = {
2740
2746
  query?: string;
2741
- schema?: JSONSchema;
2747
+ schema?: Record<string, unknown> | ZodSchema;
2742
2748
  };
2743
2749
  /**
2744
- * Represents a JSON Schema definition used for structured summary output.
2745
- * To learn more visit https://json-schema.org/overview/what-is-jsonschema.
2750
+ * @deprecated Use Record<string, unknown> instead.
2746
2751
  */
2747
- type JSONSchema = {
2748
- $schema?: string;
2749
- title?: string;
2750
- description?: string;
2751
- type: "object" | "array" | "string" | "number" | "boolean" | "null" | "integer";
2752
- properties?: Record<string, JSONSchema>;
2753
- items?: JSONSchema | JSONSchema[];
2754
- required?: string[];
2755
- enum?: any[];
2756
- additionalProperties?: boolean | JSONSchema;
2757
- definitions?: Record<string, JSONSchema>;
2758
- patternProperties?: Record<string, JSONSchema>;
2759
- allOf?: JSONSchema[];
2760
- anyOf?: JSONSchema[];
2761
- oneOf?: JSONSchema[];
2762
- not?: JSONSchema;
2763
- };
2752
+ type JSONSchema = Record<string, unknown>;
2764
2753
  /**
2765
2754
  * Options for retrieving the context from a list of search results. The context is a string
2766
2755
  * representation of all the search results.
@@ -2958,6 +2947,39 @@ type AnswerStreamResponse = {
2958
2947
  answer?: string;
2959
2948
  citations?: SearchResult<{}>[];
2960
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
+ };
2961
2983
  /**
2962
2984
  * The Exa class encapsulates the API's endpoints.
2963
2985
  */
@@ -3030,6 +3052,10 @@ declare class Exa {
3030
3052
  * @returns {Promise<SearchResponse<T>>} A list of document contents for the requested URLs.
3031
3053
  */
3032
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>>;
3033
3059
  /**
3034
3060
  * Generate an answer to a query.
3035
3061
  * @param {string} query - The question or query to answer.
@@ -3053,6 +3079,16 @@ declare class Exa {
3053
3079
  * ```
3054
3080
  */
3055
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>;
3056
3092
  /**
3057
3093
  * Stream an answer as an async generator
3058
3094
  *
@@ -3082,4 +3118,4 @@ declare class Exa {
3082
3118
  private parseSSEStream;
3083
3119
  }
3084
3120
 
3085
- 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",