class FriendSupport {
constructor(chat) {
this.chat = chat;
}
async getGentleGuidance(situation) {
const query = `I'm ${situation}. Can you offer some gentle guidance and support?`;
const response = await this.chat.sendMessage(query, 'friend');
return {
support: response.text,
situation,
personality: 'friend',
timestamp: new Date().toISOString()
};
}
async dailyPracticeSupport(practice, challenge) {
const query = `I want to develop a ${practice} practice, but I'm struggling with ${challenge}. Can you help me in a gentle, supportive way?`;
const response = await this.chat.sendMessage(query, 'friend');
return {
practice,
challenge,
guidance: response.text,
encouragement: this.extractEncouragement(response)
};
}
async emotionalSupport(emotion, context) {
const query = `I'm feeling ${emotion}${context ? ` because ${context}` : ''}. I could use some compassionate support right now.`;
const response = await this.chat.sendMessage(query, 'friend');
return {
emotion,
context,
support: response.text,
copingStrategies: this.extractStrategies(response)
};
}
extractEncouragement(response) {
// Extract encouraging elements from the response
const text = response.text.toLowerCase();
const encouragements = [];
if (text.includes('wonderful') || text.includes('great') || text.includes('proud')) {
encouragements.push('Positive affirmation');
}
if (text.includes('gentle') || text.includes('kind') || text.includes('compassion')) {
encouragements.push('Self-compassion focus');
}
if (text.includes('progress') || text.includes('journey') || text.includes('habit')) {
encouragements.push('Growth mindset');
}
return encouragements;
}
extractStrategies(response) {
// Extract practical coping strategies
const text = response.text;
const strategies = [];
const strategyPatterns = [
/try (?:the )?[""]([^""]+)[""]/gi,
/practice (?:the )?([^.,]+)/gi,
/begin with ([^.,]+)/gi,
/start by ([^.,]+)/gi
];
strategyPatterns.forEach(pattern => {
let match;
while ((match = pattern.exec(text)) !== null) {
strategies.push(match[1].trim());
}
});
return strategies;
}
}
// Usage
const friendSupport = new FriendSupport(chat);
// Get support for stress
const stressSupport = await friendSupport.emotionalSupport('overwhelmed', 'work deadlines');
// Get guidance for meditation practice
const meditationHelp = await friendSupport.dailyPracticeSupport('meditation', 'finding time');
// General gentle guidance
const gentleGuidance = await friendSupport.getGentleGuidance('new to meditation and feeling unsure');