@howells/fieldwork-sdk 0.2.0 → 0.3.1

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.
@@ -29,41 +29,37 @@ var FieldworkError = class extends Error {
29
29
  /** The fields an agent or a log needs, without the provider's response. */
30
30
  toJSON() {
31
31
  return {
32
- name: this.name,
33
32
  code: this.code,
33
+ jobId: this.jobId,
34
34
  message: this.message,
35
+ name: this.name,
35
36
  provider: this.provider,
36
- status: this.status,
37
- retryable: this.retryable,
38
37
  retryAfter: this.retryAfter,
39
- jobId: this.jobId
38
+ retryable: this.retryable,
39
+ status: this.status
40
40
  };
41
41
  }
42
42
  };
43
- function isRetryable(code, status) {
43
+ const isRetryable = (code, status) => {
44
44
  if (code === "RateLimited" || code === "Timeout") return true;
45
45
  return status !== void 0 && status >= 500;
46
- }
47
- /**
48
- * Attaches a job id to an error raised while following that job, so the
49
- * caller can resume it. Errors that are not Fieldwork's pass through.
50
- */
51
- function withJob(error, jobId) {
46
+ };
47
+ const withJob = (error, jobId) => {
52
48
  if (!(error instanceof FieldworkError) || error.jobId !== void 0) return error;
53
49
  return new FieldworkError(error.code, error.message, {
50
+ cause: error.cause,
51
+ jobId,
54
52
  provider: error.provider,
55
- status: error.status,
56
53
  retryAfter: error.retryAfter,
57
- jobId,
58
- cause: error.cause
54
+ status: error.status
59
55
  });
60
- }
61
- function codeForStatus(status) {
56
+ };
57
+ const codeForStatus = (status) => {
62
58
  if (status === 401 || status === 403) return "Unauthorized";
63
59
  if (status === 404) return "NotFound";
64
60
  if (status === 408) return "Timeout";
65
- if (status === 429 || status === 432 || status === 433) return "RateLimited";
61
+ if (status === 429 || status === 432 || status === 433 || status === 434) return "RateLimited";
66
62
  if (status === 400 || status === 422) return "InvalidRequest";
67
63
  return "ProviderError";
68
- }
64
+ };
69
65
  export { codeForStatus as n, withJob as r, FieldworkError as t };
