@fetchbrain.com/sdk 0.1.7 → 0.2.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.
- package/README.md +9 -5
- package/dist/index.d.mts +16 -209
- package/dist/index.d.ts +16 -209
- package/dist/index.js +89 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -87
- package/dist/index.mjs.map +1 -1
- package/dist/mock/index.d.mts +58 -0
- package/dist/mock/index.d.ts +58 -0
- package/dist/mock/index.js +148 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/mock/index.mjs +145 -0
- package/dist/mock/index.mjs.map +1 -0
- package/dist/types-Ddu_K1Nn.d.mts +209 -0
- package/dist/types-Ddu_K1Nn.d.ts +209 -0
- package/package.json +7 -2
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FetchBrain SDK Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the FetchBrain AI-powered scraping optimization SDK.
|
|
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
|
+
}
|
|
15
|
+
/** Configuration for FetchBrain SDK */
|
|
16
|
+
interface FetchBrainConfig {
|
|
17
|
+
/** API key for authentication */
|
|
18
|
+
apiKey: string;
|
|
19
|
+
/** Base URL for API (defaults to production) */
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
/** Intelligence level for AI responses */
|
|
22
|
+
intelligence?: IntelligenceLevel;
|
|
23
|
+
/** Whether AI should learn from new pages */
|
|
24
|
+
learning?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Control which handlers run when AI knows the page.
|
|
27
|
+
* - false: Auto-skip all handlers when AI knows (default)
|
|
28
|
+
* - true: Always run all handlers
|
|
29
|
+
* - string[]: Only run handlers with these labels (e.g., ['listing', 'category'])
|
|
30
|
+
* - 'default': Only run the default handler
|
|
31
|
+
*
|
|
32
|
+
* AI data always available via context.ai
|
|
33
|
+
*/
|
|
34
|
+
alwaysRun?: boolean | string | string[];
|
|
35
|
+
/** Custom data extractor for learning */
|
|
36
|
+
extractForLearning?: (data: unknown) => Record<string, unknown>;
|
|
37
|
+
/**
|
|
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.
|
|
41
|
+
* Default: false
|
|
42
|
+
*/
|
|
43
|
+
refreshOnRebuild?: boolean;
|
|
44
|
+
/** Request timeout in ms (default: 500ms for fast degradation) */
|
|
45
|
+
timeout?: number;
|
|
46
|
+
/** Enable debug logging */
|
|
47
|
+
debug?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Field name to use as URL for learning
|
|
50
|
+
* Useful when request URL is an API endpoint but data contains the actual page URL
|
|
51
|
+
*/
|
|
52
|
+
learnUrlField?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Batching configuration for high-performance crawling
|
|
55
|
+
*/
|
|
56
|
+
batch?: Partial<BatchConfig>;
|
|
57
|
+
/**
|
|
58
|
+
* Circuit breaker configuration for stability
|
|
59
|
+
*/
|
|
60
|
+
circuitBreaker?: Partial<CircuitBreakerConfig>;
|
|
61
|
+
/**
|
|
62
|
+
* Telemetry configuration - opt-in anonymous data sharing
|
|
63
|
+
* Helps improve proxy recommendations, detect blocks, optimize configs
|
|
64
|
+
* Default: disabled
|
|
65
|
+
*/
|
|
66
|
+
telemetry?: TelemetryConfig;
|
|
67
|
+
}
|
|
68
|
+
/** The raw request the SDK forwards; the API derives identity from a subset. */
|
|
69
|
+
interface RawRequest {
|
|
70
|
+
url: string;
|
|
71
|
+
method?: string;
|
|
72
|
+
uniqueKey?: string;
|
|
73
|
+
body?: string;
|
|
74
|
+
headers?: Record<string, string>;
|
|
75
|
+
userData?: Record<string, unknown>;
|
|
76
|
+
label?: string;
|
|
77
|
+
}
|
|
78
|
+
/** Query request to the API */
|
|
79
|
+
interface QueryRequest {
|
|
80
|
+
items: {
|
|
81
|
+
ref: string;
|
|
82
|
+
request: RawRequest;
|
|
83
|
+
}[];
|
|
84
|
+
intelligence: IntelligenceLevel;
|
|
85
|
+
build?: string;
|
|
86
|
+
}
|
|
87
|
+
/** Single query result (matched by ref) */
|
|
88
|
+
interface QueryResultItem {
|
|
89
|
+
ref: string;
|
|
90
|
+
data?: Record<string, unknown>;
|
|
91
|
+
confidence?: number;
|
|
92
|
+
}
|
|
93
|
+
/** Query response from the API */
|
|
94
|
+
interface QueryResponse {
|
|
95
|
+
known: {
|
|
96
|
+
ref: string;
|
|
97
|
+
data: Record<string, unknown>;
|
|
98
|
+
confidence: number;
|
|
99
|
+
}[];
|
|
100
|
+
unknown: string[];
|
|
101
|
+
}
|
|
102
|
+
/** Learn request to the API */
|
|
103
|
+
interface LearnRequest {
|
|
104
|
+
entries: {
|
|
105
|
+
request: RawRequest;
|
|
106
|
+
data: Record<string, unknown>;
|
|
107
|
+
}[];
|
|
108
|
+
}
|
|
109
|
+
/** Learn response from the API */
|
|
110
|
+
interface LearnResponse {
|
|
111
|
+
learned: number;
|
|
112
|
+
status: "success" | "partial" | "rejected";
|
|
113
|
+
errors?: string[];
|
|
114
|
+
}
|
|
115
|
+
/** Stats response from the API */
|
|
116
|
+
interface StatsResponse {
|
|
117
|
+
queries: number;
|
|
118
|
+
recognized: number;
|
|
119
|
+
recognitionRate: number;
|
|
120
|
+
learned: number;
|
|
121
|
+
period: string;
|
|
122
|
+
}
|
|
123
|
+
/** Result from AI knowledge query */
|
|
124
|
+
interface AIResult {
|
|
125
|
+
known: boolean;
|
|
126
|
+
data?: Record<string, unknown>;
|
|
127
|
+
confidence?: number;
|
|
128
|
+
fallback?: boolean;
|
|
129
|
+
}
|
|
130
|
+
/** Circuit breaker states */
|
|
131
|
+
type CircuitState = "closed" | "open" | "half-open";
|
|
132
|
+
/** Circuit breaker configuration */
|
|
133
|
+
interface CircuitBreakerConfig {
|
|
134
|
+
/** Number of failures before opening circuit */
|
|
135
|
+
failureThreshold: number;
|
|
136
|
+
/** Time to wait before trying half-open state (ms) */
|
|
137
|
+
resetTimeout: number;
|
|
138
|
+
/** Number of successful calls to close circuit from half-open */
|
|
139
|
+
successThreshold: number;
|
|
140
|
+
}
|
|
141
|
+
/** Batch configuration */
|
|
142
|
+
interface BatchConfig {
|
|
143
|
+
/** Max items per batch */
|
|
144
|
+
maxSize: number;
|
|
145
|
+
/** Max wait time before flushing (ms) */
|
|
146
|
+
maxWait: number;
|
|
147
|
+
}
|
|
148
|
+
/** Log levels */
|
|
149
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
150
|
+
/** Logger interface */
|
|
151
|
+
interface Logger {
|
|
152
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
153
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
154
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
155
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Telemetry configuration - opt-in data sharing for AI improvements
|
|
159
|
+
*/
|
|
160
|
+
interface TelemetryConfig {
|
|
161
|
+
/** Enable telemetry collection (default: false) */
|
|
162
|
+
enabled: boolean;
|
|
163
|
+
/** Share performance metrics: response times, retries, status codes */
|
|
164
|
+
sharePerformance?: boolean;
|
|
165
|
+
/** Share proxy info: country, type (never IP addresses) */
|
|
166
|
+
shareProxyInfo?: boolean;
|
|
167
|
+
/** Share site patterns: block rates, rate limits detected */
|
|
168
|
+
shareSitePatterns?: boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Telemetry data collected from Crawlee context
|
|
172
|
+
* All data is sanitized - no PII, no credentials, no raw content
|
|
173
|
+
*/
|
|
174
|
+
interface TelemetryData {
|
|
175
|
+
domain: string;
|
|
176
|
+
urlHash: string;
|
|
177
|
+
urlPattern?: string;
|
|
178
|
+
responseTimeMs?: number;
|
|
179
|
+
totalTimeMs?: number;
|
|
180
|
+
statusCode?: number;
|
|
181
|
+
contentSize?: number;
|
|
182
|
+
retryCount?: number;
|
|
183
|
+
proxyCountry?: string;
|
|
184
|
+
proxyType?: string;
|
|
185
|
+
proxySuccess?: boolean;
|
|
186
|
+
sessionAge?: number;
|
|
187
|
+
sessionErrorScore?: number;
|
|
188
|
+
cookieCount?: number;
|
|
189
|
+
blocked?: boolean;
|
|
190
|
+
blockType?: string;
|
|
191
|
+
crawlerType?: string;
|
|
192
|
+
requestLabel?: string;
|
|
193
|
+
timestamp: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Telemetry request to the API
|
|
197
|
+
*/
|
|
198
|
+
interface TelemetryRequest {
|
|
199
|
+
entries: TelemetryData[];
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Telemetry response from the API
|
|
203
|
+
*/
|
|
204
|
+
interface TelemetryResponse {
|
|
205
|
+
received: number;
|
|
206
|
+
status: "success" | "partial" | "error";
|
|
207
|
+
}
|
|
208
|
+
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fetchbrain.com/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
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.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./mock": {
|
|
15
|
+
"types": "./dist/mock/index.d.ts",
|
|
16
|
+
"import": "./dist/mock/index.mjs",
|
|
17
|
+
"require": "./dist/mock/index.js"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"files": [
|