@fetchbrain.com/sdk 0.4.0 → 0.5.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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * FetchBrain SDK Types
3
3
  *
4
- * Type definitions for the FetchBrain AI-powered scraping optimization SDK.
4
+ * Type definitions for the FetchBrain SDK — memory for your scrapers.
5
5
  */
6
6
  /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
7
7
  type MemoryDepth = "fresh" | "recent" | "standard" | "deep";
@@ -13,11 +13,11 @@ interface FetchBrainConfig {
13
13
  baseUrl?: string;
14
14
  /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
15
15
  memory?: MemoryDepth;
16
- /** Whether AI should learn from new pages */
16
+ /** Teach the brain from scraped data (default: true) */
17
17
  learning?: boolean;
18
18
  /**
19
- * Control which handlers run when AI knows the page.
20
- * - false: Auto-skip all handlers when AI knows (default)
19
+ * Control which handlers run when the brain knows the request.
20
+ * - false: Auto-skip all handlers when the request is known (default)
21
21
  * - true: Always run all handlers
22
22
  * - string[]: Only run handlers with these labels (e.g., ['listing', 'category'])
23
23
  * - 'default': Only run the default handler
@@ -35,7 +35,40 @@ interface FetchBrainConfig {
35
35
  * excluded from telemetry.
36
36
  */
37
37
  skipLabels?: string[];
38
- /** Custom data extractor for learning */
38
+ /**
39
+ * Recall requests in bulk as they are enqueued (default: true).
40
+ *
41
+ * In HttpCrawler/CheerioCrawler the HTTP fetch happens BEFORE the request handler runs,
42
+ * so a recall inside the handler is too late to save the fetch. With preRecall the SDK
43
+ * wraps `crawler.addRequests()` (which `run(requests)` also goes through), recalls the
44
+ * whole batch in one API call, marks known requests with `skipNavigation` so Crawlee
45
+ * never fetches them, and stashes the result so the handler does no second recall.
46
+ *
47
+ * Scope: applies to ARRAY input passed to `crawler.addRequests()` / `run(requests)`.
48
+ * Crawlee's context-level `enqueueLinks()` and context `addRequests()` reach the queue
49
+ * via other paths and are not pre-recalled (they still get handler-time recall) — in a
50
+ * handler, enqueue follow-ups with `context.crawler.addRequests([...])` instead.
51
+ * Note known recalls are counted at enqueue time, so known requests the queue later
52
+ * dedups still count as recalls. The recall result is a snapshot as of enqueue: data learned
53
+ * between enqueue and execution is not picked up (the request is simply scraped and
54
+ * re-learned). If a request skipped its fetch but its remembered data expired before
55
+ * execution (e.g. across a process restart), it fails once without retries and lands
56
+ * in your `failedRequestHandler`; it will be re-scraped on a future run. A transient
57
+ * API outage during that restore is retried normally instead.
58
+ * On crawlers with `retryOnBlocked` the fetch is never skipped (Crawlee's blocked-check
59
+ * needs a response); recalled data still replaces the handler.
60
+ * Set to false to restore handler-time recall only.
61
+ */
62
+ preRecall?: boolean;
63
+ /**
64
+ * Called whenever recalled data is delivered in place of a live scrape — the handler
65
+ * was auto-skipped and the remembered data pushed, or your handler called
66
+ * `context.brain.use()`. Use it for per-record bookkeeping that normally lives in your
67
+ * handler — e.g. metrics or counters. Errors are swallowed: a hook failure never
68
+ * breaks the crawl.
69
+ */
70
+ onRecalled?: (event: RecalledEvent) => void | Promise<void>;
71
+ /** Transform each pushed record before the brain learns it */
39
72
  extractForLearning?: (data: unknown) => Record<string, unknown>;
40
73
  /**
41
74
  * If true, scope both learn and recall to the current build version.
@@ -52,8 +85,8 @@ interface FetchBrainConfig {
52
85
  /** Enable debug logging */
53
86
  debug?: boolean;
54
87
  /**
55
- * Field name to use as URL for learning
56
- * Useful when request URL is an API endpoint but data contains the actual page URL
88
+ * Field name to use as URL for learning.
89
+ * Note: accepted and stored, but not currently applied by the SDK.
57
90
  */
58
91
  learnUrlField?: string;
59
92
  /**
@@ -65,12 +98,19 @@ interface FetchBrainConfig {
65
98
  */
66
99
  circuitBreaker?: Partial<CircuitBreakerConfig>;
67
100
  /**
68
- * Telemetry configuration - opt-in anonymous data sharing
69
- * Helps improve proxy recommendations, detect blocks, optimize configs
70
- * Default: disabled
101
+ * Telemetry configuration — opt-in, pseudonymous (sent with your API key).
102
+ * Helps improve proxy recommendations, detect blocks, optimize configs.
103
+ * Default: disabled. See the README "Telemetry (opt-in)" section for every field sent.
71
104
  */
72
105
  telemetry?: TelemetryConfig;
73
106
  }
