@fetchbrain.com/sdk 0.7.1 → 0.8.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-B579TMo9.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-B579TMo9.js';
2
2
 
3
3
  /**
4
4
  * Mock FetchBrain for unit testing
@@ -5,6 +5,52 @@
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
+ labels?: Record<string, RunLabelCounts>;
46
+ }
47
+ /** Change counts accumulated by a client, once per learn HTTP batch. */
48
+ interface ChangeStats {
49
+ changed: number;
50
+ unchanged: number;
51
+ firstSeen: number;
52
+ drift: DriftItem[];
53
+ }
8
54
  /** Configuration for FetchBrain SDK */
9
55
  interface FetchBrainConfig {
10
56
  /** API key for authentication */
@@ -18,6 +64,20 @@ interface FetchBrainConfig {
18
64
  * warning. On Apify a name overrides the actor id.
19
65
  */
20
66
  scraper?: string;
67
+ /**
68
+ * Change detection: relearn known pages your `alwaysRun` handlers re-scrape so
69
+ * FetchBrain can tell what changed since last time. Off by default. Relearning
70
+ * counts toward your learn usage.
71
+ */
72
+ changeDetection?: ChangeDetectionConfig;
73
+ /**
74
+ * Send a small end-of-run report so FetchBrain can flag runs where many pages
75
+ * came back empty or failed. It contains exactly: the run id, start and end
76
+ * timestamps, scraped/learned/recalled counts, per-label page counts
77
+ * (scraped/empty/failed), and the build id only with `refreshOnRebuild`.
78
+ * No URLs or data. Default: true. Set false to disable. Separate from telemetry.
79
+ */
80
+ reportRuns?: boolean;
21
81
  /** Base URL for API (defaults to production) */
22
82
  baseUrl?: string;
23
83
  /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
@@ -165,12 +225,18 @@ interface LearnRequest {
165
225
  data: LearnedData;
166
226
  }[];
167
227
  build?: string;
228
+ ignore?: string[];
168
229
  }
169
230
  /** Learn response from the API */
170
231
  interface LearnResponse {
171
232
  learned: number;
172
233
  status: "success" | "partial" | "rejected";
173
234
  errors?: string[];
235
+ changed?: number;
236
+ unchanged?: number;
237
+ firstSeen?: number;
238
+ changedByLabel?: Record<string, number>;
239
+ drift?: DriftItem[];
174
240
  }
175
241
  /** Stats response from the API */
176
242
  interface StatsResponse {
@@ -286,4 +352,4 @@ interface TelemetryResponse {
286
352
  status: "success" | "partial" | "error";
287
353
  }
288
354
 
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 };
355
+ 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,52 @@
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
+ labels?: Record<string, RunLabelCounts>;
46
+ }
47
+ /** Change counts accumulated by a client, once per learn HTTP batch. */
48
+ interface ChangeStats {
49
+ changed: number;
50
+ unchanged: number;
51
+ firstSeen: number;
52
+ drift: DriftItem[];
53
+ }
8
54
  /** Configuration for FetchBrain SDK */
9
55
  interface FetchBrainConfig {
10
56
  /** API key for authentication */
@@ -18,6 +64,20 @@ interface FetchBrainConfig {
18
64
  * warning. On Apify a name overrides the actor id.
19
65
  */
20
66
  scraper?: string;
67
+ /**
68
+ * Change detection: relearn known pages your `alwaysRun` handlers re-scrape so
69
+ * FetchBrain can tell what changed since last time. Off by default. Relearning
70
+ * counts toward your learn usage.
71
+ */
72
+ changeDetection?: ChangeDetectionConfig;
73
+ /**
74
+ * Send a small end-of-run report so FetchBrain can flag runs where many pages
75
+ * came back empty or failed. It contains exactly: the run id, start and end
76
+ * timestamps, scraped/learned/recalled counts, per-label page counts
77
+ * (scraped/empty/failed), and the build id only with `refreshOnRebuild`.
78
+ * No URLs or data. Default: true. Set false to disable. Separate from telemetry.
79
+ */
80
+ reportRuns?: boolean;
21
81
  /** Base URL for API (defaults to production) */
22
82
  baseUrl?: string;
23
83
  /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
@@ -165,12 +225,18 @@ interface LearnRequest {
165
225
  data: LearnedData;
166
226
  }[];
167
227
  build?: string;
228
+ ignore?: string[];
168
229
  }
169
230
  /** Learn response from the API */
170
231
  interface LearnResponse {
171
232
  learned: number;
172
233
  status: "success" | "partial" | "rejected";
173
234
  errors?: string[];
235
+ changed?: number;
236
+ unchanged?: number;
237
+ firstSeen?: number;
238
+ changedByLabel?: Record<string, number>;
239
+ drift?: DriftItem[];
174
240
  }
175
241
  /** Stats response from the API */
176
242
  interface StatsResponse {
@@ -286,4 +352,4 @@ interface TelemetryResponse {
286
352
  status: "success" | "partial" | "error";
287
353
  }
288
354
 
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 };
355
+ 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.8.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",