Skip to content

Commit cacbfa8

Browse files
feat: Add limit parameter to Spider tool (#2762)
* feat: Add limit parameter to Spider tool * fix pnpm lint
1 parent 656f6ca commit cacbfa8

File tree

1 file changed

+15
-1
lines changed
  • packages/components/nodes/documentloaders/Spider

1 file changed

+15
-1
lines changed

packages/components/nodes/documentloaders/Spider/Spider.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@ interface SpiderLoaderParameters {
99
url: string
1010
apiKey?: string
1111
mode?: 'crawl' | 'scrape'
12+
limit?: number
1213
params?: Record<string, unknown>
1314
}
1415

1516
class SpiderLoader extends BaseDocumentLoader {
1617
private apiKey: string
1718
private url: string
1819
private mode: 'crawl' | 'scrape'
20+
private limit?: number
1921
private params?: Record<string, unknown>
2022

2123
constructor(loaderParams: SpiderLoaderParameters) {
2224
super()
23-
const { apiKey, url, mode = 'crawl', params } = loaderParams
25+
const { apiKey, url, mode = 'crawl', limit, params } = loaderParams
2426
if (!apiKey) {
2527
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.')
2628
}
2729

2830
this.apiKey = apiKey
2931
this.url = url
3032
this.mode = mode
33+
this.limit = Number(limit)
3134
this.params = params
3235
}
3336

@@ -42,6 +45,9 @@ class SpiderLoader extends BaseDocumentLoader {
4245
}
4346
spiderDocs = [response.data]
4447
} else if (this.mode === 'crawl') {
48+
if (this.params) {
49+
this.params.limit = this.limit
50+
}
4551
const response = await app.crawlUrl(this.url, this.params)
4652
if (!response.success) {
4753
throw new Error(`Spider: Failed to crawl URL. Error: ${response.error}`)
@@ -113,6 +119,12 @@ class Spider_DocumentLoaders implements INode {
113119
type: 'string',
114120
placeholder: 'https://spider.cloud'
115121
},
122+
{
123+
label: 'Limit',
124+
name: 'limit',
125+
type: 'number',
126+
default: 25
127+
},
116128
{
117129
label: 'Additional Parameters',
118130
name: 'params',
@@ -136,6 +148,7 @@ class Spider_DocumentLoaders implements INode {
136148
const textSplitter = nodeData.inputs?.textSplitter as TextSplitter
137149
const url = nodeData.inputs?.url as string
138150
const mode = nodeData.inputs?.mode as 'crawl' | 'scrape'
151+
const limit = nodeData.inputs?.limit as number
139152
let params = nodeData.inputs?.params || {}
140153
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
141154
const spiderApiKey = getCredentialParam('spiderApiKey', credentialData, nodeData)
@@ -155,6 +168,7 @@ class Spider_DocumentLoaders implements INode {
155168
url,
156169
mode: mode as 'crawl' | 'scrape',
157170
apiKey: spiderApiKey,
171+
limit: limit as number,
158172
params: params as Record<string, unknown>
159173
}
160174

0 commit comments

Comments
 (0)