@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
package/README.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# FetchBrain
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- TODO: logo image once brand CDN URL is confirmed -->
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**The AI that already knows the web.**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`@fetchbrain.com/sdk` — AI-powered scraping optimization for Crawlee. Query before you fetch; teach what you learn.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/fetchbrain-com/sdk/actions/workflows/ci.yml) [](https://www.npmjs.com/package/@fetchbrain.com/sdk) [](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
FetchBrain is AI-powered web intelligence for scrapers. Ask first — if the AI already knows the URL, you get the data instantly and the HTTP request is skipped entirely. If it doesn't, your scraper runs as normal and teaches FetchBrain for next time.
|
|
8
12
|
|
|
9
13
|
## Features
|
|
10
14
|
|
|
@@ -279,4 +283,4 @@ MIT © FetchBrain
|
|
|
279
283
|
|
|
280
284
|
---
|
|
281
285
|
|
|
282
|
-
**Need help?** [Open an issue](https://github.com/fetchbrain-com/
|
|
286
|
+
**Need help?** [Open an issue](https://github.com/fetchbrain-com/sdk/issues) or check our [documentation](https://docs.fetchbrain.com).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,202 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
/** Query request to the API */
|
|
69
|
-
interface QueryRequest {
|
|
70
|
-
urls: string[];
|
|
71
|
-
actorId?: string;
|
|
72
|
-
intelligence: IntelligenceLevel;
|
|
73
|
-
/** If specified, only return data from this build version */
|
|
74
|
-
build?: string;
|
|
75
|
-
}
|
|
76
|
-
/** Single query result */
|
|
77
|
-
interface QueryResultItem {
|
|
78
|
-
url: string;
|
|
79
|
-
known: boolean;
|
|
80
|
-
data?: Record<string, unknown>;
|
|
81
|
-
confidence?: number;
|
|
82
|
-
}
|
|
83
|
-
/** Query response from the API */
|
|
84
|
-
interface QueryResponse {
|
|
85
|
-
known: QueryResultItem[];
|
|
86
|
-
unknown: string[];
|
|
87
|
-
}
|
|
88
|
-
/** Learn request to the API */
|
|
89
|
-
interface LearnRequest {
|
|
90
|
-
actorId?: string;
|
|
91
|
-
entries: Array<{
|
|
92
|
-
url: string;
|
|
93
|
-
data: Record<string, unknown>;
|
|
94
|
-
}>;
|
|
95
|
-
}
|
|
96
|
-
/** Learn response from the API */
|
|
97
|
-
interface LearnResponse {
|
|
98
|
-
status: "accepted" | "rejected" | "flagged";
|
|
99
|
-
learned: number;
|
|
100
|
-
verification?: {
|
|
101
|
-
schemaValid: boolean;
|
|
102
|
-
valuesValid: boolean;
|
|
103
|
-
duplicate: boolean;
|
|
104
|
-
warnings: string[];
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/** Stats response from the API */
|
|
108
|
-
interface StatsResponse {
|
|
109
|
-
queries: number;
|
|
110
|
-
recognized: number;
|
|
111
|
-
recognitionRate: number;
|
|
112
|
-
learned: number;
|
|
113
|
-
period: string;
|
|
114
|
-
}
|
|
115
|
-
/** Result from AI knowledge query */
|
|
116
|
-
interface AIResult {
|
|
117
|
-
known: boolean;
|
|
118
|
-
data?: Record<string, unknown>;
|
|
119
|
-
confidence?: number;
|
|
120
|
-
fallback?: boolean;
|
|
121
|
-
}
|
|
122
|
-
/** Circuit breaker states */
|
|
123
|
-
type CircuitState = "closed" | "open" | "half-open";
|
|
124
|
-
/** Circuit breaker configuration */
|
|
125
|
-
interface CircuitBreakerConfig {
|
|
126
|
-
/** Number of failures before opening circuit */
|
|
127
|
-
failureThreshold: number;
|
|
128
|
-
/** Time to wait before trying half-open state (ms) */
|
|
129
|
-
resetTimeout: number;
|
|
130
|
-
/** Number of successful calls to close circuit from half-open */
|
|
131
|
-
successThreshold: number;
|
|
132
|
-
}
|
|
133
|
-
/** Batch configuration */
|
|
134
|
-
interface BatchConfig {
|
|
135
|
-
/** Max items per batch */
|
|
136
|
-
maxSize: number;
|
|
137
|
-
/** Max wait time before flushing (ms) */
|
|
138
|
-
maxWait: number;
|
|
139
|
-
}
|
|
140
|
-
/** Log levels */
|
|
141
|
-
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
142
|
-
/** Logger interface */
|
|
143
|
-
interface Logger {
|
|
144
|
-
debug: (message: string, ...args: unknown[]) => void;
|
|
145
|
-
info: (message: string, ...args: unknown[]) => void;
|
|
146
|
-
warn: (message: string, ...args: unknown[]) => void;
|
|
147
|
-
error: (message: string, ...args: unknown[]) => void;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Telemetry configuration - opt-in data sharing for AI improvements
|
|
151
|
-
*/
|
|
152
|
-
interface TelemetryConfig {
|
|
153
|
-
/** Enable telemetry collection (default: false) */
|
|
154
|
-
enabled: boolean;
|
|
155
|
-
/** Share performance metrics: response times, retries, status codes */
|
|
156
|
-
sharePerformance?: boolean;
|
|
157
|
-
/** Share proxy info: country, type (never IP addresses) */
|
|
158
|
-
shareProxyInfo?: boolean;
|
|
159
|
-
/** Share site patterns: block rates, rate limits detected */
|
|
160
|
-
shareSitePatterns?: boolean;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Telemetry data collected from Crawlee context
|
|
164
|
-
* All data is sanitized - no PII, no credentials, no raw content
|
|
165
|
-
*/
|
|
166
|
-
interface TelemetryData {
|
|
167
|
-
domain: string;
|
|
168
|
-
urlHash: string;
|
|
169
|
-
urlPattern?: string;
|
|
170
|
-
responseTimeMs?: number;
|
|
171
|
-
totalTimeMs?: number;
|
|
172
|
-
statusCode?: number;
|
|
173
|
-
contentSize?: number;
|
|
174
|
-
retryCount?: number;
|
|
175
|
-
proxyCountry?: string;
|
|
176
|
-
proxyType?: string;
|
|
177
|
-
proxySuccess?: boolean;
|
|
178
|
-
sessionAge?: number;
|
|
179
|
-
sessionErrorScore?: number;
|
|
180
|
-
cookieCount?: number;
|
|
181
|
-
blocked?: boolean;
|
|
182
|
-
blockType?: string;
|
|
183
|
-
crawlerType?: string;
|
|
184
|
-
requestLabel?: string;
|
|
185
|
-
timestamp: string;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Telemetry request to the API
|
|
189
|
-
*/
|
|
190
|
-
interface TelemetryRequest {
|
|
191
|
-
entries: TelemetryData[];
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Telemetry response from the API
|
|
195
|
-
*/
|
|
196
|
-
interface TelemetryResponse {
|
|
197
|
-
received: number;
|
|
198
|
-
status: "success" | "partial" | "error";
|
|
199
|
-
}
|
|
1
|
+
import { F as FetchBrainConfig, R as RawRequest, A as AIResult, L as LearnResponse, S as StatsResponse, C as CircuitState, T as TelemetryData, a as TelemetryConfig, b as CircuitBreakerConfig, c as Logger, B as BatchConfig, d as LogLevel } from './types-Ddu_K1Nn.mjs';
|
|
2
|
+
export { j as AIMemoryDepth, I as IntelligenceLevel, g as LearnRequest, Q as QueryRequest, e as QueryResponse, f as QueryResultItem, h as TelemetryRequest, i as TelemetryResponse } from './types-Ddu_K1Nn.mjs';
|
|
200
3
|
|
|
201
4
|
/**
|
|
202
5
|
* FetchBrain API Client
|
|
@@ -214,17 +17,17 @@ declare class FetchBrainClient {
|
|
|
214
17
|
private logger;
|
|
215
18
|
constructor(config: FetchBrainConfig);
|
|
216
19
|
/**
|
|
217
|
-
* Query if FetchBrain "knows" a
|
|
20
|
+
* Query if FetchBrain "knows" a request
|
|
218
21
|
*/
|
|
219
|
-
query(
|
|
22
|
+
query(request: RawRequest): Promise<AIResult>;
|
|
220
23
|
/**
|
|
221
|
-
* Query multiple
|
|
24
|
+
* Query multiple requests at once — returns ordered array matching input order
|
|
222
25
|
*/
|
|
223
|
-
queryBulk(
|
|
26
|
+
queryBulk(requests: RawRequest[]): Promise<AIResult[]>;
|
|
224
27
|
/**
|
|
225
28
|
* "Teach" FetchBrain new data (batched for high-concurrency)
|
|
226
29
|
*/
|
|
227
|
-
learn(
|
|
30
|
+
learn(request: RawRequest, data: Record<string, unknown>): Promise<LearnResponse>;
|
|
228
31
|
/**
|
|
229
32
|
* Get usage statistics
|
|
230
33
|
*/
|
|
@@ -285,7 +88,7 @@ declare class FetchBrainClient {
|
|
|
285
88
|
* This allows Dataset.pushData interception even when called statically
|
|
286
89
|
*/
|
|
287
90
|
interface RequestContext {
|
|
288
|
-
|
|
91
|
+
request: RawRequest;
|
|
289
92
|
client: FetchBrainClient;
|
|
290
93
|
learning: boolean;
|
|
291
94
|
aiKnown: boolean;
|
|
@@ -435,7 +238,10 @@ declare class CircuitBreaker {
|
|
|
435
238
|
};
|
|
436
239
|
}
|
|
437
240
|
|
|
438
|
-
type BatchExecutor = (
|
|
241
|
+
type BatchExecutor = (items: {
|
|
242
|
+
ref: string;
|
|
243
|
+
request: RawRequest;
|
|
244
|
+
}[]) => Promise<Map<string, AIResult>>;
|
|
439
245
|
/**
|
|
440
246
|
* Request Batcher
|
|
441
247
|
*
|
|
@@ -448,11 +254,12 @@ declare class RequestBatcher {
|
|
|
448
254
|
private config;
|
|
449
255
|
private executor;
|
|
450
256
|
private logger;
|
|
257
|
+
private refSeq;
|
|
451
258
|
constructor(executor: BatchExecutor, config: Partial<BatchConfig> | undefined, logger: Logger);
|
|
452
259
|
/**
|
|
453
|
-
* Add a
|
|
260
|
+
* Add a request to the batch queue
|
|
454
261
|
*/
|
|
455
|
-
query(
|
|
262
|
+
query(request: RawRequest): Promise<AIResult>;
|
|
456
263
|
/**
|
|
457
264
|
* Flush the current batch
|
|
458
265
|
*/
|
|
@@ -558,4 +365,4 @@ declare class TelemetryBuffer {
|
|
|
558
365
|
stop(): Promise<void>;
|
|
559
366
|
}
|
|
560
367
|
|
|
561
|
-
export {
|
|
368
|
+
export { AIResult, BatchConfig, CircuitBreaker, CircuitBreakerConfig, CircuitState, type CrawleeContext, FetchBrain, FetchBrainClient, FetchBrainConfig, type FetchBrainContext, LearnResponse, LogLevel, Logger, RawRequest, RequestBatcher, type RequestTiming, StatsResponse, TelemetryBuffer, TelemetryConfig, TelemetryData, collectTelemetry, createFetchBrain, createLogger, getCurrentContext, pushData };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,202 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
/** Query request to the API */
|
|
69
|
-
interface QueryRequest {
|
|
70
|
-
urls: string[];
|
|
71
|
-
actorId?: string;
|
|
72
|
-
intelligence: IntelligenceLevel;
|
|
73
|
-
/** If specified, only return data from this build version */
|
|
74
|
-
build?: string;
|
|
75
|
-
}
|
|
76
|
-
/** Single query result */
|
|
77
|
-
interface QueryResultItem {
|
|
78
|
-
url: string;
|
|
79
|
-
known: boolean;
|
|
80
|
-
data?: Record<string, unknown>;
|
|
81
|
-
confidence?: number;
|
|
82
|
-
}
|
|
83
|
-
/** Query response from the API */
|
|
84
|
-
interface QueryResponse {
|
|
85
|
-
known: QueryResultItem[];
|
|
86
|
-
unknown: string[];
|
|
87
|
-
}
|
|
88
|
-
/** Learn request to the API */
|
|
89
|
-
interface LearnRequest {
|
|
90
|
-
actorId?: string;
|
|
91
|
-
entries: Array<{
|
|
92
|
-
url: string;
|
|
93
|
-
data: Record<string, unknown>;
|
|
94
|
-
}>;
|
|
95
|
-
}
|
|
96
|
-
/** Learn response from the API */
|
|
97
|
-
interface LearnResponse {
|
|
98
|
-
status: "accepted" | "rejected" | "flagged";
|
|
99
|
-
learned: number;
|
|
100
|
-
verification?: {
|
|
101
|
-
schemaValid: boolean;
|
|
102
|
-
valuesValid: boolean;
|
|
103
|
-
duplicate: boolean;
|
|
104
|
-
warnings: string[];
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/** Stats response from the API */
|
|
108
|
-
interface StatsResponse {
|
|
109
|
-
queries: number;
|
|
110
|
-
recognized: number;
|
|
111
|
-
recognitionRate: number;
|
|
112
|
-
learned: number;
|
|
113
|
-
period: string;
|
|
114
|
-
}
|
|
115
|
-
/** Result from AI knowledge query */
|
|
116
|
-
interface AIResult {
|
|
117
|
-
known: boolean;
|
|
118
|
-
data?: Record<string, unknown>;
|
|
119
|
-
confidence?: number;
|
|
120
|
-
fallback?: boolean;
|
|
121
|
-
}
|
|
122
|
-
/** Circuit breaker states */
|
|
123
|
-
type CircuitState = "closed" | "open" | "half-open";
|
|
124
|
-
/** Circuit breaker configuration */
|
|
125
|
-
interface CircuitBreakerConfig {
|
|
126
|
-
/** Number of failures before opening circuit */
|
|
127
|
-
failureThreshold: number;
|
|
128
|
-
/** Time to wait before trying half-open state (ms) */
|
|
129
|
-
resetTimeout: number;
|
|
130
|
-
/** Number of successful calls to close circuit from half-open */
|
|
131
|
-
successThreshold: number;
|
|
132
|
-
}
|
|
133
|
-
/** Batch configuration */
|
|
134
|
-
interface BatchConfig {
|
|
135
|
-
/** Max items per batch */
|
|
136
|
-
maxSize: number;
|
|
137
|
-
/** Max wait time before flushing (ms) */
|
|
138
|
-
maxWait: number;
|
|
139
|
-
}
|
|
140
|
-
/** Log levels */
|
|
141
|
-
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
142
|
-
/** Logger interface */
|
|
143
|
-
interface Logger {
|
|
144
|
-
debug: (message: string, ...args: unknown[]) => void;
|
|
145
|
-
info: (message: string, ...args: unknown[]) => void;
|
|
146
|
-
warn: (message: string, ...args: unknown[]) => void;
|
|
147
|
-
error: (message: string, ...args: unknown[]) => void;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Telemetry configuration - opt-in data sharing for AI improvements
|
|
151
|
-
*/
|
|
152
|
-
interface TelemetryConfig {
|
|
153
|
-
/** Enable telemetry collection (default: false) */
|
|
154
|
-
enabled: boolean;
|
|
155
|
-
/** Share performance metrics: response times, retries, status codes */
|
|
156
|
-
sharePerformance?: boolean;
|
|
157
|
-
/** Share proxy info: country, type (never IP addresses) */
|
|
158
|
-
shareProxyInfo?: boolean;
|
|
159
|
-
/** Share site patterns: block rates, rate limits detected */
|
|
160
|
-
shareSitePatterns?: boolean;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Telemetry data collected from Crawlee context
|
|
164
|
-
* All data is sanitized - no PII, no credentials, no raw content
|
|
165
|
-
*/
|
|
166
|
-
interface TelemetryData {
|
|
167
|
-
domain: string;
|
|
168
|
-
urlHash: string;
|
|
169
|
-
urlPattern?: string;
|
|
170
|
-
responseTimeMs?: number;
|
|
171
|
-
totalTimeMs?: number;
|
|
172
|
-
statusCode?: number;
|
|
173
|
-
contentSize?: number;
|
|
174
|
-
retryCount?: number;
|
|
175
|
-
proxyCountry?: string;
|
|
176
|
-
proxyType?: string;
|
|
177
|
-
proxySuccess?: boolean;
|
|
178
|
-
sessionAge?: number;
|
|
179
|
-
sessionErrorScore?: number;
|
|
180
|
-
cookieCount?: number;
|
|
181
|
-
blocked?: boolean;
|
|
182
|
-
blockType?: string;
|
|
183
|
-
crawlerType?: string;
|
|
184
|
-
requestLabel?: string;
|
|
185
|
-
timestamp: string;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Telemetry request to the API
|
|
189
|
-
*/
|
|
190
|
-
interface TelemetryRequest {
|
|
191
|
-
entries: TelemetryData[];
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Telemetry response from the API
|
|
195
|
-
*/
|
|
196
|
-
interface TelemetryResponse {
|
|
197
|
-
received: number;
|
|
198
|
-
status: "success" | "partial" | "error";
|
|
199
|
-
}
|
|
1
|
+
import { F as FetchBrainConfig, R as RawRequest, A as AIResult, L as LearnResponse, S as StatsResponse, C as CircuitState, T as TelemetryData, a as TelemetryConfig, b as CircuitBreakerConfig, c as Logger, B as BatchConfig, d as LogLevel } from './types-Ddu_K1Nn.js';
|
|
2
|
+
export { j as AIMemoryDepth, I as IntelligenceLevel, g as LearnRequest, Q as QueryRequest, e as QueryResponse, f as QueryResultItem, h as TelemetryRequest, i as TelemetryResponse } from './types-Ddu_K1Nn.js';
|
|
200
3
|
|
|
201
4
|
/**
|
|
202
5
|
* FetchBrain API Client
|
|
@@ -214,17 +17,17 @@ declare class FetchBrainClient {
|
|
|
214
17
|
private logger;
|
|
215
18
|
constructor(config: FetchBrainConfig);
|
|
216
19
|
/**
|
|
217
|
-
* Query if FetchBrain "knows" a
|
|
20
|
+
* Query if FetchBrain "knows" a request
|
|
218
21
|
*/
|
|
219
|
-
query(
|
|
22
|
+
query(request: RawRequest): Promise<AIResult>;
|
|
220
23
|
/**
|
|
221
|
-
* Query multiple
|
|
24
|
+
* Query multiple requests at once — returns ordered array matching input order
|
|
222
25
|
*/
|
|
223
|
-
queryBulk(
|
|
26
|
+
queryBulk(requests: RawRequest[]): Promise<AIResult[]>;
|
|
224
27
|
/**
|
|
225
28
|
* "Teach" FetchBrain new data (batched for high-concurrency)
|
|
226
29
|
*/
|
|
227
|
-
learn(
|
|
30
|
+
learn(request: RawRequest, data: Record<string, unknown>): Promise<LearnResponse>;
|
|
228
31
|
/**
|
|
229
32
|
* Get usage statistics
|
|
230
33
|
*/
|
|
@@ -285,7 +88,7 @@ declare class FetchBrainClient {
|
|
|
285
88
|
* This allows Dataset.pushData interception even when called statically
|
|
286
89
|
*/
|
|
287
90
|
interface RequestContext {
|
|
288
|
-
|
|
91
|
+
request: RawRequest;
|
|
289
92
|
client: FetchBrainClient;
|
|
290
93
|
learning: boolean;
|
|
291
94
|
aiKnown: boolean;
|
|
@@ -435,7 +238,10 @@ declare class CircuitBreaker {
|
|
|
435
238
|
};
|
|
436
239
|
}
|
|
437
240
|
|
|
438
|
-
type BatchExecutor = (
|
|
241
|
+
type BatchExecutor = (items: {
|
|
242
|
+
ref: string;
|
|
243
|
+
request: RawRequest;
|
|
244
|
+
}[]) => Promise<Map<string, AIResult>>;
|
|
439
245
|
/**
|
|
440
246
|
* Request Batcher
|
|
441
247
|
*
|
|
@@ -448,11 +254,12 @@ declare class RequestBatcher {
|
|
|
448
254
|
private config;
|
|
449
255
|
private executor;
|
|
450
256
|
private logger;
|
|
257
|
+
private refSeq;
|
|
451
258
|
constructor(executor: BatchExecutor, config: Partial<BatchConfig> | undefined, logger: Logger);
|
|
452
259
|
/**
|
|
453
|
-
* Add a
|
|
260
|
+
* Add a request to the batch queue
|
|
454
261
|
*/
|
|
455
|
-
query(
|
|
262
|
+
query(request: RawRequest): Promise<AIResult>;
|
|
456
263
|
/**
|
|
457
264
|
* Flush the current batch
|
|
458
265
|
*/
|
|
@@ -558,4 +365,4 @@ declare class TelemetryBuffer {
|
|
|
558
365
|
stop(): Promise<void>;
|
|
559
366
|
}
|
|
560
367
|
|
|
561
|
-
export {
|
|
368
|
+
export { AIResult, BatchConfig, CircuitBreaker, CircuitBreakerConfig, CircuitState, type CrawleeContext, FetchBrain, FetchBrainClient, FetchBrainConfig, type FetchBrainContext, LearnResponse, LogLevel, Logger, RawRequest, RequestBatcher, type RequestTiming, StatsResponse, TelemetryBuffer, TelemetryConfig, TelemetryData, collectTelemetry, createFetchBrain, createLogger, getCurrentContext, pushData };
|