-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add Firecrawl integration for website content crawling #1849
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
Open
devin-ai-integration
wants to merge
1
commit into
main
Choose a base branch
from
devin/1747373263-add-firecrawl-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+237
−3
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,7 @@ SUPABASE_DATABASE_URL=postgresql://postgres:[email protected]:54322/postgres | |
CSB_API_KEY=<Your api key from https://codesandbox.io/api > | ||
|
||
# Anthropic | ||
ANTHROPIC_API_KEY=<Your api key from https://console.anthropic.com/settings/keys > | ||
ANTHROPIC_API_KEY=<Your api key from https://console.anthropic.com/settings/keys > | ||
|
||
# Firecrawl | ||
VITE_FIRECRAWL_API_KEY=<Your api key from https://firecrawl.dev > |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter callback should return a boolean value, but line 72 is returning
fullUrl
instead. This will cause the filter to include URLs based on the string value rather than a true/false condition. To fix this, change:to:
This will correctly filter the array to only include valid URLs.
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.