@fetchbrain.com/sdk 0.7.1 → 0.9.0

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,4 +1,4 @@
1
- import { R as RawRequest, a as RecallResult, b as LearnResponse, S as StatsResponse, A as AskResponse, F as FetchBrainConfig } from '../types-CSG4BekA.mjs';
1
+ import { R as RawRequest, a as RecallResult, b as LearnResponse, S as StatsResponse, A as AskResponse, F as FetchBrainConfig } from '../types-CPyPUGeb.mjs';
2
2
 
3
3
  /**
4
4
  * Mock FetchBrain for unit testing
@@ -1,4 +1,4 @@
1
- import { R as RawRequest, a as RecallResult, b as LearnResponse, S as StatsResponse, A as AskResponse, F as FetchBrainConfig } from '../types-CSG4BekA.js';
1
+ import { R as RawRequest, a as RecallResult, b as LearnResponse, S as StatsResponse, A as AskResponse, F as FetchBrainConfig } from '../types-CPyPUGeb.js';
2
2
 
3
3
  /**
4
4
  * Mock FetchBrain for unit testing
@@ -5,6 +5,58 @@
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";
8
+ /** Options for change detection. */
9
+ interface ChangeDetectionConfig {
10
+ /** Relearn known `alwaysRun` pages and report what changed (default: false). */
11
+ enabled?: boolean;
12
+ /** Field names to ignore when comparing versions (e.g. "scrapedAt"). */
13
+ ignoreFields?: string[];
14
+ }
15
+ /** A scraper-drift finding: a field whose fill rate or type shifted. */
16
+ interface DriftItem {
17
+ label: string;
18
+ field: string;
19
+ kind: "fill_drop" | "missing" | "type_changed";
20
+ /** Fill rate 0..1 (or a type name for type_changed). */
21
+ from: number | string;
22
+ to: number | string;
23
+ }
24
+ /** A run-level flag returned by the run report. */
25
+ interface RunFlag {
26
+ label: string;
27
+ kind: "empty_pages" | "failed_pages";
28
+ rate: number;
29
+ }
30
+ /** Per-label page counts in a run report. */
31
+ interface RunLabelCounts {
32
+ scraped: number;
33
+ empty: number;
34
+ failed: number;
35
+ }
36
+ /** End-of-run report body (counts and labels only). */
37
+ interface RunReport {
38
+ runId: string;
39
+ build?: string;
40
+ startedAt?: string;
41
+ endedAt?: string;
42
+ scraped: number;
43
+ learned: number;
44
+ recalled: number;
45
+ /** Recalled pages whose fetch was skipped (pre-recalled at enqueue). Per run() call. */
46
+ requestsSkipped?: number;
47
+ /** Recalled pages that were fetched first (recall happened in the handler). Per run() call. */
48
+ lateRecalls?: number;
49
+ /** Pages handled outside FetchBrain (`skipLabels`). Per run() call. */
50
+ bypassed?: number;
51
+ labels?: Record<string, RunLabelCounts>;
52
+ }
53
+ /** Change counts accumulated by a client, once per learn HTTP batch. */
54
+ interface ChangeStats {
55
+ changed: number;
56
+ unchanged: number;
57
+ firstSeen: number;
58
+ drift: DriftItem[];
59
+ }
8
60
  /** Configuration for FetchBrain SDK */
