import React from 'react'; import { useCopilotActionTyped, useExecute, getDefaultUrl } from './helpers'; import { seoApiService } from '../../../services/seoApiService'; const TechnicalUI: React.FC<{ args: any; respond: (data: any) => void }> = ({ args, respond }) => { const [scope, setScope] = React.useState(args?.scope || 'full'); const [isRunning, setIsRunning] = React.useState(false); const [result, setResult] = React.useState(null); const [error, setError] = React.useState(null); const url = args?.url || getDefaultUrl(); const run = async () => { try { setIsRunning(true); setError(null); if (!url) throw new Error('No URL available'); const flags = scope === 'full' ? { analyze_core_web_vitals: true, analyze_mobile_friendliness: true, analyze_security: true } : { analyze_core_web_vitals: scope === 'core_web_vitals', analyze_mobile_friendliness: scope === 'mobile_friendliness', analyze_security: scope === 'security' }; const res = await seoApiService.analyzeTechnicalSEO({ url, ...flags }); setResult(res); respond({ success: true, url, scope, result: res }); } catch (e: any) { setError(e?.message || 'Failed to run technical SEO audit'); } finally { setIsRunning(false); } }; return (
Technical SEO audit
URL: {url || 'Not available'}
{['full', 'core_web_vitals', 'mobile_friendliness', 'security'].map((s) => ( ))}
{error &&
{error}
} {result && (
{JSON.stringify(result, null, 2)}
)}
); }; const RegisterTechnical: React.FC = () => { const execute = useExecute(); const useAction = useCopilotActionTyped(); useAction({ name: 'analyzeTechnicalSEO', description: 'Perform technical SEO audit and provide technical recommendations', parameters: [ { name: 'url', type: 'string', description: 'URL to analyze (optional)', required: false }, { name: 'scope', type: 'string', description: 'full | core_web_vitals | mobile_friendliness | security', required: false } ], renderAndWaitForResponse: ({ args, respond }: any) => , handler: async (args: any) => { const url = args?.url || getDefaultUrl(); const scope = args?.scope || 'full'; const flags = scope === 'full' ? { analyze_core_web_vitals: true, analyze_mobile_friendliness: true, analyze_security: true } : { analyze_core_web_vitals: scope === 'core_web_vitals', analyze_mobile_friendliness: scope === 'mobile_friendliness', analyze_security: scope === 'security' }; return await execute('analyzeTechnicalSEO', { ...args, url, ...flags }); } }); return null; }; export default RegisterTechnical;