Skip to content

Commit 782cd4b

Browse files
committed
fix(firecrawl): read a scheme-less start URL as https when counting depth
1 parent 4ae6aca commit 782cd4b

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎.github/CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ The easiest way to run Sim locally is the interactive setup wizard:
148148
npx sim-setup
149149
```
150150

151-
When it finishes, open [http://localhost:3000/](http://localhost:3000/) in your browser. Inside a cloned Sim repository, run `bun run sim-setup` for the local development mode.
151+
When it finishes, open [http://localhost:3000/](http://localhost:3000/) in your browser. Inside a cloned Sim repository, run `bun run sim-setup --mode dev` for the local development mode.
152152

153153
#### Requirements
154154

‎apps/sim/tools/firecrawl/crawl.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('Firecrawl legacy crawl depth', () => {
7272
['https://example.com/docs/guide/', '/docs/guide/setup', true],
7373
['https://example.com/docs/guide/index.html', '/docs/guide/setup', true],
7474
['https://example.com/docs/guide', '/docs/guide/setup/advanced', false],
75+
['docs.example.com/guide', '/guide/setup', true],
7576
])('counts depth from the start URL %s for %s', (url, path, accepted) => {
7677
const body = crawlBody({ maxDepth: 1, url })
7778
const patterns = (body.includePaths as string[]).map((pattern) => new RegExp(pattern))

‎apps/sim/tools/firecrawl/crawl.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ const logger = createLogger('FirecrawlCrawlTool')
1818
const POLL_INTERVAL_MS = 5000
1919
const MAX_POLL_TIME_MS = DEFAULT_EXECUTION_TIMEOUT_MS
2020

21-
/** Path segments of a URL as Firecrawl v1 counted them: index files add no depth. */
21+
/**
22+
* Path segments of a URL as Firecrawl v1 counted them: index files add no depth. A URL without
23+
* a scheme is read as https, as Firecrawl reads it.
24+
*/
2225
function urlPathDepth(url: string): number {
23-
if (!URL.canParse(url)) return 0
24-
return new URL(url).pathname
26+
const absolute = /^[a-z][a-z\d+.-]*:\/\//i.test(url) ? url : `https://${url}`
27+
if (!URL.canParse(absolute)) return 0
28+
return new URL(absolute).pathname
2529
.split('/')
2630
.filter((segment) => segment !== '' && segment !== 'index.html' && segment !== 'index.php')
2731
.length

0 commit comments

Comments
 (0)