9
61
  interface FetchBrainConfig {
10
62
  /** API key for authentication */
@@ -18,6 +70,20 @@ interface FetchBrainConfig {
18
70
  * warning. On Apify a name overrides the actor id.
19
71
  */
20
72
  scraper?: string;
73
+ /**
74
+ * Change detection: relearn known pages your `alwaysRun` handlers re-scrape so
75
+ * FetchBrain can tell what changed since last time. Off by default. Relearning
76
+ * counts toward your learn usage.
77
+ */
78
+ changeDetection?: ChangeDetectionConfig;
79
+ /**
80
+ * Send a small end-of-run report so FetchBrain can flag runs where many pages
81
+ * came back empty or failed. It contains exactly: the run id, start and end
82
+ * timestamps, scraped/learned/recalled counts, per-label page counts
83
+ * (scraped/empty/failed), and the build id only with `refreshOnRebuild`.
84
+ * No URLs or data. Default: true. Set false to disable. Separate from telemetry.
85
+ */
86
+ reportRuns?: boolean;
21
87
  /** Base URL for API (defaults to production) */
22
88
  baseUrl?: string;
23
89
  /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
@@ -165,12 +231,18 @@ interface LearnRequest {
165
231
  data: LearnedData;
166
232
  }[];
167
233
  build?: string;
234
+ ignore?: string[];
168
235
  }
169
236
  /** Learn response from the API */
170
237
  interface LearnResponse {
171
238
  learned: number;
172
239
  status: "success" | "partial" | "rejected";
173
240
  errors?: string[];
241
+ changed?: number;
242
+ unchanged?: number;
243
+ firstSeen?: number;
244
+ changedByLabel?: Record<string, number>;
245
+ drift?: DriftItem[];
174
246
  }
175
247
  /** Stats response from the API */
176
248
  interface StatsResponse {
@@ -286,4 +358,4 @@ interface TelemetryResponse {
286
358
  status: "success" | "partial" | "error";
287
359
  }
288
360
 
289
- export type { AskResponse as A, BatchConfig as B, CircuitState as C, FetchBrainConfig as F, LearnedData as L, MemoryDepth as M, RawRequest as R, StatsResponse as S, TelemetryData as T, RecallResult as a, LearnResponse as b, TelemetryConfig as c, CircuitBreakerConfig as d, Logger as e, LogLevel as f, RecallRequest as g, RecallResponse as h, RecallResultItem as i, LearnRequest as j, RecalledEvent as k, TelemetryRequest as l, TelemetryResponse as m };
361
+ export type { AskResponse as A, BatchConfig as B, ChangeStats as C, DriftItem as D, FetchBrainConfig as F, LearnedData as L, MemoryDepth as M, RawRequest as R, StatsResponse as S, TelemetryData as T, RecallResult as a, LearnResponse as b, RunReport as c, RunFlag as d, CircuitState as e, TelemetryConfig as f, CircuitBreakerConfig as g, Logger as h, LogLevel as i, RecallRequest as j, RecallResponse as k, RecallResultItem as l, LearnRequest as m, RecalledEvent as n, ChangeDetectionConfig as o, TelemetryRequest as p, TelemetryResponse as q };
@@ -5,6 +5,58 @@
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";
8
+ /** Options for change detection. */
9
+ interface ChangeDetectionConfig {
10
+ /** Relearn known `alwaysRun` pages and report what changed (default: false). */
11
+ enabled?: boolean;
12
+ /** Field names to ignore when comparing versions (e.g. "scrapedAt"). */
13
+ ignoreFields?: string[];
14
+ }
15
+ /** A scraper-drift finding: a field whose fill rate or type shifted. */
16
+ interface DriftItem {
17
+ label: string;
18
+ field: string;
19
+ kind: "fill_drop" | "missing" | "type_changed";
20
+ /** Fill rate 0..1 (or a type name for type_changed). */
21
+ from: number | string;
22
+ to: number | string;
23
+ }
24
+ /** A run-level flag returned by the run report. */
25
+ interface RunFlag {
26
+ label: string;
27
+ kind: "empty_pages" | "failed_pages";
28
+ rate: number;
29
+ }
30
+ /** Per-label page counts in a run report. */
31
+ interface RunLabelCounts {
32
+ scraped: number;
33
+ empty: number;
34
+ failed: number;
35
+ }
36
+ /** End-of-run report body (counts and labels only). */
37
+ interface RunReport {
38
+ runId: string;
39
+ build?: string;
40
+ startedAt?: string;
41
+ endedAt?: string;
42
+ scraped: number;
43
+ learned: number;
44
+ recalled: number;
45
+ /** Recalled pages whose fetch was skipped (pre-recalled at enqueue). Per run() call. */
46
+ requestsSkipped?: number;
47
+ /** Recalled pages that were fetched first (recall happened in the handler). Per run() call. */
48
+ lateRecalls?: number;
49
+ /** Pages handled outside FetchBrain (`skipLabels`). Per run() call. */
50
+ bypassed?: number;
51
+ labels?: Record<string, RunLabelCounts>;
52
+ }
53
+ /** Change counts accumulated by a client, once per learn HTTP batch. */
54
+ interface ChangeStats {
55
+ changed: number;
56
+ unchanged: number;
57
+ firstSeen: number;
58
+ drift: DriftItem[];
59
+ }
8
60
  /** Configuration for FetchBrain SDK */
9
61
  interface FetchBrainConfig {
10
62
  /** API key for authentication */
@@ -18,6 +70,20 @@ interface FetchBrainConfig {
18
70
  * warning. On Apify a name overrides the actor id.
19
71
  */
20
72
  scraper?: string;
73
+ /**
74
+ * Change detection: relearn known pages your `alwaysRun` handlers re-scrape so
75
+ * FetchBrain can tell what changed since last time. Off by default. Relearning
76
+ * counts toward your learn usage.
77
+ */
78
+ changeDetection?: ChangeDetectionConfig;
79
+ /**
80
+ * Send a small end-of-run report so FetchBrain can flag runs where many pages
81
+ * came back empty or failed. It contains exactly: the run id, start and end
82
+ * timestamps, scraped/learned/recalled counts, per-label page counts
83
+ * (scraped/empty/failed), and the build id only with `refreshOnRebuild`.
84
+ * No URLs or data. Default: true. Set false to disable. Separate from telemetry.
85
+ */
86
+ reportRuns?: boolean;
21
87
  /** Base URL for API (defaults to production) */
22
88
  baseUrl?: string;
23
89
  /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
@@ -165,12 +231,18 @@ interface LearnRequest {
165
231
  data: LearnedData;
166
232
  }[];
167
233
  build?: string;
234
+ ignore?: string[];
168
235
  }
169
236
  /** Learn response from the API */
170
237
  interface LearnResponse {
171
238
  learned: number;
172
239
  status: "success" | "partial" | "rejected";
173
240
  errors?: string[];
241
+ changed?: number;
242
+ unchanged?: number;
243
+ firstSeen?: number;
244
+ changedByLabel?: Record<string, number>;
245
+ drift?: DriftItem[];
174
246
  }
175
247
  /** Stats response from the API */
176
248
  interface StatsResponse {
@@ -286,4 +358,4 @@ interface TelemetryResponse {
286
358
  status: "success" | "partial" | "error";
287
359
  }
288
360
 
289
- export type { AskResponse as A, BatchConfig as B, CircuitState as C, FetchBrainConfig as F, LearnedData as L, MemoryDepth as M, RawRequest as R, StatsResponse as S, TelemetryData as T, RecallResult as a, LearnResponse as b, TelemetryConfig as c, CircuitBreakerConfig as d, Logger as e, LogLevel as f, RecallRequest as g, RecallResponse as h, RecallResultItem as i, LearnRequest as j, RecalledEvent as k, TelemetryRequest as l, TelemetryResponse as m };
361
+ export type { AskResponse as A, BatchConfig as B, ChangeStats as C, DriftItem as D, FetchBrainConfig as F, LearnedData as L, MemoryDepth as M, RawRequest as R, StatsResponse as S, TelemetryData as T, RecallResult as a, LearnResponse as b, RunReport as c, RunFlag as d, CircuitState as e, TelemetryConfig as f, CircuitBreakerConfig as g, Logger as h, LogLevel as i, RecallRequest as j, RecallResponse as k, RecallResultItem as l, LearnRequest as m, RecalledEvent as n, ChangeDetectionConfig as o, TelemetryRequest as p, TelemetryResponse as q };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fetchbrain.com/sdk",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
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",