@@ -9,25 +9,28 @@ interface SpiderLoaderParameters {
9
9
url : string
10
10
apiKey ?: string
11
11
mode ?: 'crawl' | 'scrape'
12
+ limit ?: number
12
13
params ?: Record < string , unknown >
13
14
}
14
15
15
16
class SpiderLoader extends BaseDocumentLoader {
16
17
private apiKey : string
17
18
private url : string
18
19
private mode : 'crawl' | 'scrape'
20
+ private limit ?: number
19
21
private params ?: Record < string , unknown >
20
22
21
23
constructor ( loaderParams : SpiderLoaderParameters ) {
22
24
super ( )
23
- const { apiKey, url, mode = 'crawl' , params } = loaderParams
25
+ const { apiKey, url, mode = 'crawl' , limit , params } = loaderParams
24
26
if ( ! apiKey ) {
25
27
throw new Error ( 'Spider API key not set. You can set it as SPIDER_API_KEY in your .env file, or pass it to Spider.' )
26
28
}
27
29
28
30
this . apiKey = apiKey
29
31
this . url = url
30
32
this . mode = mode
33
+ this . limit = Number ( limit )
31
34
this . params = params
32
35
}
33
36
@@ -42,6 +45,9 @@ class SpiderLoader extends BaseDocumentLoader {
42
45
}
43
46
spiderDocs = [ response . data ]
44
47
} else if ( this . mode === 'crawl' ) {
48
+ if ( this . params ) {
49
+ this . params . limit = this . limit
50
+ }
45
51
const response = await app . crawlUrl ( this . url , this . params )
46
52
if ( ! response . success ) {
47
53
throw new Error ( `Spider: Failed to crawl URL. Error: ${ response . error } ` )
@@ -113,6 +119,12 @@ class Spider_DocumentLoaders implements INode {
113
119
type : 'string' ,
114
120
placeholder : 'https://spider.cloud'
115
121
} ,
122
+ {
123
+ label : 'Limit' ,
124
+ name : 'limit' ,
125
+ type : 'number' ,
126
+ default : 25
127
+ } ,
116
128
{
117
129
label : 'Additional Parameters' ,
118
130
name : 'params' ,
@@ -136,6 +148,7 @@ class Spider_DocumentLoaders implements INode {
136
148
const textSplitter = nodeData . inputs ?. textSplitter as TextSplitter
137
149
const url = nodeData . inputs ?. url as string
138
150
const mode = nodeData . inputs ?. mode as 'crawl' | 'scrape'
151
+ const limit = nodeData . inputs ?. limit as number
139
152
let params = nodeData . inputs ?. params || { }
140
153
const credentialData = await getCredentialData ( nodeData . credential ?? '' , options )
141
154
const spiderApiKey = getCredentialParam ( 'spiderApiKey' , credentialData , nodeData )
@@ -155,6 +168,7 @@ class Spider_DocumentLoaders implements INode {
155
168
url,
156
169
mode : mode as 'crawl' | 'scrape' ,
157
170
apiKey : spiderApiKey ,
171
+ limit : limit as number ,
158
172
params : params as Record < string , unknown >
159
173
}
160
174
0 commit comments