Advanced Content Hyper-Personalization Implementation
This commit is contained in:
@@ -5,6 +5,8 @@ import { useCopilotReadable, useCopilotAction } from '@copilotkit/react-core';
|
||||
import '@copilotkit/react-ui/styles.css';
|
||||
import RegisterFacebookActions from './RegisterFacebookActions';
|
||||
import RegisterFacebookEditActions from './RegisterFacebookEditActions';
|
||||
import RegisterFacebookActionsEnhanced from './RegisterFacebookActionsEnhanced';
|
||||
import { PlatformPersonaProvider, usePlatformPersonaContext } from '../shared/PersonaContext/PlatformPersonaProvider';
|
||||
|
||||
const useCopilotActionTyped = useCopilotAction as any;
|
||||
|
||||
@@ -125,7 +127,21 @@ function simpleMarkdownToHtml(markdown: string): string {
|
||||
return html;
|
||||
}
|
||||
|
||||
const FacebookWriter: React.FC = () => {
|
||||
interface FacebookWriterProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// Enhanced Facebook Writer with Persona Integration
|
||||
const FacebookWriter: React.FC<FacebookWriterProps> = ({ className = '' }) => {
|
||||
return (
|
||||
<PlatformPersonaProvider platform="facebook">
|
||||
<FacebookWriterContent className={className} />
|
||||
</PlatformPersonaProvider>
|
||||
);
|
||||
};
|
||||
|
||||
// Main Facebook Writer Content Component
|
||||
const FacebookWriterContent: React.FC<FacebookWriterProps> = ({ className = '' }) => {
|
||||
const [postDraft, setPostDraft] = React.useState<string>('');
|
||||
const [notes, setNotes] = React.useState<string>('');
|
||||
const [stage, setStage] = React.useState<'start' | 'edit'>('start');
|
||||
@@ -143,6 +159,9 @@ const FacebookWriter: React.FC = () => {
|
||||
const renderRef = React.useRef<HTMLDivElement | null>(null);
|
||||
const [selectionMenu, setSelectionMenu] = React.useState<{ x: number; y: number; text: string } | null>(null);
|
||||
|
||||
// Get persona context for enhanced AI assistance
|
||||
const { corePersona, platformPersona, loading: personaLoading } = usePlatformPersonaContext();
|
||||
|
||||
React.useEffect(() => {
|
||||
const onUpdate = (e: any) => {
|
||||
setPostDraft(String(e.detail || ''));
|
||||
@@ -282,7 +301,9 @@ const FacebookWriter: React.FC = () => {
|
||||
className="alwrity-copilot-sidebar"
|
||||
labels={{
|
||||
title: 'ALwrity • Facebook Writer',
|
||||
initial: stage === 'start' ? 'Tell me what you want to post. I can draft, refine, and generate variants.' : 'Great! Try quick edits below to refine your post in real-time.'
|
||||
initial: stage === 'start' ?
|
||||
`Tell me what you want to post. I can draft, refine, and generate variants${corePersona ? ` with ${corePersona.persona_name} persona optimization` : ''}.` :
|
||||
`Great! Try quick edits below to refine your post in real-time${corePersona ? ` using your ${corePersona.persona_name} persona` : ''}.`
|
||||
}}
|
||||
suggestions={suggestions}
|
||||
makeSystemMessage={(_context: string, additional?: string) => {
|
||||
@@ -290,15 +311,66 @@ const FacebookWriter: React.FC = () => {
|
||||
const prefsLine = Object.keys(prefs).length ? `User preferences (remember and respect unless changed): ${JSON.stringify(prefs)}` : '';
|
||||
const history = summarizeHistory();
|
||||
const historyLine = history ? `Recent conversation (last 10 messages):\n${history}` : '';
|
||||
const currentDraft = postDraft ? `Current draft content:\n${postDraft}` : 'No current draft content.';
|
||||
|
||||
// Enhanced persona-aware guidance
|
||||
const personaGuidance = corePersona && platformPersona ? `
|
||||
PERSONA-AWARE WRITING GUIDANCE:
|
||||
- PERSONA: ${corePersona.persona_name} (${corePersona.archetype})
|
||||
- CORE BELIEF: ${corePersona.core_belief}
|
||||
- CONFIDENCE SCORE: ${corePersona.confidence_score}%
|
||||
- LINGUISTIC STYLE: ${corePersona.linguistic_fingerprint?.sentence_metrics?.average_sentence_length_words || 'Unknown'} words average, ${corePersona.linguistic_fingerprint?.sentence_metrics?.active_to_passive_ratio || 'Unknown'} active/passive ratio
|
||||
- GO-TO WORDS: ${corePersona.linguistic_fingerprint?.lexical_features?.go_to_words?.join(', ') || 'None specified'}
|
||||
- AVOID WORDS: ${corePersona.linguistic_fingerprint?.lexical_features?.avoid_words?.join(', ') || 'None specified'}
|
||||
|
||||
PLATFORM OPTIMIZATION (Facebook):
|
||||
- CHARACTER LIMIT: ${platformPersona.content_format_rules?.character_limit || '63206'} characters
|
||||
- OPTIMAL LENGTH: ${platformPersona.content_format_rules?.optimal_length || '40-80 characters'}
|
||||
- ENGAGEMENT PATTERN: ${platformPersona.engagement_patterns?.posting_frequency || '1-2 times per day'}
|
||||
- HASHTAG STRATEGY: ${platformPersona.lexical_features?.hashtag_strategy || '1-2 relevant hashtags'}
|
||||
|
||||
ALWAYS generate content that matches this persona's linguistic fingerprint and platform optimization rules.` : '';
|
||||
|
||||
const guidance = `
|
||||
You are ALwrity's Facebook Writing Assistant.
|
||||
You have the following tools available; prefer them when relevant:
|
||||
- generateFacebookPost: generate a Facebook post using provided business_type, target_audience, post_goal, post_tone, include, avoid.
|
||||
- generateFacebookHashtags: generate hashtags for a given content_topic (or infer from the user's draft/context).
|
||||
- updateFacebookPostDraft / appendToFacebookPostDraft: directly update the user's on-page draft when asked to tighten, rewrite, or append.
|
||||
- editFacebookDraft: apply a quick style or structural edit (Casual, Professional, Upbeat, Shorten, Lengthen, TightenHook, AddCTA) and reflect the change live.
|
||||
Always respond concisely and take action with the most appropriate tool.`.trim();
|
||||
return [prefsLine, historyLine, guidance, additional].filter(Boolean).join('\n\n');
|
||||
You are ALwrity's Facebook Writing Assistant specializing in engaging social media content.
|
||||
|
||||
CRITICAL CONSTRAINTS:
|
||||
- TONE: Always maintain an engaging, community-focused tone
|
||||
- PLATFORM: Focus specifically on Facebook's unique characteristics and audience
|
||||
- QUALITY: Ensure all content meets Facebook's community standards
|
||||
${personaGuidance ? `\n${personaGuidance}` : ''}
|
||||
|
||||
CURRENT CONTEXT:
|
||||
${currentDraft}
|
||||
|
||||
Available Facebook content tools:
|
||||
- generateFacebookPost: Create engaging Facebook posts with persona optimization
|
||||
- generateFacebookHashtags: Generate relevant hashtags for Facebook content
|
||||
- generateFacebookAdCopy: Create conversion-focused ad copy
|
||||
- generateFacebookStory: Create Facebook Story scripts
|
||||
- generateFacebookReel: Create Facebook Reel scripts
|
||||
- generateFacebookCarousel: Create multi-slide carousel content
|
||||
- generateFacebookEvent: Create event descriptions
|
||||
- generateFacebookPageAbout: Create page about sections
|
||||
|
||||
🎭 ENHANCED PERSONA-AWARE ACTIONS (Recommended):
|
||||
- generateFacebookPostWithPersona: Create posts optimized for your writing style and platform constraints
|
||||
- validateContentAgainstPersona: Validate existing content against your persona
|
||||
- getPersonaWritingSuggestions: Get personalized writing recommendations
|
||||
|
||||
DIRECT DRAFT ACTIONS:
|
||||
- updateFacebookPostDraft: Replace the entire draft with new content
|
||||
- appendToFacebookPostDraft: Add text to the existing draft
|
||||
- editFacebookDraft: Apply quick edits (Casual, Professional, Upbeat, Shorten, Lengthen, TightenHook, AddCTA) to the current draft
|
||||
|
||||
IMPORTANT: When refining or editing content, always reference the current draft above. If the user asks to refine their post, use the current draft content as the starting point. Never ask for content that already exists in the draft.
|
||||
|
||||
For quick edits, use editFacebookDraft with the appropriate operation. This will show a live preview of changes before applying them.
|
||||
|
||||
Use user preferences, context, conversation history, and persona data to personalize all content.
|
||||
Always respect the user's preferred tone, platform focus, and writing persona style.
|
||||
Always use the most appropriate tool for the user's request.`.trim();
|
||||
return [prefsLine, historyLine, currentDraft, guidance, additional].filter(Boolean).join('\n\n');
|
||||
}}
|
||||
observabilityHooks={{
|
||||
onChatExpanded: () => console.log('[FB Writer] Sidebar opened'),
|
||||
@@ -308,6 +380,8 @@ Always respond concisely and take action with the most appropriate tool.`.trim()
|
||||
>
|
||||
<RegisterFacebookActions />
|
||||
<RegisterFacebookEditActions />
|
||||
{/* Enhanced Persona-Aware Actions */}
|
||||
<RegisterFacebookActionsEnhanced />
|
||||
<Box
|
||||
sx={{
|
||||
minHeight: '100vh',
|
||||
@@ -324,6 +398,58 @@ Always respond concisely and take action with the most appropriate tool.`.trim()
|
||||
<Typography variant="h4" sx={{ fontWeight: 800, letterSpacing: 0.3 }}>
|
||||
Facebook Writer (Preview)
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
{/* Persona Integration Indicator */}
|
||||
{corePersona && !personaLoading && (
|
||||
<div
|
||||
style={{
|
||||
padding: '8px 16px',
|
||||
backgroundColor: 'rgba(24, 119, 242, 0.1)',
|
||||
borderBottom: '1px solid rgba(24, 119, 242, 0.3)',
|
||||
fontSize: '12px',
|
||||
color: 'rgba(255, 255, 255, 0.8)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: '8px',
|
||||
cursor: 'help',
|
||||
position: 'relative',
|
||||
marginBottom: '16px',
|
||||
borderRadius: '8px',
|
||||
border: '1px solid rgba(24, 119, 242, 0.2)'
|
||||
}}
|
||||
title={`Complete Persona Details:
|
||||
|
||||
🎭 PERSONA: ${corePersona.persona_name}
|
||||
📋 ARCHETYPE: ${corePersona.archetype}
|
||||
💭 CORE BELIEF: ${corePersona.core_belief}
|
||||
📊 CONFIDENCE: ${corePersona.confidence_score}%
|
||||
|
||||
📝 LINGUISTIC FINGERPRINT:
|
||||
• Sentence Length: ${corePersona.linguistic_fingerprint?.sentence_metrics?.average_sentence_length_words || 'Unknown'} words average
|
||||
• Voice Ratio: ${corePersona.linguistic_fingerprint?.sentence_metrics?.active_to_passive_ratio || 'Unknown'}
|
||||
• Go-to Words: ${corePersona.linguistic_fingerprint?.lexical_features?.go_to_words?.join(', ') || 'None specified'}
|
||||
• Avoid Words: ${corePersona.linguistic_fingerprint?.lexical_features?.avoid_words?.join(', ') || 'None specified'}
|
||||
|
||||
🎯 PLATFORM OPTIMIZATION (Facebook):
|
||||
• Character Limit: ${platformPersona?.content_format_rules?.character_limit || '63206'} characters
|
||||
• Optimal Length: ${platformPersona?.content_format_rules?.optimal_length || '40-80 characters'}
|
||||
• Engagement Pattern: ${platformPersona?.engagement_patterns?.posting_frequency || '1-2 times per day'}
|
||||
• Hashtag Strategy: ${platformPersona?.lexical_features?.hashtag_strategy || '1-2 relevant hashtags'}
|
||||
|
||||
✨ This persona is actively optimizing your content generation and AI assistance!`}
|
||||
>
|
||||
<span style={{ color: '#1877f2' }}>🎭</span>
|
||||
<span><strong>Persona Active:</strong> {corePersona.persona_name} ({corePersona.archetype})</span>
|
||||
<span style={{ marginLeft: 'auto', fontSize: '11px' }}>
|
||||
Confidence: {corePersona.confidence_score}% |
|
||||
Platform: Facebook Optimized
|
||||
</span>
|
||||
<span style={{ fontSize: '10px', color: 'rgba(255, 255, 255, 0.6)', marginLeft: '8px' }}>
|
||||
(Hover for details)
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<Button size="small" variant="outlined" disabled sx={{ color: 'rgba(255,255,255,0.7)', borderColor: 'rgba(255,255,255,0.25)' }}>
|
||||
DashBoard
|
||||
@@ -333,7 +459,6 @@ Always respond concisely and take action with the most appropriate tool.`.trim()
|
||||
Clear chat memory
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
<Typography variant="body1" sx={{ color: 'rgba(255,255,255,0.85)', mb: 3 }}>
|
||||
{stage === 'start' ? 'Collaborate with the Copilot to craft your post. The assistant can update the draft directly.' : 'Use the edit suggestions to see real-time changes applied to your post.'}
|
||||
</Typography>
|
||||
|
||||
Reference in New Issue
Block a user