107
+ /** Info passed to `onRecalled` when remembered data is delivered in place of a live scrape */
108
+ interface RecalledEvent {
109
+ url: string;
110
+ label?: string;
111
+ userData?: Record<string, unknown>;
112
+ data: Record<string, unknown>;
113
+ }
74
114
  /** The raw request the SDK forwards; the API derives identity from a subset. */
75
115
  interface RawRequest {
76
116
  url: string;
@@ -125,13 +165,13 @@ interface StatsResponse {
125
165
  learned: number;
126
166
  period: string;
127
167
  }
128
- /** Result from AI knowledge recall */
168
+ /** Result of a recall */
129
169
  interface RecallResult {
130
170
  known: boolean;
131
171
  data?: Record<string, unknown>;
132
172
  fallback?: boolean;
133
173
  }
134
- /** Response from a natural-language ask against learned knowledge */
174
+ /** Response from a natural-language ask, answered from everything the account has learned */
135
175
  interface AskResponse {
136
176
  sources: {
137
177
  score: number;
@@ -178,21 +218,23 @@ interface Logger {
178
218
  error: (message: string, ...args: unknown[]) => void;
179
219
  }
180
220
  /**
181
- * Telemetry configuration - opt-in data sharing for AI improvements
221
+ * Telemetry configuration — opt-in, pseudonymous diagnostics sent with your API key.
222
+ * When enabled, each sub-flag defaults to true.
182
223
  */
183
224
  interface TelemetryConfig {
184
- /** Enable telemetry collection (default: false — opt in to join the access-intelligence network) */
225
+ /** Enable telemetry collection (default: false — opt-in) */
185
226
  enabled: boolean;
186
- /** Share performance metrics: response times, retries, status codes */
227
+ /** Share performance metrics: timings, retries, status codes, content size (default: true) */
187
228
  sharePerformance?: boolean;
188
- /** Share proxy info: country, type (never IP addresses) */
229
+ /** Share proxy info: country, locally-derived type, success (never proxy URL/IP) (default: true) */
189
230
  shareProxyInfo?: boolean;
190
- /** Share site patterns: block rates, rate limits detected */
231
+ /** Share block indicators derived from status codes and error categories (default: true) */
191
232
  shareSitePatterns?: boolean;
192
233
  }
193
234
  /**
194
- * Telemetry data collected from Crawlee context
195
- * All data is sanitized - no PII, no credentials, no raw content
235
+ * Telemetry data collected from Crawlee context.
236
+ * No raw URLs, bodies, proxy URLs/IPs or error messages. The hostname, generalized
237
+ * path and request label are sent as-is, linked to your API key.
196
238
  */
197
239
  interface TelemetryData {
198
240
  domain: string;
@@ -229,4 +271,4 @@ interface TelemetryResponse {
229
271
  status: "success" | "partial" | "error";
230
272
  }
231
273
 
232
- export type { AskResponse as A, BatchConfig as B, CircuitState as C, FetchBrainConfig as F, LearnResponse as L, MemoryDepth as M, RawRequest as R, StatsResponse as S, TelemetryData as T, RecallResult as a, TelemetryConfig as b, CircuitBreakerConfig as c, Logger as d, LogLevel as e, RecallRequest as f, RecallResponse as g, RecallResultItem as h, LearnRequest as i, TelemetryRequest as j, TelemetryResponse as k };
274
+ export type { AskResponse as A, BatchConfig as B, CircuitState as C, FetchBrainConfig as F, LearnResponse as L, MemoryDepth as M, RawRequest as R, StatsResponse as S, TelemetryData as T, RecallResult as a, TelemetryConfig as b, CircuitBreakerConfig as c, Logger as d, LogLevel as e, RecallRequest as f, RecallResponse as g, RecallResultItem as h, LearnRequest as i, RecalledEvent as j, TelemetryRequest as k, TelemetryResponse as l };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fetchbrain.com/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "FetchBrain SDK — make your Crawlee scrapers smarter with every run; recall before you fetch, teach what you learn.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -36,8 +36,6 @@
36
36
  "scraping",
37
37
  "web-scraping",
38
38
  "crawlee",
39
- "crawlee",
40
- "apify",
41
39
  "optimization",
42
40
  "ai",
43
41
  "fetchbrain"