@fetchbrain.com/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.
@@ -3,23 +3,16 @@
3
3
  *
4
4
  * Type definitions for the FetchBrain AI-powered scraping optimization SDK.
5
5
  */
6
- /** Intelligence level for AI inference accuracy */
7
- type IntelligenceLevel = "realtime" | "high" | "standard" | "deep";
8
- /** AI memory depth levels - deeper memory may have minor hallucinations */
9
- declare enum AIMemoryDepth {
10
- REALTIME = 1,
11
- HIGH = 2,
12
- STANDARD = 3,
13
- DEEP = 4
14
- }
6
+ /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
7
+ type MemoryDepth = "fresh" | "recent" | "standard" | "deep";
15
8
  /** Configuration for FetchBrain SDK */
16
9
  interface FetchBrainConfig {
17
10
  /** API key for authentication */
18
11
  apiKey: string;
19
12
  /** Base URL for API (defaults to production) */
20
13
  baseUrl?: string;
21
- /** Intelligence level for AI responses */
22
- intelligence?: IntelligenceLevel;
14
+ /** How far back the brain recalls: fresh=1h, recent=24h, standard=7d, deep=30d */
15
+ memory?: MemoryDepth;
23
16
  /** Whether AI should learn from new pages */
24
17
  learning?: boolean;
25
18
  /**
@@ -29,15 +22,18 @@ interface FetchBrainConfig {
29
22
  * - string[]: Only run handlers with these labels (e.g., ['listing', 'category'])
30
23
  * - 'default': Only run the default handler
31
24
  *
32
- * AI data always available via context.ai
25
+ * Recalled data always available via context.brain
33
26
  */
34
27
  alwaysRun?: boolean | string | string[];
35
28
  /** Custom data extractor for learning */
36
29
  extractForLearning?: (data: unknown) => Record<string, unknown>;
37
30
  /**
38
- * If true, only return recognized data from the same build version.
39
- * When a scraper updates, it will re-scrape instead of using stale data.
40
- * Uses APIFY_ACTOR_BUILD_ID environment variable.
31
+ * If true, scope both learn and recall to the current build version.
32
+ * Recall only returns known data from the same build; learn stores new
33
+ * data tagged with it. When a scraper updates, it will re-scrape instead
34
+ * of using stale data, and freshly learned data won't be masked by an
35
+ * older build's memory.
36
+ * Uses the platform's native build identifier, auto-detected from the environment.
41
37
  * Default: false
42
38
  */
43
39
  refreshOnRebuild?: boolean;
@@ -75,27 +71,25 @@ interface RawRequest {
75
71
  userData?: Record<string, unknown>;
76
72
  label?: string;
77
73
  }
78
- /** Query request to the API */
79
- interface QueryRequest {
74
+ /** Recall request to the API */
75
+ interface RecallRequest {
80
76
  items: {
81
77
  ref: string;
82
78
  request: RawRequest;
83
79
  }[];
84
- intelligence: IntelligenceLevel;
80
+ memory: MemoryDepth;
85
81
  build?: string;
86
82
  }
87
- /** Single query result (matched by ref) */
88
- interface QueryResultItem {
83
+ /** Single recall result (matched by ref) */
84
+ interface RecallResultItem {
89
85
  ref: string;
90
86
  data?: Record<string, unknown>;
91
- confidence?: number;
92
87
  }
93
- /** Query response from the API */
94
- interface QueryResponse {
88
+ /** Recall response from the API */
89
+ interface RecallResponse {
95
90
  known: {
96
91
  ref: string;
97
92
  data: Record<string, unknown>;
98
- confidence: number;
99
93
  }[];
100
94
  unknown: string[];
101
95
  }
@@ -105,6 +99,7 @@ interface LearnRequest {
105
99
  request: RawRequest;
106
100
  data: Record<string, unknown>;
107
101
  }[];
102
+ build?: string;
108
103
  }
109
104
  /** Learn response from the API */
110
105
  interface LearnResponse {
@@ -115,18 +110,36 @@ interface LearnResponse {
115
110
  /** Stats response from the API */
116
111
  interface StatsResponse {
117
112
  queries: number;
118
- recognized: number;
119
- recognitionRate: number;
113
+ known: number;
114
+ recallRate: number;
120
115
  learned: number;
121
116
  period: string;
122
117
  }
123
- /** Result from AI knowledge query */
124
- interface AIResult {
118
+ /** Result from AI knowledge recall */
119
+ interface RecallResult {
125
120
  known: boolean;
126
121
  data?: Record<string, unknown>;
127
- confidence?: number;
128
122
  fallback?: boolean;
129
123
  }
124
+ /** Response from a natural-language ask against learned knowledge */
125
+ interface AskResponse {
126
+ sources: {
127
+ score: number;
128
+ url?: string;
129
+ data: unknown;
130
+ }[];
131
+ answer?: string;
132
+ /**
133
+ * "ok" — answered; "rejected" — the API refused this request (bad input,
134
+ * unknown model slug, byok not linked — see `error`); "unavailable" — the
135
+ * API is degraded or unreachable.
136
+ */
137
+ status: "ok" | "unavailable" | "rejected";
138
+ /** Why the request was rejected (only when status is "rejected"). */
139
+ error?: string;
140
+ /** Slug of the generation model actually used (answer mode; reveals fallbacks). */
141
+ model?: string;
142
+ }
130
143
  /** Circuit breaker states */
131
144
  type CircuitState = "closed" | "open" | "half-open";
132
145
  /** Circuit breaker configuration */
@@ -158,7 +171,7 @@ interface Logger {
158
171
  * Telemetry configuration - opt-in data sharing for AI improvements
159
172
  */
160
173
  interface TelemetryConfig {
161
- /** Enable telemetry collection (default: false) */
174
+ /** Enable telemetry collection (default: false — opt in to join the access-intelligence network) */
162
175
  enabled: boolean;
163
176
  /** Share performance metrics: response times, retries, status codes */
164
177
  sharePerformance?: boolean;
@@ -206,4 +219,4 @@ interface TelemetryResponse {
206
219
  status: "success" | "partial" | "error";
207
220
  }
208
221
 
209
- export { type AIResult as A, type BatchConfig as B, type CircuitState as C, type FetchBrainConfig as F, type IntelligenceLevel as I, type LearnResponse as L, type QueryRequest as Q, type RawRequest as R, type StatsResponse as S, type TelemetryData as T, type TelemetryConfig as a, type CircuitBreakerConfig as b, type Logger as c, type LogLevel as d, type QueryResponse as e, type QueryResultItem as f, type LearnRequest as g, type TelemetryRequest as h, type TelemetryResponse as i, AIMemoryDepth as j };
222
+ 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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fetchbrain.com/sdk",
3
- "version": "0.2.0",
4
- "description": "FetchBrain SDK — give your Crawlee scraper an AI that already knows the web; ask before you fetch, teach what you learn.",
3
+ "version": "0.3.1",
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",
7
7
  "types": "./dist/index.d.ts",