package/dist/exa.d.ts CHANGED
@@ -1,53 +1,136 @@
1
- import { C as SearchResponse, S as Research, _ as JsonSchema, a as RawClient, h as Extraction, l as CallOptions, t as Adapter, v as Page } from "./adapter-C_kRm6TT.js";
2
- export interface ExaConfig {
1
+ import { A as JsonSchema, F as MonitorSchedule, G as Research, I as Page, L as PageBatch, N as MonitorEvents, P as MonitorInfo, a as RawClient, f as CallOptions, l as Answer, q as SearchResponse, t as Adapter, w as Extraction } from "./adapter-DGehHCMo.js";
2
+ interface ExaConfig {
3
3
  /** Defaults to the EXA_API_KEY environment variable. */
4
4
  apiKey?: string;
5
5
  baseUrl?: string;
6
6
  fetch?: typeof fetch;
7
7
  }
8
- export interface ExaSearchOptions extends CallOptions {
9
- /** Results to return; Exa allows up to 100. */
8
+ /**
9
+ * Exa's `outputSchema` for generated output: free text, or an object schema.
10
+ * Exa limits an object schema to 10 properties in total (nested ones count),
11
+ * 2 levels of nesting, and an `items` entry on every array.
12
+ */
13
+ type ExaOutputSchema = {
14
+ type: "text";
15
+ description?: string;
16
+ } | {
17
+ type: "object";
18
+ description?: string;
19
+ properties?: Record<string, unknown>;
20
+ required?: string[];
21
+ additionalProperties?: boolean;
22
+ };
23
+ interface ExaHighlightOptions {
24
+ /** Guides which passages Exa picks. Defaults to the search query. */
25
+ query?: string;
26
+ /** Total highlight length per page, in characters. */
27
+ maxCharacters?: number;
28
+ }
29
+ interface ExaSearchOptions extends CallOptions {
30
+ /** Results to return; Exa allows 1 to 100, fewer for some types. */
10
31
  limit?: number;
11
- type?: "auto" | "lite" | "deep-lite" | "deep";
12
- category?: "company" | "people" | "research paper" | "news" | "pdf" | "github" | "personal site" | "financial report";
32
+ /**
33
+ * `lite`, `auto`, `deep-lite` and `deep` are current. `instant`, `fast` and
34
+ * `deep-reasoning` are legacy: Exa still accepts them and names `lite` (for
35
+ * the first two) and `deep` as their replacements. `lite` accepts only
36
+ * `limit`, `category`, `includeDomains`, `excludeDomains`, `publishedAfter`,
37
+ * `publishedBefore`, `country`, `moderation`, `content` and `highlights`.
38
+ */
39
+ type?: "auto" | "lite" | "deep-lite" | "deep" | "instant" | "fast" | "deep-reasoning";
40
+ /**
41
+ * `company` and `people` refuse `publishedAfter` and `publishedBefore`, and
42
+ * `people` also refuses `excludeDomains`.
43
+ */
44
+ category?: "company" | "publication" | "news" | "personal site" | "financial report" | "people";
45
+ /** Hostnames, hostname plus path prefix, or `*.` wildcards; up to 1,200. */
13
46
  includeDomains?: string[];
14
47
  excludeDomains?: string[];
15
- /** YYYY-MM-DD. */
48
+ /** YYYY-MM-DD, from the start of that day (UTC). */
16
49
  publishedAfter?: string;
17
- /** YYYY-MM-DD. */
50
+ /** YYYY-MM-DD, to the end of that day (UTC). */
18
51
  publishedBefore?: string;
19
- /** YYYY-MM-DD: only pages Exa crawled after this date. */
20
- crawledAfter?: string;
21
- crawledBefore?: string;
22
- includeText?: string[];
23
- excludeText?: string[];
24
- /** Two-letter country code. */
52
+ /** Two-letter country code that localizes results. */
25
53
  country?: string;
54
+ /** Filter unsafe content from the results. */
55
+ moderation?: boolean;
26
56
  /** Include each result's page text. */
27
57
  content?: boolean;
58
+ /**
59
+ * Passages from each page, returned as `snippet`. On by default; pass
60
+ * `false` to skip them, or options to steer them. Exa bills highlights per
61
+ * page.
62
+ */
63
+ highlights?: boolean | ExaHighlightOptions;
64
+ /**
65
+ * A generated summary of each page, kept in `raw` (the normalized result has
66
+ * no summary field). Not available on `lite`.
67
+ */
68
+ summary?: boolean | {
69
+ query?: string;
70
+ };
71
+ /** Seconds a cached copy of a page may be old; 0 fetches fresh. Not available on `lite`. */
72
+ maxAge?: number;
73
+ /** Extra query variations. Only the deep types accept them. */
28
74
  additionalQueries?: string[];
75
+ /**
76
+ * Ask Exa for a generated answer from the results, returned as `answer`
77
+ * (an object schema is returned as JSON text; the object itself and its
78
+ * grounding stay in `raw.output`). Not available on `lite`.
79
+ */
80
+ outputSchema?: ExaOutputSchema;
81
+ /** Guides the generated answer. */
82
+ systemPrompt?: string;
29
83
  }
30
- export interface ExaReadOptions extends CallOptions {
84
+ interface ExaReadOptions extends CallOptions {
31
85
  /** Return passages that answer this query as `excerpts`. */
32
86
  query?: string;
87
+ /** Limit the page text, in characters. */
33
88
  maxCharacters?: number;
34
- /** 0 forces a live fetch, -1 reads only the cache. */
35
- maxAgeHours?: number;
36
- /** Read Exa's stored copy of the page as of this ISO date. */
89
+ /** Seconds a cached copy may be old; 0 fetches fresh, a negative value reads only the cache. */
90
+ maxAge?: number;
91
+ /** Read Exa's stored copy of the page as of this ISO date or date-time. */
37
92
  snapshotAsOf?: string;
93
+ /** Add a generated summary of the page as `summary`. */
94
+ summary?: boolean | {
95
+ query?: string;
96
+ };
97
+ /** Links to return per page, 0 to 1,000. Defaults to 100; 0 returns none. */
98
+ linkLimit?: number;
99
+ /** Image URLs to return per page, 0 to 1,000. Defaults to 100; 0 returns none. */
100
+ imageLimit?: number;
38
101
  }
39
- export interface ExaExtractOptions extends CallOptions {
102
+ type ExaReadManyOptions = ExaReadOptions;
103
+ interface ExaExtractOptions extends CallOptions {
40
104
  schema: JsonSchema;
41
105
  /** What to extract, in plain words. */
42
106
  prompt?: string;
43
- maxAgeHours?: number;
107
+ /** Seconds a cached copy may be old; 0 fetches fresh. */
108
+ maxAge?: number;
44
109
  }
45
- export interface ExaResearchOptions extends CallOptions {
110
+ interface ExaAnswerOptions extends CallOptions {
111
+ /** JSON Schema (draft 7) for the answer; the answer comes back as an object. */
46
112
  schema?: JsonSchema;
113
+ systemPrompt?: string;
114
+ /** Two-letter country code that localizes the search. */
115
+ country?: string;
116
+ model?: "exa" | "exa-pro" | "exa-research" | "exa-fast";
117
+ }
118
+ interface ExaResearchOptions extends CallOptions {
119
+ schema?: JsonSchema;
120
+ /** Cost and reasoning preference. Defaults to `auto`. */
47
121
  effort?: "minimal" | "low" | "medium" | "high" | "xhigh" | "auto" | "ultra";
48
- /** Spend cap in dollars, for auto and ultra effort. */
122
+ /** Spend cap in dollars, 1 to 100. Only `auto` and `ultra` accept it. */
49
123
  maxCostDollars?: number;
124
+ /** Soft time limit in seconds, 300 to 10,800. Only `ultra` accepts it. */
50
125
  maxDurationSeconds?: number;
126
+ systemPrompt?: string;
127
+ /** Records for the run to enrich, and records it must not return. */
128
+ input?: {
129
+ data?: Record<string, unknown>[];
130
+ exclusion?: Record<string, unknown>[];
131
+ };
132
+ /** The `continuationId` of an earlier completed run, which this run builds on. */
133
+ continueFrom?: string;
51
134
  /** Milliseconds between status checks. */
52
135
  interval?: number;
53
136
  /**
@@ -56,10 +139,53 @@ export interface ExaResearchOptions extends CallOptions {
56
139
  */
57
140
  resume?: string;
58
141
  }
59
- export interface ExaOperations {
142
+ type ExaWebhookEvent = "monitor.created" | "monitor.updated" | "monitor.deleted" | "monitor.run.created" | "monitor.run.completed";
143
+ interface ExaMonitorCreateOptions extends CallOptions {
144
+ /** What to search for on every run, in plain words. */
145
+ query: string;
146
+ /** Exa calls this over HTTPS with each event, signed with the monitor's `webhookSecret`. */
147
+ webhookUrl: string;
148
+ /**
149
+ * How often the monitor runs: whole hours or days, at least one hour. Exa
150
+ * has no cron. Leave it out for a monitor that runs only when triggered.
151
+ */
152
+ schedule?: Extract<MonitorSchedule, {
153
+ every: unknown;
154
+ }>;
155
+ name?: string;
156
+ /** Results per run, 1 to 100. */
157
+ limit?: number;
158
+ includeDomains?: string[];
159
+ excludeDomains?: string[];
160
+ /** Include each result's page text. */
161
+ content?: boolean;
162
+ /** A generated report of each run; same limits as on `search`. */
163
+ outputSchema?: ExaOutputSchema;
164
+ /** Echoed back in every webhook delivery. */
165
+ metadata?: Record<string, string>;
166
+ /** Defaults to what Exa chooses. */
167
+ webhookEvents?: ExaWebhookEvent[];
168
+ }
169
+ interface ExaMonitorEventsOptions extends CallOptions {
170
+ cursor?: string;
171
+ /** Runs per page, 1 to 100. */
172
+ limit?: number;
173
+ }
174
+ type ExaMonitor = {
175
+ create(options: ExaMonitorCreateOptions): Promise<MonitorInfo>;
176
+ get(id: string, options?: CallOptions): Promise<MonitorInfo>;
177
+ list(options?: CallOptions): Promise<MonitorInfo[]>;
178
+ delete(id: string, options?: CallOptions): Promise<void>;
179
+ events(id: string, options?: ExaMonitorEventsOptions): Promise<MonitorEvents>;
180
+ };
181
+ interface ExaOperations {
60
182
  search(query: string, options?: ExaSearchOptions): Promise<SearchResponse>;
61
183
  read(url: string, options?: ExaReadOptions): Promise<Page>;
184
+ readMany(urls: string[], options?: ExaReadManyOptions): Promise<PageBatch>;
62
185
  extract<T = unknown>(url: string, options: ExaExtractOptions): Promise<Extraction<T>>;
186
+ answer<T = unknown>(question: string, options?: ExaAnswerOptions): Promise<Answer<T>>;
63
187
  research<T = unknown>(question: string, options?: ExaResearchOptions): Promise<Research<T>>;
188
+ monitor: ExaMonitor;
64
189
  }
65
- export declare function exa(config?: ExaConfig): Adapter<"exa", ExaOperations, RawClient>;
190
+ export declare const exa: (config?: ExaConfig) => Adapter<"exa", ExaOperations, RawClient>;
191
+ export type { ExaAnswerOptions, ExaConfig, ExaExtractOptions, ExaHighlightOptions, ExaMonitor, ExaMonitorCreateOptions, ExaMonitorEventsOptions, ExaOperations, ExaOutputSchema, ExaReadManyOptions, ExaReadOptions, ExaResearchOptions, ExaSearchOptions, ExaWebhookEvent };