Files
simstudioai--sim/apps/sim/tools/ahrefs/site_audit_page_explorer.ts
T
wehub-resource-sync d25d482dc2
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
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

143 lines
4.4 KiB
TypeScript

import type {
AhrefsSiteAuditPageExplorerParams,
AhrefsSiteAuditPageExplorerResponse,
} from '@/tools/ahrefs/types'
import type { ToolConfig } from '@/tools/types'
const SELECT_FIELDS =
'url,http_code,title,internal_links,external_links,backlinks,compliant,traffic'
export const siteAuditPageExplorerTool: ToolConfig<
AhrefsSiteAuditPageExplorerParams,
AhrefsSiteAuditPageExplorerResponse
> = {
id: 'ahrefs_site_audit_page_explorer',
name: 'Ahrefs Site Audit Page Explorer',
description:
'Get crawled pages from an Ahrefs Site Audit project with health and SEO metrics: HTTP status, title, link counts, backlinks, indexability, and traffic. Optionally filter to pages affected by a specific issue.',
version: '1.0.0',
params: {
projectId: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'The Site Audit project ID (found in the project URL in Ahrefs)',
},
date: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Crawl date in YYYY-MM-DDThh:mm:ss format (defaults to the most recent crawl)',
},
limit: {
type: 'number',
required: false,
visibility: 'user-or-llm',
description: 'Maximum number of results to return. Example: 50 (default: 1000)',
},
offset: {
type: 'number',
required: false,
visibility: 'user-or-llm',
description: 'Number of results to skip, for pagination',
},
issueId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Only return pages affected by this issue ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Ahrefs API Key',
},
},
request: {
url: (params) => {
const url = new URL('https://api.ahrefs.com/v3/site-audit/page-explorer')
url.searchParams.set('project_id', String(params.projectId))
url.searchParams.set('select', SELECT_FIELDS)
if (params.date) url.searchParams.set('date', params.date)
if (params.limit) url.searchParams.set('limit', String(params.limit))
if (params.offset) url.searchParams.set('offset', String(params.offset))
if (params.issueId) url.searchParams.set('issue_id', params.issueId)
return url.toString()
},
method: 'GET',
headers: (params) => ({
Accept: 'application/json',
Authorization: `Bearer ${params.apiKey}`,
}),
},
transformResponse: async (response: Response) => {
const data = await response.json()
if (!response.ok) {
throw new Error(data.error?.message || data.error || 'Failed to get site audit pages')
}
const auditPages = (data.pages || []).map((page: any) => ({
url: page.url || '',
httpCode: page.http_code ?? null,
title: page.title ?? [],
internalLinks: (page.internal_links || []).length,
externalLinks: (page.external_links || []).length,
backlinks: page.backlinks ?? null,
compliant: page.compliant ?? null,
traffic: page.traffic ?? null,
}))
return {
success: true,
output: {
auditPages,
},
}
},
outputs: {
auditPages: {
type: 'array',
description: 'List of crawled pages with health and SEO metrics',
items: {
type: 'object',
properties: {
url: { type: 'string', description: 'The crawled page URL' },
httpCode: {
type: 'number',
description: 'HTTP status code returned by the URL',
optional: true,
},
title: {
type: 'array',
description: 'Page title tag(s)',
items: { type: 'string' },
},
internalLinks: { type: 'number', description: 'Number of internal outgoing links' },
externalLinks: { type: 'number', description: 'Number of external outgoing links' },
backlinks: {
type: 'number',
description: 'Number of incoming external links to the page',
optional: true,
},
compliant: {
type: 'boolean',
description: 'Whether the page is indexable (200 status, no canonical/noindex)',
optional: true,
},
traffic: {
type: 'number',
description: 'Estimated monthly organic traffic to the page',
optional: true,
},
},
},
},
},
}