chore: import upstream snapshot with attribution
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
import type {
|
||||
SimilarwebBounceRateParams,
|
||||
SimilarwebBounceRateResponse,
|
||||
} from '@/tools/similarweb/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const similarwebBounceRateTool: ToolConfig<
|
||||
SimilarwebBounceRateParams,
|
||||
SimilarwebBounceRateResponse
|
||||
> = {
|
||||
id: 'similarweb_bounce_rate',
|
||||
name: 'SimilarWeb Bounce Rate',
|
||||
description: 'Get website bounce rate over time (desktop and mobile combined)',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
apiKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'SimilarWeb API key',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Website domain to analyze (e.g., "example.com" without www or protocol)',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'2-letter ISO country code (e.g., "us", "gb", "de") or "world" for worldwide data',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Data granularity: daily, weekly, or monthly',
|
||||
},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Start date in YYYY-MM format (e.g., "2024-01")',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'End date in YYYY-MM format (e.g., "2024-12")',
|
||||
},
|
||||
mainDomainOnly: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Exclude subdomains from results',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const domain = params.domain
|
||||
?.trim()
|
||||
.replace(/^(https?:\/\/)?(www\.)?/, '')
|
||||
.replace(/\/$/, '')
|
||||
const url = new URL(
|
||||
`https://api.similarweb.com/v1/website/${domain}/total-traffic-and-engagement/bounce-rate`
|
||||
)
|
||||
url.searchParams.set('api_key', params.apiKey?.trim())
|
||||
url.searchParams.set('country', params.country?.trim() ?? 'world')
|
||||
url.searchParams.set('granularity', params.granularity ?? 'monthly')
|
||||
url.searchParams.set('format', 'json')
|
||||
if (params.startDate) url.searchParams.set('start_date', params.startDate)
|
||||
if (params.endDate) url.searchParams.set('end_date', params.endDate)
|
||||
if (params.mainDomainOnly !== undefined)
|
||||
url.searchParams.set('main_domain_only', String(params.mainDomainOnly))
|
||||
return url.toString()
|
||||
},
|
||||
method: 'GET',
|
||||
headers: () => ({
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error?.message || data.message || 'Failed to get bounce rate')
|
||||
}
|
||||
|
||||
const meta = data.meta ?? {}
|
||||
const request = meta.request ?? {}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
domain: request.domain ?? null,
|
||||
country: request.country ?? null,
|
||||
granularity: request.granularity ?? null,
|
||||
lastUpdated: meta.last_updated ?? null,
|
||||
bounceRate:
|
||||
data.bounce_rate?.map((b: { date: string; bounce_rate: number }) => ({
|
||||
date: b.date,
|
||||
bounceRate: b.bounce_rate,
|
||||
})) ?? [],
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
domain: {
|
||||
type: 'string',
|
||||
description: 'Analyzed domain',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
description: 'Country filter applied',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
description: 'Data granularity',
|
||||
},
|
||||
lastUpdated: {
|
||||
type: 'string',
|
||||
description: 'Data last updated timestamp',
|
||||
optional: true,
|
||||
},
|
||||
bounceRate: {
|
||||
type: 'array',
|
||||
description: 'Bounce rate data over time',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
date: { type: 'string', description: 'Date (YYYY-MM-DD)' },
|
||||
bounceRate: { type: 'number', description: 'Bounce rate (0-1)' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export { similarwebBounceRateTool } from './bounce_rate'
|
||||
export { similarwebPageViewsTool } from './page_views'
|
||||
export { similarwebPagesPerVisitTool } from './pages_per_visit'
|
||||
export { similarwebTrafficVisitsTool } from './traffic_visits'
|
||||
export * from './types'
|
||||
export { similarwebVisitDurationTool } from './visit_duration'
|
||||
export { similarwebWebsiteOverviewTool } from './website_overview'
|
||||
@@ -0,0 +1,148 @@
|
||||
import type {
|
||||
SimilarwebPageViewsParams,
|
||||
SimilarwebPageViewsResponse,
|
||||
} from '@/tools/similarweb/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const similarwebPageViewsTool: ToolConfig<
|
||||
SimilarwebPageViewsParams,
|
||||
SimilarwebPageViewsResponse
|
||||
> = {
|
||||
id: 'similarweb_page_views',
|
||||
name: 'SimilarWeb Page Views',
|
||||
description: 'Get total page views over time (desktop and mobile combined)',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
apiKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'SimilarWeb API key',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Website domain to analyze (e.g., "example.com" without www or protocol)',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'2-letter ISO country code (e.g., "us", "gb", "de") or "world" for worldwide data',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Data granularity: daily, weekly, or monthly',
|
||||
},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Start date in YYYY-MM format (e.g., "2024-01")',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'End date in YYYY-MM format (e.g., "2024-12")',
|
||||
},
|
||||
mainDomainOnly: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Exclude subdomains from results',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const domain = params.domain
|
||||
?.trim()
|
||||
.replace(/^(https?:\/\/)?(www\.)?/, '')
|
||||
.replace(/\/$/, '')
|
||||
const url = new URL(
|
||||
`https://api.similarweb.com/v1/website/${domain}/total-traffic-and-engagement/page-views`
|
||||
)
|
||||
url.searchParams.set('api_key', params.apiKey?.trim())
|
||||
url.searchParams.set('country', params.country?.trim() ?? 'world')
|
||||
url.searchParams.set('granularity', params.granularity ?? 'monthly')
|
||||
url.searchParams.set('format', 'json')
|
||||
if (params.startDate) url.searchParams.set('start_date', params.startDate)
|
||||
if (params.endDate) url.searchParams.set('end_date', params.endDate)
|
||||
if (params.mainDomainOnly !== undefined)
|
||||
url.searchParams.set('main_domain_only', String(params.mainDomainOnly))
|
||||
return url.toString()
|
||||
},
|
||||
method: 'GET',
|
||||
headers: () => ({
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error?.message || data.message || 'Failed to get page views')
|
||||
}
|
||||
|
||||
const meta = data.meta ?? {}
|
||||
const request = meta.request ?? {}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
domain: request.domain ?? null,
|
||||
country: request.country ?? null,
|
||||
granularity: request.granularity ?? null,
|
||||
lastUpdated: meta.last_updated ?? null,
|
||||
// SimilarWeb's own docs example response uses "pages_views" (with the extra "s") for
|
||||
// this endpoint, unlike its sibling total-traffic-and-engagement endpoints; fall back
|
||||
// to "page_views" too in case that spelling changes or varies by account.
|
||||
pageViews:
|
||||
(data.pages_views ?? data.page_views)?.map(
|
||||
(p: { date: string; pages_views?: number; page_views?: number }) => ({
|
||||
date: p.date,
|
||||
pageViews: p.pages_views ?? p.page_views ?? 0,
|
||||
})
|
||||
) ?? [],
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
domain: {
|
||||
type: 'string',
|
||||
description: 'Analyzed domain',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
description: 'Country filter applied',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
description: 'Data granularity',
|
||||
},
|
||||
lastUpdated: {
|
||||
type: 'string',
|
||||
description: 'Data last updated timestamp',
|
||||
optional: true,
|
||||
},
|
||||
pageViews: {
|
||||
type: 'array',
|
||||
description: 'Page view data over time',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
date: { type: 'string', description: 'Date (YYYY-MM-DD)' },
|
||||
pageViews: { type: 'number', description: 'Total page views' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import type {
|
||||
SimilarwebPagesPerVisitParams,
|
||||
SimilarwebPagesPerVisitResponse,
|
||||
} from '@/tools/similarweb/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const similarwebPagesPerVisitTool: ToolConfig<
|
||||
SimilarwebPagesPerVisitParams,
|
||||
SimilarwebPagesPerVisitResponse
|
||||
> = {
|
||||
id: 'similarweb_pages_per_visit',
|
||||
name: 'SimilarWeb Pages Per Visit',
|
||||
description: 'Get average pages per visit over time (desktop and mobile combined)',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
apiKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'SimilarWeb API key',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Website domain to analyze (e.g., "example.com" without www or protocol)',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'2-letter ISO country code (e.g., "us", "gb", "de") or "world" for worldwide data',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Data granularity: daily, weekly, or monthly',
|
||||
},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Start date in YYYY-MM format (e.g., "2024-01")',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'End date in YYYY-MM format (e.g., "2024-12")',
|
||||
},
|
||||
mainDomainOnly: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Exclude subdomains from results',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const domain = params.domain
|
||||
?.trim()
|
||||
.replace(/^(https?:\/\/)?(www\.)?/, '')
|
||||
.replace(/\/$/, '')
|
||||
const url = new URL(
|
||||
`https://api.similarweb.com/v1/website/${domain}/total-traffic-and-engagement/pages-per-visit`
|
||||
)
|
||||
url.searchParams.set('api_key', params.apiKey?.trim())
|
||||
url.searchParams.set('country', params.country?.trim() ?? 'world')
|
||||
url.searchParams.set('granularity', params.granularity ?? 'monthly')
|
||||
url.searchParams.set('format', 'json')
|
||||
if (params.startDate) url.searchParams.set('start_date', params.startDate)
|
||||
if (params.endDate) url.searchParams.set('end_date', params.endDate)
|
||||
if (params.mainDomainOnly !== undefined)
|
||||
url.searchParams.set('main_domain_only', String(params.mainDomainOnly))
|
||||
return url.toString()
|
||||
},
|
||||
method: 'GET',
|
||||
headers: () => ({
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error?.message || data.message || 'Failed to get pages per visit')
|
||||
}
|
||||
|
||||
const meta = data.meta ?? {}
|
||||
const request = meta.request ?? {}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
domain: request.domain ?? null,
|
||||
country: request.country ?? null,
|
||||
granularity: request.granularity ?? null,
|
||||
lastUpdated: meta.last_updated ?? null,
|
||||
pagesPerVisit:
|
||||
data.pages_per_visit?.map((p: { date: string; pages_per_visit: number }) => ({
|
||||
date: p.date,
|
||||
pagesPerVisit: p.pages_per_visit,
|
||||
})) ?? [],
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
domain: {
|
||||
type: 'string',
|
||||
description: 'Analyzed domain',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
description: 'Country filter applied',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
description: 'Data granularity',
|
||||
},
|
||||
lastUpdated: {
|
||||
type: 'string',
|
||||
description: 'Data last updated timestamp',
|
||||
optional: true,
|
||||
},
|
||||
pagesPerVisit: {
|
||||
type: 'array',
|
||||
description: 'Pages per visit data over time',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
date: { type: 'string', description: 'Date (YYYY-MM-DD)' },
|
||||
pagesPerVisit: { type: 'number', description: 'Average pages per visit' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import type {
|
||||
SimilarwebTrafficVisitsParams,
|
||||
SimilarwebTrafficVisitsResponse,
|
||||
} from '@/tools/similarweb/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const similarwebTrafficVisitsTool: ToolConfig<
|
||||
SimilarwebTrafficVisitsParams,
|
||||
SimilarwebTrafficVisitsResponse
|
||||
> = {
|
||||
id: 'similarweb_traffic_visits',
|
||||
name: 'SimilarWeb Traffic Visits',
|
||||
description: 'Get total website visits over time (desktop and mobile combined)',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
apiKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'SimilarWeb API key',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Website domain to analyze (e.g., "example.com" without www or protocol)',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'2-letter ISO country code (e.g., "us", "gb", "de") or "world" for worldwide data',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Data granularity: daily, weekly, or monthly',
|
||||
},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Start date in YYYY-MM format (e.g., "2024-01")',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'End date in YYYY-MM format (e.g., "2024-12")',
|
||||
},
|
||||
mainDomainOnly: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Exclude subdomains from results',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const domain = params.domain
|
||||
?.trim()
|
||||
.replace(/^(https?:\/\/)?(www\.)?/, '')
|
||||
.replace(/\/$/, '')
|
||||
const url = new URL(
|
||||
`https://api.similarweb.com/v1/website/${domain}/total-traffic-and-engagement/visits`
|
||||
)
|
||||
url.searchParams.set('api_key', params.apiKey?.trim())
|
||||
url.searchParams.set('country', params.country?.trim() ?? 'world')
|
||||
url.searchParams.set('granularity', params.granularity ?? 'monthly')
|
||||
url.searchParams.set('format', 'json')
|
||||
if (params.startDate) url.searchParams.set('start_date', params.startDate)
|
||||
if (params.endDate) url.searchParams.set('end_date', params.endDate)
|
||||
if (params.mainDomainOnly !== undefined)
|
||||
url.searchParams.set('main_domain_only', String(params.mainDomainOnly))
|
||||
return url.toString()
|
||||
},
|
||||
method: 'GET',
|
||||
headers: () => ({
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error?.message || data.message || 'Failed to get traffic visits')
|
||||
}
|
||||
|
||||
const meta = data.meta ?? {}
|
||||
const request = meta.request ?? {}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
domain: request.domain ?? null,
|
||||
country: request.country ?? null,
|
||||
granularity: request.granularity ?? null,
|
||||
lastUpdated: meta.last_updated ?? null,
|
||||
visits:
|
||||
data.visits?.map((v: { date: string; visits: number }) => ({
|
||||
date: v.date,
|
||||
visits: v.visits,
|
||||
})) ?? [],
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
domain: {
|
||||
type: 'string',
|
||||
description: 'Analyzed domain',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
description: 'Country filter applied',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
description: 'Data granularity',
|
||||
},
|
||||
lastUpdated: {
|
||||
type: 'string',
|
||||
description: 'Data last updated timestamp',
|
||||
optional: true,
|
||||
},
|
||||
visits: {
|
||||
type: 'array',
|
||||
description: 'Visit data over time',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
date: { type: 'string', description: 'Date (YYYY-MM-DD)' },
|
||||
visits: { type: 'number', description: 'Number of visits' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
import type { ToolResponse } from '@/tools/types'
|
||||
|
||||
/**
|
||||
* Common parameters for all SimilarWeb API endpoints
|
||||
*/
|
||||
interface SimilarwebBaseParams {
|
||||
apiKey: string
|
||||
domain: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for time-series endpoints (visits, bounce rate, etc.)
|
||||
*/
|
||||
interface SimilarwebTimeSeriesParams extends SimilarwebBaseParams {
|
||||
country: string
|
||||
granularity: 'daily' | 'weekly' | 'monthly'
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
mainDomainOnly?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Website Overview (API Lite) parameters
|
||||
*/
|
||||
export interface SimilarwebWebsiteOverviewParams extends SimilarwebBaseParams {}
|
||||
|
||||
/**
|
||||
* Website Overview response
|
||||
*/
|
||||
export interface SimilarwebWebsiteOverviewResponse extends ToolResponse {
|
||||
output: {
|
||||
siteName: string
|
||||
description: string | null
|
||||
globalRank: number | null
|
||||
countryRank: number | null
|
||||
categoryRank: number | null
|
||||
category: string | null
|
||||
monthlyVisits: number | null
|
||||
engagementVisitDuration: number | null
|
||||
engagementPagesPerVisit: number | null
|
||||
engagementBounceRate: number | null
|
||||
topCountries: Array<{
|
||||
country: string
|
||||
share: number
|
||||
}>
|
||||
trafficSources: {
|
||||
direct: number | null
|
||||
referrals: number | null
|
||||
search: number | null
|
||||
social: number | null
|
||||
mail: number | null
|
||||
paidReferrals: number | null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Traffic Visits parameters
|
||||
*/
|
||||
export interface SimilarwebTrafficVisitsParams extends SimilarwebTimeSeriesParams {}
|
||||
|
||||
/**
|
||||
* Traffic Visits response
|
||||
*/
|
||||
export interface SimilarwebTrafficVisitsResponse extends ToolResponse {
|
||||
output: {
|
||||
domain: string
|
||||
country: string
|
||||
granularity: string
|
||||
lastUpdated: string | null
|
||||
visits: Array<{
|
||||
date: string
|
||||
visits: number
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bounce Rate parameters
|
||||
*/
|
||||
export interface SimilarwebBounceRateParams extends SimilarwebTimeSeriesParams {}
|
||||
|
||||
/**
|
||||
* Bounce Rate response
|
||||
*/
|
||||
export interface SimilarwebBounceRateResponse extends ToolResponse {
|
||||
output: {
|
||||
domain: string
|
||||
country: string
|
||||
granularity: string
|
||||
lastUpdated: string | null
|
||||
bounceRate: Array<{
|
||||
date: string
|
||||
bounceRate: number
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pages Per Visit parameters
|
||||
*/
|
||||
export interface SimilarwebPagesPerVisitParams extends SimilarwebTimeSeriesParams {}
|
||||
|
||||
/**
|
||||
* Pages Per Visit response
|
||||
*/
|
||||
export interface SimilarwebPagesPerVisitResponse extends ToolResponse {
|
||||
output: {
|
||||
domain: string
|
||||
country: string
|
||||
granularity: string
|
||||
lastUpdated: string | null
|
||||
pagesPerVisit: Array<{
|
||||
date: string
|
||||
pagesPerVisit: number
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Page Views parameters
|
||||
*/
|
||||
export interface SimilarwebPageViewsParams extends SimilarwebTimeSeriesParams {}
|
||||
|
||||
/**
|
||||
* Page Views response
|
||||
*/
|
||||
export interface SimilarwebPageViewsResponse extends ToolResponse {
|
||||
output: {
|
||||
domain: string
|
||||
country: string
|
||||
granularity: string
|
||||
lastUpdated: string | null
|
||||
pageViews: Array<{
|
||||
date: string
|
||||
pageViews: number
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Average Visit Duration parameters
|
||||
*/
|
||||
export interface SimilarwebVisitDurationParams extends SimilarwebTimeSeriesParams {}
|
||||
|
||||
/**
|
||||
* Average Visit Duration response
|
||||
*/
|
||||
export interface SimilarwebVisitDurationResponse extends ToolResponse {
|
||||
output: {
|
||||
domain: string
|
||||
country: string
|
||||
granularity: string
|
||||
lastUpdated: string | null
|
||||
averageVisitDuration: Array<{
|
||||
date: string
|
||||
durationSeconds: number
|
||||
}>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
import type {
|
||||
SimilarwebVisitDurationParams,
|
||||
SimilarwebVisitDurationResponse,
|
||||
} from '@/tools/similarweb/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const similarwebVisitDurationTool: ToolConfig<
|
||||
SimilarwebVisitDurationParams,
|
||||
SimilarwebVisitDurationResponse
|
||||
> = {
|
||||
id: 'similarweb_visit_duration',
|
||||
name: 'SimilarWeb Visit Duration',
|
||||
description: 'Get average desktop visit duration over time (in seconds)',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
apiKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'SimilarWeb API key',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Website domain to analyze (e.g., "example.com" without www or protocol)',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'2-letter ISO country code (e.g., "us", "gb", "de") or "world" for worldwide data',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Data granularity: daily, weekly, or monthly',
|
||||
},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Start date in YYYY-MM format (e.g., "2024-01")',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'End date in YYYY-MM format (e.g., "2024-12")',
|
||||
},
|
||||
mainDomainOnly: {
|
||||
type: 'boolean',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Exclude subdomains from results',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const domain = params.domain
|
||||
?.trim()
|
||||
.replace(/^(https?:\/\/)?(www\.)?/, '')
|
||||
.replace(/\/$/, '')
|
||||
const url = new URL(
|
||||
`https://api.similarweb.com/v1/website/${domain}/traffic-and-engagement/average-visit-duration`
|
||||
)
|
||||
url.searchParams.set('api_key', params.apiKey?.trim())
|
||||
url.searchParams.set('country', params.country?.trim() ?? 'world')
|
||||
url.searchParams.set('granularity', params.granularity ?? 'monthly')
|
||||
url.searchParams.set('format', 'json')
|
||||
if (params.startDate) url.searchParams.set('start_date', params.startDate)
|
||||
if (params.endDate) url.searchParams.set('end_date', params.endDate)
|
||||
if (params.mainDomainOnly !== undefined)
|
||||
url.searchParams.set('main_domain_only', String(params.mainDomainOnly))
|
||||
return url.toString()
|
||||
},
|
||||
method: 'GET',
|
||||
headers: () => ({
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error?.message || data.message || 'Failed to get visit duration')
|
||||
}
|
||||
|
||||
const meta = data.meta ?? {}
|
||||
const request = meta.request ?? {}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
domain: request.domain ?? null,
|
||||
country: request.country ?? null,
|
||||
granularity: request.granularity ?? null,
|
||||
lastUpdated: meta.last_updated ?? null,
|
||||
averageVisitDuration:
|
||||
data.average_visit_duration?.map(
|
||||
(d: { date: string; average_visit_duration: number }) => ({
|
||||
date: d.date,
|
||||
durationSeconds: d.average_visit_duration,
|
||||
})
|
||||
) ?? [],
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
domain: {
|
||||
type: 'string',
|
||||
description: 'Analyzed domain',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
description: 'Country filter applied',
|
||||
},
|
||||
granularity: {
|
||||
type: 'string',
|
||||
description: 'Data granularity',
|
||||
},
|
||||
lastUpdated: {
|
||||
type: 'string',
|
||||
description: 'Data last updated timestamp',
|
||||
optional: true,
|
||||
},
|
||||
averageVisitDuration: {
|
||||
type: 'array',
|
||||
description: 'Desktop visit duration data over time',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
date: { type: 'string', description: 'Date (YYYY-MM-DD)' },
|
||||
durationSeconds: { type: 'number', description: 'Average visit duration in seconds' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
import type {
|
||||
SimilarwebWebsiteOverviewParams,
|
||||
SimilarwebWebsiteOverviewResponse,
|
||||
} from '@/tools/similarweb/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const similarwebWebsiteOverviewTool: ToolConfig<
|
||||
SimilarwebWebsiteOverviewParams,
|
||||
SimilarwebWebsiteOverviewResponse
|
||||
> = {
|
||||
id: 'similarweb_website_overview',
|
||||
name: 'SimilarWeb Website Overview',
|
||||
description:
|
||||
'Get comprehensive website analytics including traffic, rankings, engagement, and traffic sources',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
apiKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'SimilarWeb API key',
|
||||
},
|
||||
domain: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Website domain to analyze (e.g., "example.com" without www or protocol)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: (params) => {
|
||||
const domain = params.domain
|
||||
?.trim()
|
||||
.replace(/^(https?:\/\/)?(www\.)?/, '')
|
||||
.replace(/\/$/, '')
|
||||
const url = new URL(`https://api.similarweb.com/v1/website/${domain}/general-data/all`)
|
||||
url.searchParams.set('api_key', params.apiKey?.trim())
|
||||
url.searchParams.set('format', 'json')
|
||||
return url.toString()
|
||||
},
|
||||
method: 'GET',
|
||||
headers: () => ({
|
||||
Accept: 'application/json',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response) => {
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error?.message || data.message || 'Failed to get website overview')
|
||||
}
|
||||
|
||||
const topCountriesRaw = data.TopCountryShares ?? data.top_country_shares ?? []
|
||||
const topCountries = topCountriesRaw.map(
|
||||
(c: {
|
||||
Country?: number
|
||||
CountryCode?: string
|
||||
Value?: number
|
||||
country?: number
|
||||
country_code?: string
|
||||
value?: number
|
||||
}) => ({
|
||||
country: c.CountryCode ?? c.country_code ?? String(c.Country ?? c.country ?? ''),
|
||||
share: c.Value ?? c.value ?? 0,
|
||||
})
|
||||
)
|
||||
|
||||
const sources = data.TrafficSources ?? data.traffic_sources ?? {}
|
||||
|
||||
const engagements = data.Engagements ?? data.engagements ?? data.engagments ?? {}
|
||||
|
||||
const getGlobalRank = () => {
|
||||
if (data.GlobalRank?.Rank !== undefined) return data.GlobalRank.Rank
|
||||
if (data.global_rank?.rank !== undefined) return data.global_rank.rank
|
||||
if (typeof data.GlobalRank === 'number') return data.GlobalRank
|
||||
if (typeof data.global_rank === 'number') return data.global_rank
|
||||
return null
|
||||
}
|
||||
|
||||
const getCountryRank = () => {
|
||||
if (data.CountryRank?.Rank !== undefined) return data.CountryRank.Rank
|
||||
if (data.country_rank?.rank !== undefined) return data.country_rank.rank
|
||||
if (typeof data.CountryRank === 'number') return data.CountryRank
|
||||
if (typeof data.country_rank === 'number') return data.country_rank
|
||||
return null
|
||||
}
|
||||
|
||||
const getCategoryRank = () => {
|
||||
if (data.CategoryRank?.Rank !== undefined) return data.CategoryRank.Rank
|
||||
if (data.category_rank?.rank !== undefined) return data.category_rank.rank
|
||||
if (typeof data.CategoryRank === 'number') return data.CategoryRank
|
||||
if (typeof data.category_rank === 'number') return data.category_rank
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
siteName: data.SiteName ?? data.site_name ?? null,
|
||||
description: data.Description ?? data.description ?? null,
|
||||
globalRank: getGlobalRank(),
|
||||
countryRank: getCountryRank(),
|
||||
categoryRank: getCategoryRank(),
|
||||
category: data.Category ?? data.category ?? null,
|
||||
monthlyVisits: engagements.Visits ?? engagements.visits ?? null,
|
||||
engagementVisitDuration: engagements.TimeOnSite ?? engagements.time_on_site ?? null,
|
||||
engagementPagesPerVisit: engagements.PagePerVisit ?? engagements.page_per_visit ?? null,
|
||||
engagementBounceRate: engagements.BounceRate ?? engagements.bounce_rate ?? null,
|
||||
topCountries,
|
||||
trafficSources: {
|
||||
direct: sources.Direct ?? sources.direct ?? null,
|
||||
referrals: sources.Referrals ?? sources.referrals ?? null,
|
||||
search: sources.Search ?? sources.search ?? null,
|
||||
social: sources.Social ?? sources.social ?? null,
|
||||
mail: sources.Mail ?? sources.mail ?? null,
|
||||
paidReferrals:
|
||||
sources['Paid Referrals'] ??
|
||||
// SimilarWeb's API Lite response literally uses "paid _referrals" (space before
|
||||
// the underscore) as the key for this field.
|
||||
sources['paid _referrals'] ??
|
||||
sources.paid_referrals ??
|
||||
null,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
siteName: {
|
||||
type: 'string',
|
||||
description: 'Website name',
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
description: 'Website description',
|
||||
optional: true,
|
||||
},
|
||||
globalRank: {
|
||||
type: 'number',
|
||||
description: 'Global traffic rank',
|
||||
optional: true,
|
||||
},
|
||||
countryRank: {
|
||||
type: 'number',
|
||||
description: 'Country traffic rank',
|
||||
optional: true,
|
||||
},
|
||||
categoryRank: {
|
||||
type: 'number',
|
||||
description: 'Category traffic rank',
|
||||
optional: true,
|
||||
},
|
||||
category: {
|
||||
type: 'string',
|
||||
description: 'Website category',
|
||||
optional: true,
|
||||
},
|
||||
monthlyVisits: {
|
||||
type: 'number',
|
||||
description: 'Estimated monthly visits',
|
||||
optional: true,
|
||||
},
|
||||
engagementVisitDuration: {
|
||||
type: 'number',
|
||||
description: 'Average visit duration in seconds',
|
||||
optional: true,
|
||||
},
|
||||
engagementPagesPerVisit: {
|
||||
type: 'number',
|
||||
description: 'Average pages per visit',
|
||||
optional: true,
|
||||
},
|
||||
engagementBounceRate: {
|
||||
type: 'number',
|
||||
description: 'Bounce rate (0-1)',
|
||||
optional: true,
|
||||
},
|
||||
topCountries: {
|
||||
type: 'array',
|
||||
description: 'Top countries by traffic share',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
country: { type: 'string', description: 'Country code' },
|
||||
share: { type: 'number', description: 'Traffic share (0-1)' },
|
||||
},
|
||||
},
|
||||
},
|
||||
trafficSources: {
|
||||
type: 'json',
|
||||
description: 'Traffic source breakdown',
|
||||
properties: {
|
||||
direct: { type: 'number', description: 'Direct traffic share' },
|
||||
referrals: { type: 'number', description: 'Referral traffic share' },
|
||||
search: { type: 'number', description: 'Search traffic share' },
|
||||
social: { type: 'number', description: 'Social traffic share' },
|
||||
mail: { type: 'number', description: 'Email traffic share' },
|
||||
paidReferrals: { type: 'number', description: 'Paid referral traffic share' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user