Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/docs/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4874,6 +4874,27 @@ export function WealthboxIcon(props: SVGProps<SVGSVGElement>) {
)
}

export function WebsiteIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
{...props}
xmlns='http://www.w3.org/2000/svg'
width='24'
height='24'
viewBox='0 0 24 24'
fill='none'
stroke='currentColor'
strokeWidth='2'
strokeLinecap='round'
strokeLinejoin='round'
>
<circle cx='12' cy='12' r='10' />
<path d='M2 12h20' />
<path d='M12 2a15 15 0 0 1 4 10 15 15 0 0 1-4 10 15 15 0 0 1-4-10 15 15 0 0 1 4-10z' />
</svg>
)
}

export function WebhookIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
Expand Down
21 changes: 21 additions & 0 deletions apps/sim/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4874,6 +4874,27 @@ export function WealthboxIcon(props: SVGProps<SVGSVGElement>) {
)
}

export function WebsiteIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
{...props}
xmlns='http://www.w3.org/2000/svg'
width='24'
height='24'
viewBox='0 0 24 24'
fill='none'
stroke='currentColor'
strokeWidth='2'
strokeLinecap='round'
strokeLinejoin='round'
>
<circle cx='12' cy='12' r='10' />
<path d='M2 12h20' />
<path d='M12 2a15 15 0 0 1 4 10 15 15 0 0 1-4 10 15 15 0 0 1-4-10 15 15 0 0 1 4-10z' />
</svg>
)
}

