@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.
- package/README.md +300 -120
- package/dist/index.d.mts +32 -22
- package/dist/index.d.ts +32 -22
- package/dist/index.js +138 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -64
- package/dist/index.mjs.map +1 -1
- package/dist/mock/index.d.mts +20 -7
- package/dist/mock/index.d.ts +20 -7
- package/dist/mock/index.js +40 -15
- package/dist/mock/index.js.map +1 -1
- package/dist/mock/index.mjs +40 -15
- package/dist/mock/index.mjs.map +1 -1
- package/dist/{types-Ddu_K1Nn.d.mts → types-BOfLGSkb.d.mts} +44 -31
- package/dist/{types-Ddu_K1Nn.d.ts → types-BOfLGSkb.d.ts} +44 -31
- package/package.json +2 -2
|
@@ -3,23 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Type definitions for the FetchBrain AI-powered scraping optimization SDK.
|
|
5
5
|
*/
|
|
6
|
-
/**
|
|
7
|
-
type
|
|
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
|
-
/**
|
|
22
|
-
|
|
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
|
-
*
|
|
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,
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
|
-
/**
|
|
79
|
-
interface
|
|
74
|
+
/** Recall request to the API */
|
|
75
|
+
interface RecallRequest {
|
|
80
76
|
items: {
|
|
81
77
|
ref: string;
|
|
82
78
|
request: RawRequest;
|
|
83
79
|
}[];
|
|
84
|
-
|
|
80
|
+
memory: MemoryDepth;
|
|
85
81
|
build?: string;
|
|
86
82
|
}
|
|
87
|
-
/** Single
|
|
88
|
-
interface
|
|
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
|
-
/**
|
|
94
|
-
interface
|
|
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
|
-
|
|
119
|
-
|
|
113
|
+
known: number;
|
|
114
|
+
recallRate: number;
|
|
120
115
|
learned: number;
|
|
121
116
|
period: string;
|
|
122
117
|
}
|
|
123
|
-
/** Result from AI knowledge
|
|
124
|
-
interface
|
|
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 {
|
|
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.
|
|
4
|
-
"description": "FetchBrain SDK —
|
|
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",
|