-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Added firecrawl as a toolcall to crawl website contents from url #1797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47b20b3
Added firecrawl with an input box to crawl website contents from url
SoloDevAbu 2b43d82
Added strict url validation and fixed typo
SoloDevAbu 6c05577
fixed loading environment variable and moved hard-coded crawl input p…
SoloDevAbu db20380
Added validation for firecrawl api key and trimmed the url using url …
SoloDevAbu 793342e
make the url input clear on successful crawl
SoloDevAbu 3ee56d4
Added type-safe in the crawled response
SoloDevAbu 3857b50
Removed UI and make it a toolcall
SoloDevAbu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import FirecrawlApp from '@mendable/firecrawl-js'; | ||
|
|
||
| export interface CrawlOptions { | ||
| limit?: number; | ||
| scrapeOptions?: { | ||
| formats?: ( | ||
| | 'markdown' | ||
| | 'html' | ||
| | 'rawHtml' | ||
| | 'content' | ||
| | 'links' | ||
| | 'screenshot' | ||
| | 'screenshot@fullPage' | ||
| | 'extract' | ||
| | 'json' | ||
| | 'changeTracking' | ||
| )[]; | ||
| }; | ||
| } | ||
|
|
||
| export interface CrawlerResponse { | ||
| success: boolean; | ||
| error?: string; | ||
| data: Array<{ | ||
| html?: string; | ||
| markdown?: string; | ||
| }>; | ||
| } | ||
|
|
||
| export interface CrawledContent { | ||
| markdown?: string; | ||
| html?: string; | ||
| } | ||
|
|
||
| export function validateCrawlerResponse(response: unknown): response is CrawlerResponse { | ||
| if (!response || typeof response !== 'object') { | ||
| return false; | ||
| } | ||
|
|
||
| if (!('success' in response) || typeof response.success !== 'boolean') { | ||
| return false; | ||
| } | ||
|
|
||
| if (!('data' in response) || !Array.isArray(response.data)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (response.data.length === 0) { | ||
| return false; | ||
| } | ||
|
|
||
| const firstItem = response.data[0]; | ||
| return ( | ||
| typeof firstItem === 'object' && | ||
| firstItem !== null && | ||
| ('html' in firstItem || 'markdown' in firstItem) && | ||
| (firstItem.html === undefined || typeof firstItem.html === 'string') && | ||
| (firstItem.markdown === undefined || typeof firstItem.markdown === 'string') | ||
| ); | ||
| } | ||
|
|
||
| export class CrawlerService { | ||
| private static instance: CrawlerService; | ||
|
|
||
| private app: FirecrawlApp; | ||
|
|
||
| private constructor() { | ||
| const apiKey = import.meta.env.VITE_FIRECRAWL_API_KEY; | ||
| if (!apiKey) { | ||
| throw new Error( | ||
| 'VITE_FIRECRAWL_API_KEY is not defined. Please provide a valid API key.', | ||
| ); | ||
| } | ||
| this.app = new FirecrawlApp({ apiKey }); | ||
| } | ||
|
|
||
| static getInstance(): CrawlerService { | ||
| if (!this.instance) { | ||
| this.instance = new CrawlerService(); | ||
| } | ||
| return this.instance; | ||
| } | ||
|
|
||
| async crawlUrl( | ||
| url: string, | ||
| options: CrawlOptions = { | ||
| limit: 100, | ||
| scrapeOptions: { | ||
| formats: ['markdown', 'html'], | ||
| }, | ||
| }, | ||
| ) { | ||
| try { | ||
| const response = await this.app.crawlUrl(url, options); | ||
|
|
||
| if (!response.success) { | ||
| throw new Error(`Failed to crawl: ${response.error}`); | ||
| } | ||
| return response; | ||
| } catch (error) { | ||
| console.error('Error during crawling:', error); | ||
| throw error; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.