export function WebhookIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/connectors/registry.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { trelloConnector } from '@/connectors/trello'
import { typeformConnector } from '@/connectors/typeform'
import type { ConnectorRegistry } from '@/connectors/types'
import { webflowConnector } from '@/connectors/webflow'
import { websiteConnector } from '@/connectors/website'
import { wordpressConnector } from '@/connectors/wordpress'
import { workdayConnector } from '@/connectors/workday'
import { xConnector } from '@/connectors/x'
Expand Down Expand Up @@ -139,6 +140,7 @@ export const CONNECTOR_REGISTRY: ConnectorRegistry = {
trello: trelloConnector,
typeform: typeformConnector,
webflow: webflowConnector,
website: websiteConnector,
wordpress: wordpressConnector,
workday: workdayConnector,
x: xConnector,
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/connectors/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { trelloConnectorMeta } from '@/connectors/trello/meta'
import { typeformConnectorMeta } from '@/connectors/typeform/meta'
import type { ConnectorMeta, ConnectorMetaRegistry } from '@/connectors/types'
import { webflowConnectorMeta } from '@/connectors/webflow/meta'
import { websiteConnectorMeta } from '@/connectors/website/meta'
import { wordpressConnectorMeta } from '@/connectors/wordpress/meta'
import { workdayConnectorMeta } from '@/connectors/workday/meta'
import { xConnectorMeta } from '@/connectors/x/meta'
Expand Down Expand Up @@ -139,6 +140,7 @@ export const CONNECTOR_META_REGISTRY: ConnectorMetaRegistry = {
trello: trelloConnectorMeta,
typeform: typeformConnectorMeta,
webflow: webflowConnectorMeta,
website: websiteConnectorMeta,
wordpress: wordpressConnectorMeta,
workday: workdayConnectorMeta,
x: xConnectorMeta,
Expand Down
1 change: 1 addition & 0 deletions apps/sim/connectors/website/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { websiteConnector } from '@/connectors/website/website'
80 changes: 80 additions & 0 deletions apps/sim/connectors/website/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { WebsiteIcon } from '@/components/icons'
import type { ConnectorMeta } from '@/connectors/types'

/** Pages indexed per sync when `maxPages` is not configured. */
export const WEBSITE_DEFAULT_MAX_PAGES = 500

/** Hard ceiling on the configurable `maxPages` value. */
export const WEBSITE_MAX_PAGES_LIMIT = 5000

/** Client-safe metadata for the website connector: its setup fields, auth and tags. */
export const websiteConnectorMeta: ConnectorMeta = {
id: 'website',
name: 'Website',
description: 'Sync the pages of a website from its sitemap',
version: '1.0.0',
icon: WebsiteIcon,

/**
* Public sites need nothing. A site behind a gateway that accepts a service credential in one
* header, such as an API key, takes one `Name: value` line. Cookies are refused: a session cookie
* is a person's identity, and everything it unlocks would become readable to everyone with
* access to the knowledge base.
*/
auth: {
mode: 'apiKey',
label: 'Request Header',
placeholder: 'Only for sites that require a service header, e.g. X-Api-Key: value',
optional: true,
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
},

configFields: [
{
id: 'siteUrl',
title: 'Website URL',
type: 'short-input',
placeholder: 'https://www.example.com',
required: true,
description:
'Pages are discovered from the sitemaps the site lists in robots.txt, or its sitemap.xml. Only pages on this host and under this path are synced, and robots.txt rules are honored.',
},
{
id: 'sitemapUrl',
title: 'Sitemap URL',
type: 'short-input',
placeholder: 'e.g. https://www.example.com/pages-sitemap.xml',
required: false,
description: 'A sitemap on the same host to read instead of the discovered ones',
},
{
id: 'includePaths',
title: 'Include Paths',
type: 'short-input',
placeholder: 'e.g. /benefits, /help/*/faq',
required: false,
description:
'Comma-separated path prefixes to sync; * matches any characters. Leave empty to sync every page.',
},
{
id: 'excludePaths',
title: 'Exclude Paths',
type: 'short-input',
placeholder: 'e.g. /blog, /archive',
required: false,
description: 'Comma-separated path prefixes never to sync; * matches any characters.',
},
{
id: 'maxPages',
title: 'Max Pages',
type: 'short-input',
placeholder: `e.g. 200 (default: ${WEBSITE_DEFAULT_MAX_PAGES}, max: ${WEBSITE_MAX_PAGES_LIMIT})`,
required: false,
description: 'Maximum number of pages to index',
},
],

tagDefinitions: [
{ id: 'section', displayName: 'Section', fieldType: 'text' },
{ id: 'lastModified', displayName: 'Last Modified', fieldType: 'date' },
],
}
42 changes: 42 additions & 0 deletions apps/sim/connectors/website/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as cheerio from 'cheerio'
import {
assertHtmlStringWithinLimits,
loadedHtmlToStructuredText,
} from '@/lib/file-parsers/html-parser'
import { WEBSITE_CRAWLER_TOKEN } from '@/connectors/website/robots'

/** Page-level chrome repeated on every page, which would make every page's text look alike. */
const CHROME_SELECTOR =
'body > header, body > footer, nav, [role="navigation"], [role="banner"], [role="contentinfo"]'

/** What a rendered page contributes to the index: its title, its text, and whether it opts out. */
export interface WebsitePageText {
title: string
text: string
/** The page asks not to be indexed (`noindex` or `none` in its robots meta tag). */
noindex: boolean
}

/**
* Reads a rendered HTML page as structured text: headings, lists and tables survive, scripts and
* styles do not, and the `<main>` or `<article>` region is preferred over the whole body. The
* shared HTML size and markup limits apply before the page is parsed.
*/
export function extractPageText(html: string): WebsitePageText {
assertHtmlStringWithinLimits(html)
const $ = cheerio.load(html)
const directives = $(`meta[name="robots" i], meta[name="${WEBSITE_CRAWLER_TOKEN}" i]`)
.map((_, element) => $(element).attr('content') ?? '')
.get()
.join(',')
const title =
$('meta[property="og:title"]').attr('content')?.trim() ||
$('title').first().text().trim() ||
$('h1').first().text().trim()
$(CHROME_SELECTOR).remove()
const region = ['main', 'article'].find((selector) => $(selector).length > 0) ?? 'body'
const regionText = loadedHtmlToStructuredText($, region)
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
// A client-rendered page leaves <main>/<article> empty; fall back to the body.
const text = regionText || region === 'body' ? regionText : loadedHtmlToStructuredText($)
return { title, text, noindex: /\b(noindex|none)\b/i.test(directives) }
}
80 changes: 80 additions & 0 deletions apps/sim/connectors/website/robots.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { describe, expect, it } from 'vitest'
import { parseRobots } from '@/connectors/website/robots'

describe('robots.txt rules for the website connector', () => {
it('lets the longest matching rule decide, with Allow winning a tie', () => {
const robots = parseRobots(
[
'User-agent: *',
'Disallow: /private',
'Allow: /private/handbook',
'Disallow: /tie',
'Allow: /tie',
].join('\n')
)
expect(robots.allows('/private/salaries')).toBe(false)
expect(robots.allows('/private/handbook/leave')).toBe(true)
expect(robots.allows('/tie')).toBe(true)
expect(parseRobots('User-agent: *\nAllow: /foo\nDisallow: /foo$').allows('/foo')).toBe(true)
expect(robots.allows('/public')).toBe(true)
})

it('applies only the group naming this crawler when one exists', () => {
const robots = parseRobots(
[
'User-agent: *',
'Disallow: /',
'',
'User-agent: OtherBot',
'User-agent: SimBot',
'Disallow: /drafts',
].join('\n')
)
expect(robots.allows('/benefits')).toBe(true)
expect(robots.allows('/drafts/plan')).toBe(false)
})

it('matches wildcards and end anchors against the path and query', () => {
const robots = parseRobots(
['User-agent: *', 'Disallow: /*?print=', 'Disallow: /*.pdf$'].join('\n')
)
expect(robots.allows('/plans?print=1')).toBe(false)
expect(robots.allows('/guide.pdf')).toBe(false)
expect(robots.allows('/guide.pdf.html')).toBe(true)
})

it('treats an empty Disallow as allowing everything and collects declared sitemaps', () => {
const robots = parseRobots(
['Sitemap: https://example.com/a.xml', 'User-agent: *', 'Disallow:', '# Disallow: /x'].join(
'\n'
)
)
expect(robots.allows('/x')).toBe(true)
expect(robots.sitemaps).toEqual(['https://example.com/a.xml'])
})

it('matches rules and paths in one canonical encoding, so an escape cannot slip past a rule', () => {
const robots = parseRobots(
['User-agent: *', 'Disallow: /private', 'Disallow: /café'].join('\n')
)
expect(robots.allows('/%70rivate/salaries')).toBe(false)
expect(robots.allows('/caf%C3%A9/menu')).toBe(false)
expect(robots.allows('/a%2Fprivate')).toBe(true)
})

it('matches a pathological wildcard rule against a long path in linear time', () => {
const robots = parseRobots(`User-agent: *\nDisallow: /${'*a'.repeat(40)}b\n`)
const started = performance.now()
expect(robots.allows(`/${'a'.repeat(20_000)}`)).toBe(true)
expect(performance.now() - started).toBeLessThan(1000)
})

it('reads records separated by carriage returns alone', () => {
expect(parseRobots('User-agent: *\rDisallow: /\r').allows('/anything')).toBe(false)
})

it('refuses a policy with more rules than it evaluates rather than dropping some', () => {
const rules = Array.from({ length: 1001 }, (_, index) => `Disallow: /p${index}`)
expect(() => parseRobots(['User-agent: *', ...rules].join('\n'))).toThrow('more than')
})
})
Loading
Loading