import React from 'react'; import { useCopilotAction } from '@copilotkit/react-core'; import { blogWriterApi, BlogResearchResponse, BlogOutlineSection } from '../../services/blogWriterApi'; const useCopilotActionTyped = useCopilotAction as any; interface ResearchDataActionsProps { research: BlogResearchResponse | null; onOutlineCreated: (outline: BlogOutlineSection[]) => void; onTitleOptionsSet: (titles: string[]) => void; } export const ResearchDataActions: React.FC = ({ research, onOutlineCreated, onTitleOptionsSet }) => { // Chat with Research Data useCopilotActionTyped({ name: 'chatWithResearchData', description: 'Chat with the research data to explore insights, ask questions, and get recommendations', parameters: [ { name: 'question', type: 'string', description: 'Question or topic to explore in the research data', required: true } ], handler: async ({ question }: { question: string }) => { if (!research) { return { success: false, message: 'No research data available. Please complete research first.', suggestion: 'Try asking: "I want to research a topic for my blog"' }; } // Provide comprehensive research context for the copilot to answer intelligently const researchContext = { sources: research.sources.length, primaryKeywords: research.keyword_analysis?.primary || [], secondaryKeywords: research.keyword_analysis?.secondary || [], longTailKeywords: research.keyword_analysis?.long_tail || [], searchIntent: research.keyword_analysis?.search_intent || 'informational', contentAngles: research.suggested_angles || [], competitorAnalysis: research.competitor_analysis || {}, searchQueries: research.search_queries || [], topSources: research.sources.slice(0, 5).map(s => ({ title: s.title, credibility: s.credibility_score, excerpt: s.excerpt?.substring(0, 200) })) }; return { success: true, message: `I can help you explore the research data! Here's what I found:`, research_context: researchContext, user_question: question, next_step_suggestion: 'Ready to create an outline? Try: "Create outline with custom inputs" or "Let\'s proceed to create an outline"' }; }, render: ({ status, result }: any) => { if (status === 'complete' && result?.success) { return (

🔍 Research Data Insights

Your Question: {result.user_question}

Research Summary:

  • {result.research_context.sources} authoritative sources found
  • Primary keywords: {result.research_context.primaryKeywords.join(', ')}
  • Search intent: {result.research_context.searchIntent}
  • {result.research_context.contentAngles.length} content angles identified

💡 Next Step:

{result.next_step_suggestion}

); } return null; } }); // Create Outline with Custom Inputs useCopilotActionTyped({ name: 'createOutlineWithCustomInputs', description: 'Create an outline with custom instructions and requirements from the user', parameters: [ { name: 'customInstructions', type: 'string', description: 'Custom instructions for outline generation', required: true } ], handler: async ({ customInstructions }: { customInstructions: string }) => { if (!research) { return { success: false, message: 'No research data available. Please complete research first.', suggestion: 'Try asking: "I want to research a topic for my blog"' }; } try { // Create a custom outline request with user instructions const customOutlineRequest = { research: research, word_count: 1500, custom_instructions: customInstructions }; const outlineResponse = await blogWriterApi.generateOutline(customOutlineRequest); onOutlineCreated(outlineResponse.outline); onTitleOptionsSet(outlineResponse.title_options); return { success: true, message: `Created custom outline with ${outlineResponse.outline.length} sections based on your instructions: "${customInstructions}"`, outline_sections: outlineResponse.outline.length, title_options: outlineResponse.title_options.length, next_step_suggestion: 'Great! Now you can enhance sections, generate content, or refine the outline further.' }; } catch (error) { return { success: false, message: `Custom outline creation failed: ${error}`, suggestion: 'Try providing more specific instructions or ask me to help refine your requirements.' }; } }, render: ({ status }: any) => { if (status === 'inProgress' || status === 'executing') { return (

🎨 Creating Custom Outline

• Analyzing your custom instructions...

• Applying requirements to research data...

• Generating tailored outline structure...

); } return null; } }); return null; // This component only provides the CopilotKit actions, no UI };